diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2013-08-08 02:54:29 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-08-08 02:54:29 +0000 |
commit | a50f4b1d0592d34547a4bb33e08915b171f954f6 (patch) | |
tree | 7250aa7d5002b365b674ee4c596a897253b87267 /core/tests | |
parent | 1194d3f7332c933599c7b8dcf86b0b604b6e5cf1 (diff) | |
parent | 3f1e1b2ce407684519f8bd070c931940fd33db4f (diff) | |
download | frameworks_base-a50f4b1d0592d34547a4bb33e08915b171f954f6.zip frameworks_base-a50f4b1d0592d34547a4bb33e08915b171f954f6.tar.gz frameworks_base-a50f4b1d0592d34547a4bb33e08915b171f954f6.tar.bz2 |
Merge "Simplify LinkPropertiesTest."
Diffstat (limited to 'core/tests')
-rw-r--r-- | core/tests/coretests/src/android/net/LinkPropertiesTest.java | 149 |
1 files changed, 65 insertions, 84 deletions
diff --git a/core/tests/coretests/src/android/net/LinkPropertiesTest.java b/core/tests/coretests/src/android/net/LinkPropertiesTest.java index d8290f4..9fdfd0e 100644 --- a/core/tests/coretests/src/android/net/LinkPropertiesTest.java +++ b/core/tests/coretests/src/android/net/LinkPropertiesTest.java @@ -25,14 +25,18 @@ import java.net.InetAddress; import java.util.ArrayList; public class LinkPropertiesTest extends TestCase { - private static String ADDRV4 = "75.208.6.1"; - private static String ADDRV6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; - private static String DNS1 = "75.208.7.1"; - private static String DNS2 = "69.78.7.1"; - private static String GATEWAY1 = "75.208.8.1"; - private static String GATEWAY2 = "69.78.8.1"; + private static InetAddress ADDRV4 = NetworkUtils.numericToInetAddress("75.208.6.1"); + private static InetAddress ADDRV6 = NetworkUtils.numericToInetAddress( + "2001:0db8:85a3:0000:0000:8a2e:0370:7334"); + private static InetAddress DNS1 = NetworkUtils.numericToInetAddress("75.208.7.1"); + private static InetAddress DNS2 = NetworkUtils.numericToInetAddress("69.78.7.1"); + private static InetAddress GATEWAY1 = NetworkUtils.numericToInetAddress("75.208.8.1"); + private static InetAddress GATEWAY2 = NetworkUtils.numericToInetAddress("69.78.8.1"); private static String NAME = "qmi0"; + private static LinkAddress LINKADDRV4 = new LinkAddress(ADDRV4, 32); + private static LinkAddress LINKADDRV6 = new LinkAddress(ADDRV6, 128); + public void assertLinkPropertiesEqual(LinkProperties source, LinkProperties target) { // Check implementation of equals(), element by element. assertTrue(source.isIdenticalInterfaceName(target)); @@ -76,43 +80,37 @@ public class LinkPropertiesTest extends TestCase { LinkProperties source = new LinkProperties(); source.setInterfaceName(NAME); // set 2 link addresses - source.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV4), 32)); - source.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV6), 128)); + source.addLinkAddress(LINKADDRV4); + source.addLinkAddress(LINKADDRV6); // set 2 dnses - source.addDns(NetworkUtils.numericToInetAddress(DNS1)); - source.addDns(NetworkUtils.numericToInetAddress(DNS2)); + source.addDns(DNS1); + source.addDns(DNS2); // set 2 gateways - source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); - source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + source.addRoute(new RouteInfo(GATEWAY1)); + source.addRoute(new RouteInfo(GATEWAY2)); LinkProperties target = new LinkProperties(); // All fields are same target.setInterfaceName(NAME); - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV4), 32)); - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV6), 128)); - target.addDns(NetworkUtils.numericToInetAddress(DNS1)); - target.addDns(NetworkUtils.numericToInetAddress(DNS2)); - target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); - target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + target.addLinkAddress(LINKADDRV4); + target.addLinkAddress(LINKADDRV6); + target.addDns(DNS1); + target.addDns(DNS2); + target.addRoute(new RouteInfo(GATEWAY1)); + target.addRoute(new RouteInfo(GATEWAY2)); assertLinkPropertiesEqual(source, target); target.clear(); // change Interface Name target.setInterfaceName("qmi1"); - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV4), 32)); - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV6), 128)); - target.addDns(NetworkUtils.numericToInetAddress(DNS1)); - target.addDns(NetworkUtils.numericToInetAddress(DNS2)); - target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); - target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + target.addLinkAddress(LINKADDRV4); + target.addLinkAddress(LINKADDRV6); + target.addDns(DNS1); + target.addDns(DNS2); + target.addRoute(new RouteInfo(GATEWAY1)); + target.addRoute(new RouteInfo(GATEWAY2)); assertFalse(source.equals(target)); target.clear(); @@ -120,38 +118,33 @@ public class LinkPropertiesTest extends TestCase { // change link addresses target.addLinkAddress(new LinkAddress( NetworkUtils.numericToInetAddress("75.208.6.2"), 32)); - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV6), 128)); - target.addDns(NetworkUtils.numericToInetAddress(DNS1)); - target.addDns(NetworkUtils.numericToInetAddress(DNS2)); - target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); - target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + target.addLinkAddress(LINKADDRV6); + target.addDns(DNS1); + target.addDns(DNS2); + target.addRoute(new RouteInfo(GATEWAY1)); + target.addRoute(new RouteInfo(GATEWAY2)); assertFalse(source.equals(target)); target.clear(); target.setInterfaceName(NAME); - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV4), 32)); - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV6), 128)); + target.addLinkAddress(LINKADDRV4); + target.addLinkAddress(LINKADDRV6); // change dnses target.addDns(NetworkUtils.numericToInetAddress("75.208.7.2")); - target.addDns(NetworkUtils.numericToInetAddress(DNS2)); - target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); - target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + target.addDns(DNS2); + target.addRoute(new RouteInfo(GATEWAY1)); + target.addRoute(new RouteInfo(GATEWAY2)); assertFalse(source.equals(target)); target.clear(); target.setInterfaceName(NAME); - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV4), 32)); - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV6), 128)); - target.addDns(NetworkUtils.numericToInetAddress(DNS1)); - target.addDns(NetworkUtils.numericToInetAddress(DNS2)); + target.addLinkAddress(LINKADDRV4); + target.addLinkAddress(LINKADDRV6); + target.addDns(DNS1); + target.addDns(DNS2); // change gateway target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress("75.208.8.2"))); - target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + target.addRoute(new RouteInfo(GATEWAY2)); assertFalse(source.equals(target)); } catch (Exception e) { @@ -166,28 +159,24 @@ public class LinkPropertiesTest extends TestCase { LinkProperties source = new LinkProperties(); source.setInterfaceName(NAME); // set 2 link addresses - source.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV4), 32)); - source.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV6), 128)); + source.addLinkAddress(LINKADDRV4); + source.addLinkAddress(LINKADDRV6); // set 2 dnses - source.addDns(NetworkUtils.numericToInetAddress(DNS1)); - source.addDns(NetworkUtils.numericToInetAddress(DNS2)); + source.addDns(DNS1); + source.addDns(DNS2); // set 2 gateways - source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); - source.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); + source.addRoute(new RouteInfo(GATEWAY1)); + source.addRoute(new RouteInfo(GATEWAY2)); LinkProperties target = new LinkProperties(); // Exchange order target.setInterfaceName(NAME); - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV6), 128)); - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV4), 32)); - target.addDns(NetworkUtils.numericToInetAddress(DNS2)); - target.addDns(NetworkUtils.numericToInetAddress(DNS1)); - target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY2))); - target.addRoute(new RouteInfo(NetworkUtils.numericToInetAddress(GATEWAY1))); + target.addLinkAddress(LINKADDRV6); + target.addLinkAddress(LINKADDRV4); + target.addDns(DNS2); + target.addDns(DNS1); + target.addRoute(new RouteInfo(GATEWAY2)); + target.addRoute(new RouteInfo(GATEWAY1)); assertLinkPropertiesEqual(source, target); } catch (Exception e) { @@ -200,21 +189,15 @@ public class LinkPropertiesTest extends TestCase { try { LinkProperties source = new LinkProperties(); // set 3 link addresses, eg, [A, A, B] - source.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV4), 32)); - source.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV4), 32)); - source.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV6), 128)); + source.addLinkAddress(LINKADDRV4); + source.addLinkAddress(LINKADDRV4); + source.addLinkAddress(LINKADDRV6); LinkProperties target = new LinkProperties(); // set 3 link addresses, eg, [A, B, B] - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV4), 32)); - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV6), 128)); - target.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV6), 128)); + target.addLinkAddress(LINKADDRV4); + target.addLinkAddress(LINKADDRV6); + target.addLinkAddress(LINKADDRV6); assertLinkPropertiesEqual(source, target); } catch (Exception e) { @@ -232,7 +215,7 @@ public class LinkPropertiesTest extends TestCase { public void testRouteInterfaces() { LinkAddress prefix = new LinkAddress( NetworkUtils.numericToInetAddress("2001:db8::"), 32); - InetAddress address = NetworkUtils.numericToInetAddress(ADDRV6); + InetAddress address = ADDRV6; // Add a route with no interface to a LinkProperties with no interface. No errors. LinkProperties lp = new LinkProperties(); @@ -265,7 +248,7 @@ public class LinkPropertiesTest extends TestCase { assertAllRoutesHaveInterface("wlan0", lp); // Routes with null interfaces are converted to wlan0. - r = RouteInfo.makeHostRoute(NetworkUtils.numericToInetAddress(ADDRV6), null); + r = RouteInfo.makeHostRoute(ADDRV6, null); lp.addRoute(r); assertEquals(3, lp.getRoutes().size()); assertAllRoutesHaveInterface("wlan0", lp); @@ -286,13 +269,11 @@ public class LinkPropertiesTest extends TestCase { public void testStackedInterfaces() { LinkProperties rmnet0 = new LinkProperties(); rmnet0.setInterfaceName("rmnet0"); - rmnet0.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV6), 128)); + rmnet0.addLinkAddress(LINKADDRV6); LinkProperties clat4 = new LinkProperties(); clat4.setInterfaceName("clat4"); - clat4.addLinkAddress(new LinkAddress( - NetworkUtils.numericToInetAddress(ADDRV4), 32)); + clat4.addLinkAddress(LINKADDRV4); assertEquals(0, rmnet0.getStackedLinks().size()); assertEquals(1, rmnet0.getAddresses().size()); |