Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: tests/standalone/io/socket_test.dart

Issue 12328037: Add missing files from previous commit (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 //
5 // VMOptions=
6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write
9
10 import "dart:async";
11 import "dart:io";
12 import "dart:isolate";
13
14 void testArguments() {
15 Expect.throws(() => ServerSocket.bind("127.0.0.1", 65536));
16 Expect.throws(() => ServerSocket.bind("127.0.0.1", -1));
17 Expect.throws(() => ServerSocket.bind("127.0.0.1", 0, -1));
18 }
19
20 void testSimpleBind() {
21 ReceivePort port = new ReceivePort();
22 ServerSocket.bind().then((s) {
23 Expect.isTrue(s.port > 0);
24 port.close();
25 });
26 }
27
28 void testInvalidBind() {
29 int count = 0;
30 ReceivePort port = new ReceivePort();
31 port.receive((_, __) { count++; if (count == 3) port.close(); });
32
33 // Bind to a unknown DNS name.
34 ServerSocket.bind("ko.faar.__hest__")
35 .then((_) { Expect.fail("Failure expected"); } )
36 .catchError((e) {
37 Expect.isTrue(e.error is SocketIOException);
38 port.toSendPort().send(1);
39 });
40
41 // Bind to an unavaliable IP-address.
42 ServerSocket.bind("8.8.8.8")
43 .then((_) { Expect.fail("Failure expected"); } )
44 .catchError((e) {
45 Expect.isTrue(e.error is SocketIOException);
46 port.toSendPort().send(1);
47 });
48
49 // Bind to a port already in use.
50 // Either an error or a successful bind is allowed.
51 // Windows platforms allow multiple binding to the same socket, with
52 // unpredictable results.
53 ServerSocket.bind("127.0.0.1")
54 .then((s) {
55 ServerSocket.bind("127.0.0.1", s.port)
56 .then((t) {
57 Expect.equals('windows', Platform.operatingSystem);
58 Expect.equals(s.port, t.port);
59 port.toSendPort().send(1);
60 })
61 .catchError((e) {
62 Expect.notEquals('windows', Platform.operatingSystem);
63 Expect.isTrue(e.error is SocketIOException);
64 port.toSendPort().send(1);
65 });
66 });
67 }
68
69 void testConnectNoDestroy() {
70 ReceivePort port = new ReceivePort();
71 ServerSocket.bind().then((server) {
72 server.listen((_) { });
73 Socket.connect("127.0.0.1", server.port).then((_) {
74 server.close();
75 port.close();
76 });
77 });
78 }
79
80 void testConnectImmediateDestroy() {
81 ReceivePort port = new ReceivePort();
82 ServerSocket.bind().then((server) {
83 server.listen((_) { });
84 Socket.connect("127.0.0.1", server.port).then((socket) {
85 socket.destroy();
86 server.close();
87 port.close();
88 });
89 });
90 }
91
92 void testConnectConsumerClose() {
93 // Connect socket then immediate close the consumer without
94 // listening on the stream.
95 ReceivePort port = new ReceivePort();
96 ServerSocket.bind().then((server) {
97 server.listen((_) { });
98 Socket.connect("127.0.0.1", server.port).then((socket) {
99 socket.close();
100 socket.done.then((_) {
101 socket.destroy();
102 server.close();
103 port.close();
104 });
105 });
106 });
107 }
108
109 void testConnectConsumerWriteClose() {
110 // Connect socket write some data immediate close the consumer
111 // without listening on the stream.
112 ReceivePort port = new ReceivePort();
113 ServerSocket.bind().then((server) {
114 server.listen((_) { });
115 Socket.connect("127.0.0.1", server.port).then((socket) {
116 socket.add([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
117 socket.close();
118 socket.done.then((_) {
119 socket.destroy();
120 server.close();
121 port.close();
122 });
123 });
124 });
125 }
126
127 void testConnectStreamClose() {
128 // Connect socket and listen on the stream. The server closes
129 // immediately so only a done event is received.
130 ReceivePort port = new ReceivePort();
131 ServerSocket.bind().then((server) {
132 server.listen((client) {
133 client.close();
134 client.done.then((_) => client.destroy());
135 });
136 Socket.connect("127.0.0.1", server.port).then((socket) {
137 bool onDoneCalled = false;
138 socket.listen((_) { Expect.fail("Unexpected data"); },
139 onDone: () {
140 Expect.isFalse(onDoneCalled);
141 onDoneCalled = true;
142 socket.close();
143 server.close();
144 port.close();
145 });
146 });
147 });
148 }
149
150 void testConnectStreamDataClose(bool useDestroy) {
151 // Connect socket and listen on the stream. The server sends data
152 // and then closes so both data and a done event is received.
153 List<int> sendData = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
154 ReceivePort port = new ReceivePort();
155 ServerSocket.bind().then((server) {
156 server.listen(
157 (client) {
158 client.add(sendData);
159 if (useDestroy) {
160 client.destroy();
161 } else {
162 client.close();
163 }
164 client.done.then((_) { if (!useDestroy) { client.destroy(); } });
165 });
166 Socket.connect("127.0.0.1", server.port).then((socket) {
167 List<int> data = [];
168 bool onDoneCalled = false;
169 socket.listen(data.addAll,
170 onDone: () {
171 Expect.isFalse(onDoneCalled);
172 onDoneCalled = true;
173 if (!useDestroy) Expect.listEquals(sendData, data);
174 socket.add([0]);
175 socket.close();
176 server.close();
177 port.close();
178 });
179 });
180 });
181 }
182
183 void testConnectStreamDataCloseCancel(bool useDestroy) {
184 List<int> sendData = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
185 ReceivePort port = new ReceivePort();
186 ServerSocket.bind().then((server) {
187 server.listen(
188 (client) {
189 client.add(sendData);
190 if (useDestroy) {
191 client.destroy();
192 } else {
193 client.close();
194 }
195 client.done
196 .then((_) {
197 if (!useDestroy) client.destroy();
198 })
199 .catchError((e) { /* can happen with short writes */ });
200 });
201 Socket.connect("127.0.0.1", server.port).then((socket) {
202 List<int> data = [];
203 bool onDoneCalled = false;
204 var subscription;
205 subscription = socket.listen(
206 (_) {
207 subscription.cancel();
208 socket.close();
209 server.close();
210 port.close();
211 },
212 onDone: () { Expect.fail("Unexpected pipe completion"); });
213 });
214 });
215 }
216
217 main() {
218 testArguments();
219 testSimpleBind();
220 testInvalidBind();
221 testConnectNoDestroy();
222 testConnectImmediateDestroy();
223 testConnectConsumerClose();
224 testConnectConsumerWriteClose();
225 testConnectStreamClose();
226 testConnectStreamDataClose(true);
227 testConnectStreamDataClose(false);
228 testConnectStreamDataCloseCancel(true);
229 testConnectStreamDataCloseCancel(false);
230 }
OLDNEW
« no previous file with comments | « tests/standalone/io/secure_server_socket_test.dart ('k') | tests/standalone/io/string_transformer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698