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

Side by Side Diff: tests/standalone/src/SocketStreamCloseTest.dart

Issue 9500002: Rename blahHandler to onBlah throughout dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 9 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // Test socket close events. 10 // Test socket close events.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 Expect.fail("Unknown test mode"); 93 Expect.fail("Unknown test mode");
94 } 94 }
95 } 95 }
96 96
97 void errorHandler() { 97 void errorHandler() {
98 _errorEvents++; 98 _errorEvents++;
99 _socket.close(); 99 _socket.close();
100 } 100 }
101 101
102 void connectHandler() { 102 void connectHandler() {
103 _socket.inputStream.dataHandler = dataHandler; 103 _socket.inputStream.onData = dataHandler;
104 _socket.inputStream.closeHandler = closeHandler; 104 _socket.inputStream.onClosed = closeHandler;
105 _socket.errorHandler = errorHandler; 105 _socket.onError = errorHandler;
106 106
107 _iterations++; 107 _iterations++;
108 switch (_mode) { 108 switch (_mode) {
109 case 0: 109 case 0:
110 _socket.inputStream.close(); 110 _socket.inputStream.close();
111 proceed(); 111 proceed();
112 break; 112 break;
113 case 1: 113 case 1:
114 _socket.outputStream.write("Hello".charCodes()); 114 _socket.outputStream.write("Hello".charCodes());
115 _socket.outputStream.noPendingWriteHandler = () { 115 _socket.outputStream.onNoPendingWrites = () {
116 _socket.inputStream.close(); 116 _socket.inputStream.close();
117 proceed(); 117 proceed();
118 }; 118 };
119 break; 119 break;
120 case 2: 120 case 2:
121 case 3: 121 case 3:
122 case 4: 122 case 4:
123 _socket.outputStream.write("Hello".charCodes()); 123 _socket.outputStream.write("Hello".charCodes());
124 break; 124 break;
125 case 5: 125 case 5:
126 _socket.outputStream.write("Hello".charCodes()); 126 _socket.outputStream.write("Hello".charCodes());
127 _socket.outputStream.noPendingWriteHandler = () { 127 _socket.outputStream.onNoPendingWrites = () {
128 _socket.outputStream.close(); 128 _socket.outputStream.close();
129 }; 129 };
130 break; 130 break;
131 case 6: 131 case 6:
132 _socket.outputStream.write("Hello".charCodes()); 132 _socket.outputStream.write("Hello".charCodes());
133 break; 133 break;
134 case 7: 134 case 7:
135 case 8: 135 case 8:
136 _socket.outputStream.write("Hello".charCodes()); 136 _socket.outputStream.write("Hello".charCodes());
137 _socket.outputStream.noPendingWriteHandler = () { 137 _socket.outputStream.onNoPendingWrites = () {
138 _socket.outputStream.close(); 138 _socket.outputStream.close();
139 }; 139 };
140 break; 140 break;
141 default: 141 default:
142 Expect.fail("Unknown test mode"); 142 Expect.fail("Unknown test mode");
143 } 143 }
144 } 144 }
145 145
146 _socket = new Socket(SocketCloseServer.HOST, _port); 146 _socket = new Socket(SocketCloseServer.HOST, _port);
147 Expect.equals(true, _socket !== null); 147 Expect.equals(true, _socket !== null);
148 _socket.connectHandler = connectHandler; 148 _socket.onConnect = connectHandler;
149 } 149 }
150 150
151 void start() { 151 void start() {
152 _receivePort.receive((var message, SendPort replyTo) { 152 _receivePort.receive((var message, SendPort replyTo) {
153 _port = message; 153 _port = message;
154 proceed(); 154 proceed();
155 }); 155 });
156 _sendPort.send(_mode, _receivePort.toSendPort()); 156 _sendPort.send(_mode, _receivePort.toSendPort());
157 } 157 }
158 158
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 case 2: 247 case 2:
248 readBytes(() { 248 readBytes(() {
249 _dataEvents++; 249 _dataEvents++;
250 connection.inputStream.close(); 250 connection.inputStream.close();
251 }); 251 });
252 break; 252 break;
253 case 3: 253 case 3:
254 readBytes(() { 254 readBytes(() {
255 _dataEvents++; 255 _dataEvents++;
256 connection.outputStream.write("Hello".charCodes()); 256 connection.outputStream.write("Hello".charCodes());
257 connection.outputStream.noPendingWriteHandler = () { 257 connection.outputStream.onNoPendingWrites = () {
258 connection.inputStream.close(); 258 connection.inputStream.close();
259 }; 259 };
260 }); 260 });
261 break; 261 break;
262 case 4: 262 case 4:
263 readBytes(() { 263 readBytes(() {
264 _dataEvents++; 264 _dataEvents++;
265 connection.outputStream.write("Hello".charCodes()); 265 connection.outputStream.write("Hello".charCodes());
266 connection.inputStream.close(); 266 connection.inputStream.close();
267 }); 267 });
268 break; 268 break;
269 case 5: 269 case 5:
270 readBytes(() { 270 readBytes(() {
271 _dataEvents++; 271 _dataEvents++;
272 connection.outputStream.write("Hello".charCodes()); 272 connection.outputStream.write("Hello".charCodes());
273 }); 273 });
274 break; 274 break;
275 case 6: 275 case 6:
276 case 7: 276 case 7:
277 readBytes(() { 277 readBytes(() {
278 _dataEvents++; 278 _dataEvents++;
279 connection.outputStream.write("Hello".charCodes()); 279 connection.outputStream.write("Hello".charCodes());
280 connection.outputStream.noPendingWriteHandler = () { 280 connection.outputStream.onNoPendingWrites = () {
281 connection.outputStream.close(); 281 connection.outputStream.close();
282 }; 282 };
283 }); 283 });
284 break; 284 break;
285 case 8: 285 case 8:
286 readBytes(() { 286 readBytes(() {
287 _dataEvents++; 287 _dataEvents++;
288 connection.outputStream.write("Hello".charCodes()); 288 connection.outputStream.write("Hello".charCodes());
289 connection.outputStream.close(); 289 connection.outputStream.close();
290 }); 290 });
291 break; 291 break;
292 default: 292 default:
293 Expect.fail("Unknown test mode"); 293 Expect.fail("Unknown test mode");
294 } 294 }
295 } 295 }
296 296
297 void closeHandler() { 297 void closeHandler() {
298 _closeEvents++; 298 _closeEvents++;
299 connection.outputStream.close(); 299 connection.outputStream.close();
300 } 300 }
301 301
302 void errorHandler() { 302 void errorHandler() {
303 Expect.fail("Socket error"); 303 Expect.fail("Socket error");
304 } 304 }
305 305
306 _iterations++; 306 _iterations++;
307 307
308 connection.inputStream.dataHandler = dataHandler; 308 connection.inputStream.onData = dataHandler;
309 connection.inputStream.closeHandler = closeHandler; 309 connection.inputStream.onClosed = closeHandler;
310 connection.errorHandler = errorHandler; 310 connection.onError = errorHandler;
311 } 311 }
312 312
313 void errorHandlerServer() { 313 void errorHandlerServer() {
314 Expect.fail("Server socket error"); 314 Expect.fail("Server socket error");
315 } 315 }
316 316
317 waitForResult(Timer timer) { 317 waitForResult(Timer timer) {
318 // Make sure all iterations have been run. In multiple of these 318 // Make sure all iterations have been run. In multiple of these
319 // scenarios it is possible to get the SERVERSHUTDOWN message 319 // scenarios it is possible to get the SERVERSHUTDOWN message
320 // before we have received the last close event on the 320 // before we have received the last close event on the
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 _donePort = replyTo; 361 _donePort = replyTo;
362 if (message != SERVERSHUTDOWN) { 362 if (message != SERVERSHUTDOWN) {
363 _readBytes = 0; 363 _readBytes = 0;
364 _errorEvents = 0; 364 _errorEvents = 0;
365 _dataEvents = 0; 365 _dataEvents = 0;
366 _closeEvents = 0; 366 _closeEvents = 0;
367 _iterations = 0; 367 _iterations = 0;
368 _mode = message; 368 _mode = message;
369 _server = new ServerSocket(HOST, 0, 10); 369 _server = new ServerSocket(HOST, 0, 10);
370 Expect.equals(true, _server !== null); 370 Expect.equals(true, _server !== null);
371 _server.connectionHandler = (connection) { 371 _server.onConnection = (connection) {
372 var data = new ConnectionData(connection); 372 var data = new ConnectionData(connection);
373 connectionHandler(data); 373 connectionHandler(data);
374 }; 374 };
375 _server.errorHandler = errorHandlerServer; 375 _server.onError = errorHandlerServer;
376 replyTo.send(_server.port, null); 376 replyTo.send(_server.port, null);
377 } else { 377 } else {
378 new Timer(waitForResult, 0); 378 new Timer(waitForResult, 0);
379 } 379 }
380 }); 380 });
381 } 381 }
382 382
383 ServerSocket _server; 383 ServerSocket _server;
384 SendPort _donePort; 384 SendPort _donePort;
385 int _readBytes; 385 int _readBytes;
(...skipping 21 matching lines...) Expand all
407 var tests = 9; 407 var tests = 9;
408 var port = new ReceivePort(); 408 var port = new ReceivePort();
409 var completed = 0; 409 var completed = 0;
410 port.receive((message, ignore) { 410 port.receive((message, ignore) {
411 if (++completed == tests) port.close(); 411 if (++completed == tests) port.close();
412 }); 412 });
413 for (var i = 0; i < tests; i++) { 413 for (var i = 0; i < tests; i++) {
414 new SocketClose.start(i, port.toSendPort()); 414 new SocketClose.start(i, port.toSendPort());
415 } 415 }
416 } 416 }
OLDNEW
« no previous file with comments | « tests/standalone/src/SocketManyConnectionsTest.dart ('k') | tests/standalone/src/StreamPipeTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698