1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.net.nsd 18 19 import android.os.Build 20 import androidx.test.filters.SmallTest 21 import com.android.testutils.ConnectivityModuleTest 22 import com.android.testutils.DevSdkIgnoreRule 23 import com.android.testutils.DevSdkIgnoreRunner 24 import kotlin.test.assertTrue 25 import org.junit.Test 26 import org.junit.runner.RunWith 27 28 /** Unit tests for {@link NsdServiceInfo}. */ 29 @SmallTest 30 @ConnectivityModuleTest 31 @RunWith(DevSdkIgnoreRunner::class) 32 @DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.S_V2) 33 class NsdServiceInfoTest { 34 @Test testToString_txtRecordnull35 fun testToString_txtRecord() { 36 val info = NsdServiceInfo().apply { 37 this.setAttribute("abc", byteArrayOf(0xff.toByte(), 0xfe.toByte())) 38 this.setAttribute("def", null as String?) 39 this.setAttribute("ghi", "猫") 40 this.setAttribute("jkl", byteArrayOf(0, 0x21)) 41 this.setAttribute("mno", "Hey Tom! It's you?.~{}") 42 } 43 44 val infoStr = info.toString() 45 46 assertTrue( 47 infoStr.contains("txtRecord: " + 48 "{abc=0xFFFE, def=(null), ghi=0xE78CAB, jkl=0x0021, mno=Hey Tom! It's you?.~{}}"), 49 infoStr) 50 } 51 } 52