Add TetheringCommonTests
Bug: 153614365
Bug: 153613717
Test: atest TetheringTests TetheringCoverageTests
Change-Id: If7c933ec0c72943312cd37bfc66918f10a5504a9
Merged-In: If7c933ec0c72943312cd37bfc66918f10a5504a9
(cherry picked from commit f340f6fd46, aosp/1290553)
This commit is contained in:
parent
70e43fb856
commit
1cae88f560
2 changed files with 21 additions and 0 deletions
|
|
@ -14,6 +14,26 @@
|
|||
// limitations under the License.
|
||||
//
|
||||
|
||||
// Tests in this folder are included both in unit tests and CTS.
|
||||
java_library {
|
||||
name: "TetheringCommonTests",
|
||||
srcs: [
|
||||
"common/**/*.java",
|
||||
"common/**/*.kt"
|
||||
],
|
||||
static_libs: [
|
||||
"androidx.test.rules",
|
||||
"net-tests-utils",
|
||||
],
|
||||
// TODO(b/147200698) change sdk_version to module-current and remove framework-minus-apex
|
||||
sdk_version: "core_platform",
|
||||
libs: [
|
||||
"framework-minus-apex",
|
||||
"framework-tethering",
|
||||
],
|
||||
visibility: ["//cts/tests/tests/tethering"],
|
||||
}
|
||||
|
||||
java_defaults {
|
||||
name: "TetheringTestsDefaults",
|
||||
srcs: [
|
||||
|
|
@ -22,6 +42,7 @@ java_defaults {
|
|||
],
|
||||
static_libs: [
|
||||
"TetheringApiCurrentLib",
|
||||
"TetheringCommonTests",
|
||||
"androidx.test.rules",
|
||||
"frameworks-base-testutils",
|
||||
"mockito-target-extended-minus-junit4",
|
||||
|
|
|
|||
104
Tethering/tests/unit/common/android/net/TetheredClientTest.kt
Normal file
104
Tethering/tests/unit/common/android/net/TetheredClientTest.kt
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net
|
||||
|
||||
import android.net.InetAddresses.parseNumericAddress
|
||||
import android.net.TetheredClient.AddressInfo
|
||||
import android.net.TetheringManager.TETHERING_BLUETOOTH
|
||||
import android.net.TetheringManager.TETHERING_USB
|
||||
import android.system.OsConstants.RT_SCOPE_UNIVERSE
|
||||
import androidx.test.filters.SmallTest
|
||||
import androidx.test.runner.AndroidJUnit4
|
||||
import com.android.testutils.assertParcelSane
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotEquals
|
||||
|
||||
private val TEST_MACADDR = MacAddress.fromBytes(byteArrayOf(12, 23, 34, 45, 56, 67))
|
||||
private val TEST_OTHER_MACADDR = MacAddress.fromBytes(byteArrayOf(23, 34, 45, 56, 67, 78))
|
||||
private val TEST_ADDR1 = makeLinkAddress("192.168.113.3", prefixLength = 24, expTime = 123L)
|
||||
private val TEST_ADDR2 = makeLinkAddress("fe80::1:2:3", prefixLength = 64, expTime = 456L)
|
||||
private val TEST_ADDRINFO1 = AddressInfo(TEST_ADDR1, "test_hostname")
|
||||
private val TEST_ADDRINFO2 = AddressInfo(TEST_ADDR2, null)
|
||||
|
||||
private fun makeLinkAddress(addr: String, prefixLength: Int, expTime: Long) = LinkAddress(
|
||||
parseNumericAddress(addr),
|
||||
prefixLength,
|
||||
0 /* flags */,
|
||||
RT_SCOPE_UNIVERSE,
|
||||
expTime /* deprecationTime */,
|
||||
expTime /* expirationTime */)
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@SmallTest
|
||||
class TetheredClientTest {
|
||||
@Test
|
||||
fun testParceling() {
|
||||
assertParcelSane(makeTestClient(), fieldCount = 3)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEquals() {
|
||||
assertEquals(makeTestClient(), makeTestClient())
|
||||
|
||||
// Different mac address
|
||||
assertNotEquals(makeTestClient(), TetheredClient(
|
||||
TEST_OTHER_MACADDR,
|
||||
listOf(TEST_ADDRINFO1, TEST_ADDRINFO2),
|
||||
TETHERING_BLUETOOTH))
|
||||
|
||||
// Different hostname
|
||||
assertNotEquals(makeTestClient(), TetheredClient(
|
||||
TEST_MACADDR,
|
||||
listOf(AddressInfo(TEST_ADDR1, "test_other_hostname"), TEST_ADDRINFO2),
|
||||
TETHERING_BLUETOOTH))
|
||||
|
||||
// Null hostname
|
||||
assertNotEquals(makeTestClient(), TetheredClient(
|
||||
TEST_MACADDR,
|
||||
listOf(AddressInfo(TEST_ADDR1, null), TEST_ADDRINFO2),
|
||||
TETHERING_BLUETOOTH))
|
||||
|
||||
// Missing address
|
||||
assertNotEquals(makeTestClient(), TetheredClient(
|
||||
TEST_MACADDR,
|
||||
listOf(TEST_ADDRINFO2),
|
||||
TETHERING_BLUETOOTH))
|
||||
|
||||
// Different type
|
||||
assertNotEquals(makeTestClient(), TetheredClient(
|
||||
TEST_MACADDR,
|
||||
listOf(TEST_ADDRINFO1, TEST_ADDRINFO2),
|
||||
TETHERING_USB))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAddAddresses() {
|
||||
val client1 = TetheredClient(TEST_MACADDR, listOf(TEST_ADDRINFO1), TETHERING_USB)
|
||||
val client2 = TetheredClient(TEST_OTHER_MACADDR, listOf(TEST_ADDRINFO2), TETHERING_USB)
|
||||
assertEquals(TetheredClient(
|
||||
TEST_MACADDR,
|
||||
listOf(TEST_ADDRINFO1, TEST_ADDRINFO2),
|
||||
TETHERING_USB), client1.addAddresses(client2))
|
||||
}
|
||||
|
||||
private fun makeTestClient() = TetheredClient(
|
||||
TEST_MACADDR,
|
||||
listOf(TEST_ADDRINFO1, TEST_ADDRINFO2),
|
||||
TETHERING_BLUETOOTH)
|
||||
}
|
||||
Loading…
Reference in a new issue