Index: tests/standalone/io/socket_source_address_test.dart |
diff --git a/tests/standalone/io/socket_source_address_test.dart b/tests/standalone/io/socket_source_address_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0129fedeaba67c9d1f7d7546e5ceaf2316051ed9 |
--- /dev/null |
+++ b/tests/standalone/io/socket_source_address_test.dart |
@@ -0,0 +1,212 @@ |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+// |
+// VMOptions= |
+// VMOptions=--short_socket_read |
+// VMOptions=--short_socket_write |
+// VMOptions=--short_socket_read --short_socket_write |
kustermann
2015/02/10 10:06:54
You're not transfering any data between sockets, s
Søren Gjesse
2015/02/10 11:13:33
Done.
|
+ |
+import "dart:async"; |
+import "dart:io"; |
+ |
+import "package:async_helper/async_helper.dart"; |
+import "package:expect/expect.dart"; |
+ |
+Future throws(Function f, Function check) async { |
+ try { |
+ await f(); |
+ Expect.fail('Did not throw'); |
+ } catch (e) { |
+ if (check != null) { |
+ if (!check(e)) { |
+ Expect.fail('Unexpected: $e'); |
+ } |
+ } |
+ } |
+} |
+ |
+Future testArgumentsRawSocket() async { |
+ asyncStart(); |
+ var server = await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); |
+ server.listen((_) { throw 'Connection unexpected'; }, |
+ onDone: () => asyncEnd()); |
+ |
+ asyncStart(); |
+ // Illegal type for sourceAddress. |
+ for (var sourceAddress in ['www.google.com', 'abc']) { |
+ await throws(() => RawSocket.connect('127.0.0.1', |
+ server.port, |
+ sourceAddress: sourceAddress), |
+ (e) => e is ArgumentError); |
+ } |
+ // Unsupported local address. |
+ for (var sourceAddress in ['8.8.8.8', new InternetAddress('8.8.8.8')]) { |
+ await throws(() => RawSocket.connect('127.0.0.1', |
+ server.port, |
+ sourceAddress: sourceAddress), |
+ (e) => e is SocketException); |
+ } |
+ // Address family mismatch. |
+ for (var sourceAddress in ['::1', InternetAddress.LOOPBACK_IP_V6]) { |
+ await throws(() => RawSocket.connect('127.0.0.1', |
+ server.port, |
+ sourceAddress: sourceAddress), |
+ (e) => e is SocketException); |
+ } |
+ asyncEnd(); |
+ server.close(); |
+} |
+ |
+Future testArgumentsSocket() async { |
+ asyncStart(); |
+ var server = await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); |
+ server.listen((_) { throw 'Connection unexpected'; }, |
+ onDone: () => asyncEnd()); |
+ |
+ asyncStart(); |
+ // Illegal type for sourceAddress. |
+ for (var sourceAddress in ['www.google.com', 'abc']) { |
+ await throws(() => Socket.connect('127.0.0.1', |
+ server.port, |
+ sourceAddress: sourceAddress), |
+ (e) => e is ArgumentError); |
+ } |
+ // Unsupported local address. |
+ for (var sourceAddress in ['8.8.8.8', new InternetAddress('8.8.8.8')]) { |
+ await throws(() => Socket.connect('127.0.0.1', |
+ server.port, |
+ sourceAddress: sourceAddress), |
+ (e) => e is SocketException); |
+ } |
+ // Address family mismatch. |
+ for (var sourceAddress in ['::1', InternetAddress.LOOPBACK_IP_V6]) { |
+ await throws(() => Socket.connect('127.0.0.1', |
+ server.port, |
+ sourceAddress: sourceAddress), |
+ (e) => e is SocketException); |
+ } |
+ asyncEnd(); |
+ server.close(); |
+} |
+ |
+Future testConnectRawSocket() async { |
+ asyncStart(); |
+ var server = await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); |
+ var port = server.port; |
+ server.listen((s) { |
+ s.destroy(); |
+ }, onDone: () => asyncEnd()); |
+ |
+ asyncStart(); |
+ for (var sourceAddress in [InternetAddress.LOOPBACK_IP_V4, |
+ InternetAddress.ANY_IP_V4, |
+ '127.0.0.1', |
+ '0.0.0.0']) { |
+ RawSocket raw; |
+ raw = await RawSocket.connect(InternetAddress.LOOPBACK_IP_V4, |
+ port, |
+ sourceAddress: sourceAddress); |
+ raw.close(); |
+ } |
+ server.close(); |
+ asyncEnd(); |
+} |
+ |
+Future testConnectSocket() async { |
+ asyncStart(); |
+ var server = await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); |
+ var port = server.port; |
+ server.listen((s) { |
+ s.destroy(); |
+ }, onDone: () => asyncEnd()); |
+ |
+ asyncStart(); |
+ for (var sourceAddress in [InternetAddress.LOOPBACK_IP_V4, |
+ InternetAddress.ANY_IP_V4, |
+ '127.0.0.1', |
+ '0.0.0.0']) { |
+ Socket s; |
+ s = await Socket.connect(InternetAddress.LOOPBACK_IP_V4, |
+ port, |
+ sourceAddress: sourceAddress); |
+ s.destroy(); |
+ } |
+ server.close(); |
+ asyncEnd(); |
+} |
+ |
+Future testConnectRawSocketIPv6() async { |
+ asyncStart(); |
+ var server = await ServerSocket.bind(InternetAddress.ANY_IP_V6, 0); |
+ var port = server.port; |
+ server.listen((s) { |
+ s.destroy(); |
+ }, onDone: () => asyncEnd()); |
+ |
+ asyncStart(); |
+ for (var sourceAddress in [InternetAddress.LOOPBACK_IP_V4, |
+ InternetAddress.ANY_IP_V4, |
+ '127.0.0.1', |
+ '0.0.0.0']) { |
+ RawSocket raw; |
+ raw = await RawSocket.connect(InternetAddress.LOOPBACK_IP_V4, |
+ port, |
+ sourceAddress: sourceAddress); |
+ raw.close(); |
+ } |
+ for (var sourceAddress in [InternetAddress.LOOPBACK_IP_V6, |
+ InternetAddress.ANY_IP_V6, |
+ '::1', |
+ '::']) { |
+ RawSocket raw; |
+ raw = await RawSocket.connect(InternetAddress.LOOPBACK_IP_V6, |
+ port, |
+ sourceAddress: sourceAddress); |
+ raw.close(); |
+ } |
+ server.close(); |
+ asyncEnd(); |
+} |
+ |
+Future testConnectSocketIPv6() async { |
+ asyncStart(); |
+ var server = await ServerSocket.bind(InternetAddress.ANY_IP_V6, 0); |
+ var port = server.port; |
+ server.listen((s) { |
+ s.destroy(); |
+ }, onDone: () => asyncEnd()); |
+ |
+ asyncStart(); |
+ for (var sourceAddress in [InternetAddress.LOOPBACK_IP_V4, |
+ InternetAddress.ANY_IP_V4, |
+ '127.0.0.1', |
+ '0.0.0.0']) { |
+ Socket s; |
+ s = await Socket.connect(InternetAddress.LOOPBACK_IP_V4, |
+ port, |
+ sourceAddress: sourceAddress); |
+ s.destroy(); |
+ } |
+ for (var sourceAddress in [InternetAddress.LOOPBACK_IP_V6, |
+ InternetAddress.ANY_IP_V6, |
+ '::1', |
+ '::']) { |
+ Socket s; |
+ s = await Socket.connect(InternetAddress.LOOPBACK_IP_V6, |
+ port, |
+ sourceAddress: sourceAddress); |
+ s.destroy(); |
+ } |
+ server.close(); |
+ asyncEnd(); |
+} |
+ |
+main() { |
+ testArgumentsRawSocket(); |
+ testArgumentsSocket(); |
+ testConnectRawSocket(); |
+ testConnectSocket(); |
+ testConnectRawSocketIPv6(); |
+ testConnectSocketIPv6(); |
+} |