OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:io'; | 5 import 'dart:io'; |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 | 8 |
9 void testDefaultAddresses() { | 9 void testDefaultAddresses() { |
10 var loopback4 = InternetAddress.LOOPBACK_IP_V4; | 10 var loopback4 = InternetAddress.LOOPBACK_IP_V4; |
(...skipping 14 matching lines...) Expand all Loading... |
25 Expect.equals("0.0.0.0", any4.host); | 25 Expect.equals("0.0.0.0", any4.host); |
26 Expect.equals("0.0.0.0", any4.address); | 26 Expect.equals("0.0.0.0", any4.address); |
27 | 27 |
28 var any6 = InternetAddress.ANY_IP_V6; | 28 var any6 = InternetAddress.ANY_IP_V6; |
29 Expect.isNotNull(any6); | 29 Expect.isNotNull(any6); |
30 Expect.equals(InternetAddressType.IP_V6, any6.type); | 30 Expect.equals(InternetAddressType.IP_V6, any6.type); |
31 Expect.equals("::", any6.host); | 31 Expect.equals("::", any6.host); |
32 Expect.equals("::", any6.address); | 32 Expect.equals("::", any6.address); |
33 } | 33 } |
34 | 34 |
| 35 void testConstructor() { |
| 36 var loopback4 = new InternetAddress("127.0.0.1"); |
| 37 Expect.equals(InternetAddressType.IP_V4, loopback4.type); |
| 38 Expect.equals("127.0.0.1", loopback4.host); |
| 39 Expect.equals("127.0.0.1", loopback4.address); |
| 40 Expect.isFalse(loopback4.isMulticast); |
| 41 |
| 42 var loopback6 = new InternetAddress("::1"); |
| 43 Expect.equals(InternetAddressType.IP_V6, loopback6.type); |
| 44 Expect.equals("::1", loopback6.host); |
| 45 Expect.equals("::1", loopback6.address); |
| 46 Expect.isFalse(loopback6.isMulticast); |
| 47 |
| 48 var ip4 = new InternetAddress("10.20.30.40"); |
| 49 Expect.equals(InternetAddressType.IP_V4, ip4.type); |
| 50 Expect.equals("10.20.30.40", ip4.host); |
| 51 Expect.equals("10.20.30.40", ip4.address); |
| 52 Expect.isFalse(ip4.isMulticast); |
| 53 |
| 54 var ip6 = new InternetAddress("10:20::30:40"); |
| 55 Expect.equals(InternetAddressType.IP_V6, ip6.type); |
| 56 Expect.equals("10:20::30:40", ip6.host); |
| 57 Expect.equals("10:20::30:40", ip6.address); |
| 58 Expect.isFalse(ip6.isMulticast); |
| 59 |
| 60 var multicast4 = new InternetAddress("224.1.2.3"); |
| 61 Expect.equals(InternetAddressType.IP_V4, multicast4.type); |
| 62 Expect.isTrue(multicast4.isMulticast); |
| 63 |
| 64 var multicast6 = new InternetAddress("FF00::1:2:3"); |
| 65 Expect.equals(InternetAddressType.IP_V6, multicast6.type); |
| 66 Expect.isTrue(multicast6.isMulticast); |
| 67 |
| 68 Expect.throws(() => new InternetAddress("1.2.3"), |
| 69 (e) => e is ArgumentError); |
| 70 Expect.throws(() => new InternetAddress("::FFFF::1"), |
| 71 (e) => e is ArgumentError); |
| 72 } |
| 73 |
| 74 void testEquality() { |
| 75 Expect.equals(new InternetAddress("127.0.0.1"), |
| 76 new InternetAddress("127.0.0.1")); |
| 77 Expect.equals(new InternetAddress("127.0.0.1"), |
| 78 InternetAddress.LOOPBACK_IP_V4); |
| 79 Expect.equals(new InternetAddress("::1"), |
| 80 new InternetAddress("::1")); |
| 81 Expect.equals(new InternetAddress("::1"), |
| 82 InternetAddress.LOOPBACK_IP_V6); |
| 83 Expect.equals(new InternetAddress("1:2:3:4:5:6:7:8"), |
| 84 new InternetAddress("1:2:3:4:5:6:7:8")); |
| 85 Expect.equals(new InternetAddress("1::2"), |
| 86 new InternetAddress("1:0:0:0:0:0:0:2")); |
| 87 Expect.equals(new InternetAddress("::FFFF:0:0:16.32.48.64"), |
| 88 new InternetAddress("::FFFF:0:0:1020:3040")); |
| 89 |
| 90 var set = new Set(); |
| 91 set.add(new InternetAddress("127.0.0.1")); |
| 92 set.add(new InternetAddress("::1")); |
| 93 set.add(new InternetAddress("1:2:3:4:5:6:7:8")); |
| 94 Expect.isTrue(set.contains(new InternetAddress("127.0.0.1"))); |
| 95 Expect.isTrue(set.contains(InternetAddress.LOOPBACK_IP_V4)); |
| 96 Expect.isFalse(set.contains(new InternetAddress("127.0.0.2"))); |
| 97 Expect.isTrue(set.contains(new InternetAddress("::1"))); |
| 98 Expect.isTrue(set.contains(InternetAddress.LOOPBACK_IP_V6)); |
| 99 Expect.isFalse(set.contains(new InternetAddress("::2"))); |
| 100 Expect.isTrue(set.contains(new InternetAddress("1:2:3:4:5:6:7:8"))); |
| 101 Expect.isFalse(set.contains(new InternetAddress("1:2:3:4:5:6:7:9"))); |
| 102 Expect.isFalse(set.contains(new InternetAddress("0:2:3:4:5:6:7:8"))); |
| 103 } |
| 104 |
35 void testLookup() { | 105 void testLookup() { |
36 InternetAddress.lookup("127.0.0.1").then((addresses) { | 106 InternetAddress.lookup("127.0.0.1").then((addresses) { |
37 Expect.equals(1, addresses.length); | 107 Expect.equals(1, addresses.length); |
38 Expect.equals("127.0.0.1", addresses[0].address); | 108 Expect.equals("127.0.0.1", addresses[0].address); |
39 }); | 109 }); |
40 | 110 |
41 InternetAddress.lookup("::1").then((addresses) { | 111 InternetAddress.lookup("::1").then((addresses) { |
42 Expect.equals(1, addresses.length); | 112 Expect.equals(1, addresses.length); |
43 Expect.equals("::1", addresses[0].address); | 113 Expect.equals("::1", addresses[0].address); |
44 }); | 114 }); |
(...skipping 10 matching lines...) Expand all Loading... |
55 Expect.equals('127.0.0.1', addrs.first.host); | 125 Expect.equals('127.0.0.1', addrs.first.host); |
56 addrs.first.reverse().then((addr) { | 126 addrs.first.reverse().then((addr) { |
57 Expect.isNotNull(addr.host); | 127 Expect.isNotNull(addr.host); |
58 Expect.notEquals('127.0.0.1', addr.host); | 128 Expect.notEquals('127.0.0.1', addr.host); |
59 }); | 129 }); |
60 }); | 130 }); |
61 } | 131 } |
62 | 132 |
63 void main() { | 133 void main() { |
64 testDefaultAddresses(); | 134 testDefaultAddresses(); |
| 135 testConstructor(); |
| 136 testEquality(); |
65 testLookup(); | 137 testLookup(); |
66 testReverseLookup(); | 138 testReverseLookup(); |
67 } | 139 } |
OLD | NEW |