Merge "Format MdnsUtilsTest" into main

This commit is contained in:
Treehugger Robot 2025-03-24 21:16:34 -07:00 • committed by Gerrit Code Review
commit f0dcda3be3

View file

@ -35,14 +35,14 @@ import com.android.server.connectivity.mdns.util.MdnsUtils.createQueryDatagramPa
import com.android.server.connectivity.mdns.util.MdnsUtils.truncateServiceName import com.android.server.connectivity.mdns.util.MdnsUtils.truncateServiceName
import com.android.testutils.DevSdkIgnoreRule import com.android.testutils.DevSdkIgnoreRule
import com.android.testutils.DevSdkIgnoreRunner import com.android.testutils.DevSdkIgnoreRunner
import java.net.DatagramPacket
import kotlin.test.assertContentEquals
import org.junit.Assert.assertArrayEquals import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import java.net.DatagramPacket
import kotlin.test.assertContentEquals
@RunWith(DevSdkIgnoreRunner::class) @RunWith(DevSdkIgnoreRunner::class)
@DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.S_V2) @DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.S_V2)
@ -178,8 +178,13 @@ class MdnsUtilsTest {
val interfaceIndex = 99 val interfaceIndex = 99
val response = MdnsResponse(0 /* now */, serviceName, interfaceIndex, null /* network */) val response = MdnsResponse(0 /* now */, serviceName, interfaceIndex, null /* network */)
// Set PTR record // Set PTR record
response.addPointerRecord(MdnsPointerRecord(serviceType.split(".").toTypedArray(), response.addPointerRecord(MdnsPointerRecord(
testElapsedRealtime, false /* cacheFlush */, ttlTime, serviceName)) serviceType.split(".").toTypedArray(),
testElapsedRealtime,
false /* cacheFlush */,
ttlTime,
serviceName
))
// Set SRV record. // Set SRV record.
response.serviceRecord = MdnsServiceRecord(serviceName, testElapsedRealtime, response.serviceRecord = MdnsServiceRecord(serviceName, testElapsedRealtime,
false /* cacheFlush */, ttlTime, 0 /* servicePriority */, 0 /* serviceWeight */, false /* cacheFlush */, ttlTime, 0 /* servicePriority */, 0 /* serviceWeight */,
@ -189,16 +194,27 @@ class MdnsUtilsTest {
testElapsedRealtime, true /* cacheFlush */, 0L /* ttlMillis */, testElapsedRealtime, true /* cacheFlush */, 0L /* ttlMillis */,
listOf(MdnsServiceInfo.TextEntry.fromString("somedifferent=entry"))) listOf(MdnsServiceInfo.TextEntry.fromString("somedifferent=entry")))
// Set InetAddress record. // Set InetAddress record.
response.addInet4AddressRecord(MdnsInetAddressRecord(hostName.split(".").toTypedArray(), response.addInet4AddressRecord(MdnsInetAddressRecord(
testElapsedRealtime, true /* cacheFlush */, hostName.split(".").toTypedArray(),
0L /* ttlMillis */, InetAddresses.parseNumericAddress(v4Address))) testElapsedRealtime,
response.addInet6AddressRecord(MdnsInetAddressRecord(hostName.split(".").toTypedArray(), true /* cacheFlush */,
testElapsedRealtime, true /* cacheFlush */, 0L /* ttlMillis */,
0L /* ttlMillis */, InetAddresses.parseNumericAddress(v6Address))) InetAddresses.parseNumericAddress(v4Address)
))
response.addInet6AddressRecord(MdnsInetAddressRecord(
hostName.split(".").toTypedArray(),
testElapsedRealtime,
true /* cacheFlush */,
0L /* ttlMillis */,
InetAddresses.parseNumericAddress(v6Address)
))
// Convert a MdnsResponse to a MdnsServiceInfo // Convert a MdnsResponse to a MdnsServiceInfo
val serviceInfo = MdnsUtils.buildMdnsServiceInfoFromResponse( val serviceInfo = MdnsUtils.buildMdnsServiceInfoFromResponse(
response, serviceType.split(".").toTypedArray(), testElapsedRealtime) response,
serviceType.split(".").toTypedArray(),
testElapsedRealtime
)
assertEquals(serviceInstanceName, serviceInfo.serviceInstanceName) assertEquals(serviceInstanceName, serviceInfo.serviceInstanceName)
assertArrayEquals(serviceType.split(".").toTypedArray(), serviceInfo.serviceType) assertArrayEquals(serviceType.split(".").toTypedArray(), serviceInfo.serviceType)
@ -210,7 +226,6 @@ class MdnsUtilsTest {
assertEquals(v6Address, serviceInfo.ipv6Addresses[0]) assertEquals(v6Address, serviceInfo.ipv6Addresses[0])
assertEquals(interfaceIndex, serviceInfo.interfaceIndex) assertEquals(interfaceIndex, serviceInfo.interfaceIndex)
assertEquals(null, serviceInfo.network) assertEquals(null, serviceInfo.network)
assertEquals(mapOf("somedifferent" to "entry"), assertEquals(mapOf("somedifferent" to "entry"), serviceInfo.attributes)
serviceInfo.attributes)
} }
} }