| 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:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 import "package:expect/expect.dart"; |
| 8 | 9 |
| 9 const ANY = InternetAddressType.ANY; | 10 const ANY = InternetAddressType.ANY; |
| 10 | 11 |
| 11 void testIPv6toIPv6() { | 12 void testIPv6toIPv6() { |
| 12 asyncStart(); | 13 asyncStart(); |
| 13 InternetAddress.lookup("::0", type: ANY).then((serverAddr) { | 14 InternetAddress.lookup("::0", type: ANY).then((serverAddr) { |
| 14 InternetAddress.lookup("::1", type: ANY).then((clientAddr) { | 15 InternetAddress.lookup("::1", type: ANY).then((clientAddr) { |
| 15 ServerSocket.bind(serverAddr.first, 0).then((server) { | 16 ServerSocket.bind(serverAddr.first, 0).then((server) { |
| 17 Expect.equals('::0', server.address.host); |
| 18 Expect.equals('::', server.address.address); |
| 16 server.listen((socket) { | 19 server.listen((socket) { |
| 17 socket.destroy(); | 20 socket.destroy(); |
| 18 server.close(); | 21 server.close(); |
| 19 asyncEnd(); | 22 asyncEnd(); |
| 20 }); | 23 }); |
| 21 Socket.connect(clientAddr.first, server.port).then((socket) { | 24 Socket.connect(clientAddr.first, server.port).then((socket) { |
| 22 socket.destroy(); | 25 socket.destroy(); |
| 23 }); | 26 }); |
| 24 }); | 27 }); |
| 25 }); | 28 }); |
| 26 }); | 29 }); |
| 27 } | 30 } |
| 28 | 31 |
| 29 void testIPv4toIPv6() { | 32 void testIPv4toIPv6() { |
| 30 asyncStart(); | 33 asyncStart(); |
| 31 InternetAddress.lookup("::0", type: ANY).then((serverAddr) { | 34 InternetAddress.lookup("::0", type: ANY).then((serverAddr) { |
| 32 ServerSocket.bind(serverAddr.first, 0).then((server) { | 35 ServerSocket.bind(serverAddr.first, 0).then((server) { |
| 36 Expect.equals('::0', server.address.host); |
| 37 Expect.equals('::', server.address.address); |
| 33 server.listen((socket) { | 38 server.listen((socket) { |
| 34 socket.destroy(); | 39 socket.destroy(); |
| 35 server.close(); | 40 server.close(); |
| 36 asyncEnd(); | 41 asyncEnd(); |
| 37 }); | 42 }); |
| 38 Socket.connect("127.0.0.1", server.port).then((socket) { | 43 Socket.connect("127.0.0.1", server.port).then((socket) { |
| 39 socket.destroy(); | 44 socket.destroy(); |
| 40 }); | 45 }); |
| 41 }); | 46 }); |
| 42 }); | 47 }); |
| 43 } | 48 } |
| 44 | 49 |
| 45 void testIPv6toIPv4() { | 50 void testIPv6toIPv4() { |
| 46 asyncStart(); | 51 asyncStart(); |
| 47 InternetAddress.lookup("::1", type: ANY).then((clientAddr) { | 52 InternetAddress.lookup("::1", type: ANY).then((clientAddr) { |
| 48 ServerSocket.bind("127.0.0.1", 0).then((server) { | 53 ServerSocket.bind("127.0.0.1", 0).then((server) { |
| 54 Expect.equals('127.0.0.1', server.address.host); |
| 55 Expect.equals('127.0.0.1', server.address.address); |
| 49 server.listen((socket) { | 56 server.listen((socket) { |
| 50 throw "Unexpected socket"; | 57 throw "Unexpected socket"; |
| 51 }); | 58 }); |
| 52 Socket.connect(clientAddr.first, server.port).catchError((e) { | 59 Socket.connect(clientAddr.first, server.port).catchError((e) { |
| 53 server.close(); | 60 server.close(); |
| 54 asyncEnd(); | 61 asyncEnd(); |
| 55 }); | 62 }); |
| 56 }); | 63 }); |
| 57 }); | 64 }); |
| 58 } | 65 } |
| 59 | 66 |
| 60 void testIPv4toIPv4() { | 67 void testIPv4toIPv4() { |
| 61 asyncStart(); | 68 asyncStart(); |
| 62 ServerSocket.bind("127.0.0.1", 0).then((server) { | 69 ServerSocket.bind("127.0.0.1", 0).then((server) { |
| 70 Expect.equals('127.0.0.1', server.address.host); |
| 71 Expect.equals('127.0.0.1', server.address.address); |
| 63 server.listen((socket) { | 72 server.listen((socket) { |
| 64 socket.destroy(); | 73 socket.destroy(); |
| 65 server.close(); | 74 server.close(); |
| 66 asyncEnd(); | 75 asyncEnd(); |
| 67 }); | 76 }); |
| 68 Socket.connect("127.0.0.1", server.port).then((socket) { | 77 Socket.connect("127.0.0.1", server.port).then((socket) { |
| 69 socket.destroy(); | 78 socket.destroy(); |
| 70 }); | 79 }); |
| 71 }); | 80 }); |
| 72 } | 81 } |
| 73 | 82 |
| 74 void testIPv6Lookup() { | 83 void testIPv6Lookup() { |
| 75 asyncStart(); | 84 asyncStart(); |
| 76 InternetAddress.lookup("::0", type: ANY).then((list) { | 85 InternetAddress.lookup("::0", type: ANY).then((list) { |
| 77 if (list.length < 0) throw "no address"; | 86 if (list.length < 0) throw "no address"; |
| 78 for (var entry in list) { | 87 for (var entry in list) { |
| 79 if (entry.type != InternetAddressType.IP_V6) { | 88 if (entry.type != InternetAddressType.IP_V6) { |
| 80 throw "Wrong IP type"; | 89 throw "Wrong IP type"; |
| 81 } | 90 } |
| 82 } | 91 } |
| 83 asyncEnd(); | 92 asyncEnd(); |
| 84 }); | 93 }); |
| 85 } | 94 } |
| 86 | 95 |
| 87 void testIPv4Lookup() { | 96 void testIPv4Lookup() { |
| 88 asyncStart(); | 97 asyncStart(); |
| 89 InternetAddress.lookup("127.0.0.1").then((list) { | 98 InternetAddress.lookup("127.0.0.1").then((list) { |
| 90 if (list.length < 0) throw "no addresse"; | 99 if (list.length < 0) throw "no address"; |
| 91 for (var entry in list) { | 100 for (var entry in list) { |
| 92 if (entry.type != InternetAddressType.IP_V4) { | 101 if (entry.type != InternetAddressType.IP_V4) { |
| 93 throw "Wrong IP type"; | 102 throw "Wrong IP type"; |
| 94 } | 103 } |
| 95 } | 104 } |
| 96 asyncEnd(); | 105 asyncEnd(); |
| 97 }); | 106 }); |
| 98 } | 107 } |
| 99 | 108 |
| 100 void testIPv4toIPv6_IPV6Only() { | 109 void testIPv4toIPv6_IPV6Only() { |
| 101 asyncStart(); | 110 asyncStart(); |
| 102 InternetAddress.lookup("::0", type: ANY) | 111 InternetAddress.lookup("::0", type: ANY) |
| 103 .then((serverAddr) { | 112 .then((serverAddr) { |
| 104 ServerSocket.bind(serverAddr.first, 0, v6Only: true) | 113 ServerSocket.bind(serverAddr.first, 0, v6Only: true) |
| 105 .then((server) { | 114 .then((server) { |
| 106 server.listen((socket) { | 115 server.listen((socket) { |
| 107 throw "Unexpcted socket"; | 116 throw "Unexpected socket"; |
| 108 }); | 117 }); |
| 109 Socket.connect("127.0.0.1", server.port).catchError((error) { | 118 Socket.connect("127.0.0.1", server.port).catchError((error) { |
| 110 server.close(); | 119 server.close(); |
| 111 asyncEnd(); | 120 asyncEnd(); |
| 112 }); | 121 }); |
| 113 }); | 122 }); |
| 114 }); | 123 }); |
| 115 } | 124 } |
| 116 | 125 |
| 117 void main() { | 126 void main() { |
| 118 testIPv6toIPv6(); | 127 testIPv6toIPv6(); |
| 119 testIPv4toIPv6(); | 128 testIPv4toIPv6(); |
| 120 testIPv6toIPv4(); | 129 testIPv6toIPv4(); |
| 121 testIPv4toIPv4(); | 130 testIPv4toIPv4(); |
| 122 testIPv6Lookup(); | 131 testIPv6Lookup(); |
| 123 testIPv4Lookup(); | 132 testIPv4Lookup(); |
| 124 | 133 |
| 125 testIPv4toIPv6_IPV6Only(); | 134 testIPv4toIPv6_IPV6Only(); |
| 126 } | 135 } |
| OLD | NEW |