| 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 | 5 |
| 6 import "dart:async"; | 6 import "dart:async"; |
| 7 import "dart:io"; | 7 import "dart:io"; |
| 8 | 8 |
| 9 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
| 10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| 11 | 11 |
| 12 Future throws(Function f, Function check) async { | 12 Future throws(Function f, Function check) async { |
| 13 try { | 13 try { |
| 14 await f(); | 14 await f(); |
| 15 Expect.fail('Did not throw'); | 15 Expect.fail('Did not throw'); |
| 16 } catch (e) { | 16 } catch (e) { |
| 17 if (check != null) { | 17 if (check != null) { |
| 18 if (!check(e)) { | 18 if (!check(e)) { |
| 19 Expect.fail('Unexpected: $e'); | 19 Expect.fail('Unexpected: $e'); |
| 20 } | 20 } |
| 21 } | 21 } |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 Future testArguments(connectFunction) async { | 25 Future testArguments(connectFunction) async { |
| 26 var sourceAddress; |
| 26 asyncStart(); | 27 asyncStart(); |
| 27 var server = await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); | 28 var server = await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); |
| 28 server.listen((_) { throw 'Connection unexpected'; }, | 29 server.listen((_) { |
| 29 onDone: () => asyncEnd()); | 30 throw 'Unexpected connection from address $sourceAddress'; |
| 31 }, onDone: () => asyncEnd()); |
| 30 | 32 |
| 31 asyncStart(); | 33 asyncStart(); |
| 32 // Illegal type for sourceAddress. | 34 // Illegal type for sourceAddress. |
| 33 for (var sourceAddress in ['www.google.com', 'abc']) { | 35 for (sourceAddress in ['www.google.com', 'abc']) { |
| 34 await throws(() => connectFunction('127.0.0.1', | 36 await throws(() => connectFunction('127.0.0.1', |
| 35 server.port, | 37 server.port, |
| 36 sourceAddress: sourceAddress), | 38 sourceAddress: sourceAddress), |
| 37 (e) => e is ArgumentError); | 39 (e) => e is ArgumentError); |
| 38 } | 40 } |
| 39 // Unsupported local address. | 41 // Unsupported local address. |
| 40 for (var sourceAddress in ['8.8.8.8', new InternetAddress('8.8.8.8')]) { | 42 for (sourceAddress in ['8.8.8.8', new InternetAddress('8.8.8.8')]) { |
| 41 await throws(() => connectFunction('127.0.0.1', | 43 await throws(() => connectFunction('127.0.0.1', |
| 42 server.port, | 44 server.port, |
| 43 sourceAddress: sourceAddress), | 45 sourceAddress: sourceAddress), |
| 44 (e) => e is SocketException); | 46 (e) => e is SocketException); |
| 45 } | 47 } |
| 46 // Address family mismatch. | 48 // Address family mismatch. |
| 47 for (var sourceAddress in ['::1', InternetAddress.LOOPBACK_IP_V6]) { | 49 for (sourceAddress in ['::1', InternetAddress.LOOPBACK_IP_V6]) { |
| 48 await throws(() => connectFunction('127.0.0.1', | 50 await throws(() => connectFunction('127.0.0.1', |
| 49 server.port, | 51 server.port, |
| 50 sourceAddress: sourceAddress), | 52 sourceAddress: sourceAddress), |
| 51 (e) => e is SocketException); | 53 (e) => e is SocketException); |
| 52 } | 54 } |
| 53 asyncEnd(); | 55 asyncEnd(); |
| 54 server.close(); | 56 server.close(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 // IPv4 addresses to use as source address when connecting locally. | 59 // IPv4 addresses to use as source address when connecting locally. |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 InternetAddress.ANY_IP_V4, false, Socket.connect, (s) => s.destroy()); | 138 InternetAddress.ANY_IP_V4, false, Socket.connect, (s) => s.destroy()); |
| 137 testConnect( | 139 testConnect( |
| 138 InternetAddress.ANY_IP_V6, false, RawSocket.connect, (s) => s.close()); | 140 InternetAddress.ANY_IP_V6, false, RawSocket.connect, (s) => s.close()); |
| 139 testConnect( | 141 testConnect( |
| 140 InternetAddress.ANY_IP_V6, false, Socket.connect, (s) => s.destroy()); | 142 InternetAddress.ANY_IP_V6, false, Socket.connect, (s) => s.destroy()); |
| 141 testConnect( | 143 testConnect( |
| 142 InternetAddress.ANY_IP_V6, true, RawSocket.connect, (s) => s.close()); | 144 InternetAddress.ANY_IP_V6, true, RawSocket.connect, (s) => s.close()); |
| 143 testConnect( | 145 testConnect( |
| 144 InternetAddress.ANY_IP_V6, true, Socket.connect, (s) => s.destroy()); | 146 InternetAddress.ANY_IP_V6, true, Socket.connect, (s) => s.destroy()); |
| 145 } | 147 } |
| OLD | NEW |