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 // VMOptions= | 5 // VMOptions= |
6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
9 | 9 |
10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
(...skipping 16 matching lines...) Expand all Loading... |
27 } | 27 } |
28 | 28 |
29 void testInvalidBind() { | 29 void testInvalidBind() { |
30 int count = 0; | 30 int count = 0; |
31 ReceivePort port = new ReceivePort(); | 31 ReceivePort port = new ReceivePort(); |
32 port.receive((_, __) { count++; if (count == 3) port.close(); }); | 32 port.receive((_, __) { count++; if (count == 3) port.close(); }); |
33 | 33 |
34 // Bind to a unknown DNS name. | 34 // Bind to a unknown DNS name. |
35 RawServerSocket.bind("ko.faar.__hest__") | 35 RawServerSocket.bind("ko.faar.__hest__") |
36 .then((_) { Expect.fail("Failure expected"); } ) | 36 .then((_) { Expect.fail("Failure expected"); } ) |
37 .catchError((e) { | 37 .catchError((error) { |
38 Expect.isTrue(e.error is SocketIOException); | 38 Expect.isTrue(error is SocketIOException); |
39 port.toSendPort().send(1); | 39 port.toSendPort().send(1); |
40 }); | 40 }); |
41 | 41 |
42 // Bind to an unavaliable IP-address. | 42 // Bind to an unavaliable IP-address. |
43 RawServerSocket.bind("8.8.8.8") | 43 RawServerSocket.bind("8.8.8.8") |
44 .then((_) { Expect.fail("Failure expected"); } ) | 44 .then((_) { Expect.fail("Failure expected"); } ) |
45 .catchError((e) { | 45 .catchError((error) { |
46 Expect.isTrue(e.error is SocketIOException); | 46 Expect.isTrue(error is SocketIOException); |
47 port.toSendPort().send(1); | 47 port.toSendPort().send(1); |
48 }); | 48 }); |
49 | 49 |
50 // Bind to a port already in use. | 50 // Bind to a port already in use. |
51 // Either an error or a successful bind is allowed. | 51 // Either an error or a successful bind is allowed. |
52 // Windows platforms allow multiple binding to the same socket, with | 52 // Windows platforms allow multiple binding to the same socket, with |
53 // unpredictable results. | 53 // unpredictable results. |
54 RawServerSocket.bind("127.0.0.1") | 54 RawServerSocket.bind("127.0.0.1") |
55 .then((s) { | 55 .then((s) { |
56 RawServerSocket.bind("127.0.0.1", s.port) | 56 RawServerSocket.bind("127.0.0.1", s.port) |
57 .then((t) { | 57 .then((t) { |
58 Expect.equals('windows', Platform.operatingSystem); | 58 Expect.equals('windows', Platform.operatingSystem); |
59 Expect.equals(s.port, t.port); | 59 Expect.equals(s.port, t.port); |
60 port.toSendPort().send(1); | 60 port.toSendPort().send(1); |
61 }) | 61 }) |
62 .catchError((e) { | 62 .catchError((error) { |
63 Expect.notEquals('windows', Platform.operatingSystem); | 63 Expect.notEquals('windows', Platform.operatingSystem); |
64 Expect.isTrue(e.error is SocketIOException); | 64 Expect.isTrue(error is SocketIOException); |
65 port.toSendPort().send(1); | 65 port.toSendPort().send(1); |
66 }); | 66 }); |
67 }); | 67 }); |
68 } | 68 } |
69 | 69 |
70 void testSimpleConnect() { | 70 void testSimpleConnect() { |
71 ReceivePort port = new ReceivePort(); | 71 ReceivePort port = new ReceivePort(); |
72 RawServerSocket.bind().then((server) { | 72 RawServerSocket.bind().then((server) { |
73 server.listen((_) { }); | 73 server.listen((_) { }); |
74 RawSocket.connect("127.0.0.1", server.port).then((_) { | 74 RawSocket.connect("127.0.0.1", server.port).then((_) { |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 testSimpleBind(); | 349 testSimpleBind(); |
350 testCloseOneEnd("client"); | 350 testCloseOneEnd("client"); |
351 testCloseOneEnd("server"); | 351 testCloseOneEnd("server"); |
352 testInvalidBind(); | 352 testInvalidBind(); |
353 testSimpleConnect(); | 353 testSimpleConnect(); |
354 testServerListenAfterConnect(); | 354 testServerListenAfterConnect(); |
355 testSimpleReadWrite(); | 355 testSimpleReadWrite(); |
356 testPauseServerSocket(); | 356 testPauseServerSocket(); |
357 testPauseSocket(); | 357 testPauseSocket(); |
358 } | 358 } |
OLD | NEW |