Add common tests for FrameworksBaseTests and CTS
The common package covers tests that should be included both in CTS and unit tests. Test: atest FrameworksBaseTests Bug: 129199908 Change-Id: I9c138d49ce010edde095e4bd3c47e36ca301634a
This commit is contained in:
@@ -7,6 +7,7 @@ android_test {
|
|||||||
// Include all test java files.
|
// Include all test java files.
|
||||||
srcs: ["java/**/*.java"],
|
srcs: ["java/**/*.java"],
|
||||||
static_libs: [
|
static_libs: [
|
||||||
|
"FrameworksNetCommonTests",
|
||||||
"frameworks-base-testutils",
|
"frameworks-base-testutils",
|
||||||
"framework-protos",
|
"framework-protos",
|
||||||
"androidx.test.rules",
|
"androidx.test.rules",
|
||||||
|
|||||||
29
tests/net/common/Android.bp
Normal file
29
tests/net/common/Android.bp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// Copyright (C) 2019 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.
|
||||||
|
//
|
||||||
|
|
||||||
|
// Tests in this folder are included both in unit tests and CTS.
|
||||||
|
// They must be fast and stable, and exercise public or test APIs.
|
||||||
|
java_library {
|
||||||
|
name: "FrameworksNetCommonTests",
|
||||||
|
srcs: ["java/**/*.java"],
|
||||||
|
static_libs: [
|
||||||
|
"androidx.test.rules",
|
||||||
|
"junit",
|
||||||
|
],
|
||||||
|
libs: [
|
||||||
|
"android.test.base.stubs",
|
||||||
|
],
|
||||||
|
}
|
||||||
@@ -39,7 +39,7 @@ import java.util.Random;
|
|||||||
@SmallTest
|
@SmallTest
|
||||||
public class IpPrefixTest {
|
public class IpPrefixTest {
|
||||||
|
|
||||||
private static InetAddress Address(String addr) {
|
private static InetAddress address(String addr) {
|
||||||
return InetAddress.parseNumericAddress(addr);
|
return InetAddress.parseNumericAddress(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,28 +226,28 @@ public class IpPrefixTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testContainsInetAddress() {
|
public void testContainsInetAddress() {
|
||||||
IpPrefix p = new IpPrefix("2001:db8:f00::ace:d00d/127");
|
IpPrefix p = new IpPrefix("2001:db8:f00::ace:d00d/127");
|
||||||
assertTrue(p.contains(Address("2001:db8:f00::ace:d00c")));
|
assertTrue(p.contains(address("2001:db8:f00::ace:d00c")));
|
||||||
assertTrue(p.contains(Address("2001:db8:f00::ace:d00d")));
|
assertTrue(p.contains(address("2001:db8:f00::ace:d00d")));
|
||||||
assertFalse(p.contains(Address("2001:db8:f00::ace:d00e")));
|
assertFalse(p.contains(address("2001:db8:f00::ace:d00e")));
|
||||||
assertFalse(p.contains(Address("2001:db8:f00::bad:d00d")));
|
assertFalse(p.contains(address("2001:db8:f00::bad:d00d")));
|
||||||
assertFalse(p.contains(Address("2001:4868:4860::8888")));
|
assertFalse(p.contains(address("2001:4868:4860::8888")));
|
||||||
assertFalse(p.contains(Address("8.8.8.8")));
|
assertFalse(p.contains(address("8.8.8.8")));
|
||||||
|
|
||||||
p = new IpPrefix("192.0.2.0/23");
|
p = new IpPrefix("192.0.2.0/23");
|
||||||
assertTrue(p.contains(Address("192.0.2.43")));
|
assertTrue(p.contains(address("192.0.2.43")));
|
||||||
assertTrue(p.contains(Address("192.0.3.21")));
|
assertTrue(p.contains(address("192.0.3.21")));
|
||||||
assertFalse(p.contains(Address("192.0.0.21")));
|
assertFalse(p.contains(address("192.0.0.21")));
|
||||||
assertFalse(p.contains(Address("8.8.8.8")));
|
assertFalse(p.contains(address("8.8.8.8")));
|
||||||
assertFalse(p.contains(Address("2001:4868:4860::8888")));
|
assertFalse(p.contains(address("2001:4868:4860::8888")));
|
||||||
|
|
||||||
IpPrefix ipv6Default = new IpPrefix("::/0");
|
IpPrefix ipv6Default = new IpPrefix("::/0");
|
||||||
assertTrue(ipv6Default.contains(Address("2001:db8::f00")));
|
assertTrue(ipv6Default.contains(address("2001:db8::f00")));
|
||||||
assertFalse(ipv6Default.contains(Address("192.0.2.1")));
|
assertFalse(ipv6Default.contains(address("192.0.2.1")));
|
||||||
|
|
||||||
IpPrefix ipv4Default = new IpPrefix("0.0.0.0/0");
|
IpPrefix ipv4Default = new IpPrefix("0.0.0.0/0");
|
||||||
assertTrue(ipv4Default.contains(Address("255.255.255.255")));
|
assertTrue(ipv4Default.contains(address("255.255.255.255")));
|
||||||
assertTrue(ipv4Default.contains(Address("192.0.2.1")));
|
assertTrue(ipv4Default.contains(address("192.0.2.1")));
|
||||||
assertFalse(ipv4Default.contains(Address("2001:db8::f00")));
|
assertFalse(ipv4Default.contains(address("2001:db8::f00")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
Reference in New Issue
Block a user