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

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

Issue 8386029: Consistently use setters to set event handlers in native APIs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Test socket close events. 5 // Test socket close events.
6 6
7 class SocketCloseTest { 7 class SocketCloseTest {
8 8
9 static void testMain() { 9 static void testMain() {
10 SocketClose socketClose = new SocketClose.start(); 10 SocketClose socketClose = new SocketClose.start();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 shutdown(); 46 shutdown();
47 } 47 }
48 } 48 }
49 49
50 void errorHandler() { 50 void errorHandler() {
51 _errorEvents++; 51 _errorEvents++;
52 _socket.close(); 52 _socket.close();
53 } 53 }
54 54
55 void connectHandler() { 55 void connectHandler() {
56 _socket.setDataHandler(dataHandler); 56 _socket.dataHandler = dataHandler;
57 _socket.setCloseHandler(closeHandler); 57 _socket.closeHandler = closeHandler;
58 _socket.setErrorHandler(errorHandler); 58 _socket.errorHandler = errorHandler;
59 59
60 if ((_iterations % 2) == 0) { 60 if ((_iterations % 2) == 0) {
61 _socket.writeList("Hello".charCodes(), 0, 5); 61 _socket.writeList("Hello".charCodes(), 0, 5);
62 } 62 }
63 } 63 }
64 64
65 _socket = new Socket(SocketCloseServer.HOST, _port); 65 _socket = new Socket(SocketCloseServer.HOST, _port);
66 Expect.equals(true, _socket !== null); 66 Expect.equals(true, _socket !== null);
67 _socket.setConnectHandler(connectHandler); 67 _socket.connectHandler = connectHandler;
68 } 68 }
69 69
70 void start() { 70 void start() {
71 _receivePort.receive((var message, SendPort replyTo) { 71 _receivePort.receive((var message, SendPort replyTo) {
72 _port = message; 72 _port = message;
73 sendData(); 73 sendData();
74 }); 74 });
75 _sendPort.send(SERVERINIT, _receivePort.toSendPort()); 75 _sendPort.send(SERVERINIT, _receivePort.toSendPort());
76 } 76 }
77 77
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 void errorHandler() { 122 void errorHandler() {
123 _errorEvents++; 123 _errorEvents++;
124 _client.close(); 124 _client.close();
125 } 125 }
126 126
127 _client = _server.accept(); 127 _client = _server.accept();
128 if ((_iterations % 2) == 1) { 128 if ((_iterations % 2) == 1) {
129 _client.close(); 129 _client.close();
130 } 130 }
131 _client.setDataHandler(messageHandler); 131 _client.dataHandler = messageHandler;
132 _client.setCloseHandler(closeHandler); 132 _client.closeHandler = closeHandler;
133 _client.setErrorHandler(errorHandler); 133 _client.errorHandler = errorHandler;
134 _iterations++; 134 _iterations++;
135 } 135 }
136 136
137 void errorHandlerServer() { 137 void errorHandlerServer() {
138 _server.close(); 138 _server.close();
139 } 139 }
140 140
141 this.port.receive((message, SendPort replyTo) { 141 this.port.receive((message, SendPort replyTo) {
142 if (message == SocketClose.SERVERINIT) { 142 if (message == SocketClose.SERVERINIT) {
143 _errorEvents = 0; 143 _errorEvents = 0;
144 _dataEvents = 0; 144 _dataEvents = 0;
145 _closeEvents = 0; 145 _closeEvents = 0;
146 _iterations = 0; 146 _iterations = 0;
147 _server = new ServerSocket(HOST, 0, 10); 147 _server = new ServerSocket(HOST, 0, 10);
148 Expect.equals(true, _server !== null); 148 Expect.equals(true, _server !== null);
149 _server.setConnectionHandler(connectionHandler); 149 _server.connectionHandler = connectionHandler;
150 _server.setErrorHandler(errorHandlerServer); 150 _server.errorHandler = errorHandlerServer;
151 replyTo.send(_server.port, null); 151 replyTo.send(_server.port, null);
152 } else if (message == SocketClose.SERVERSHUTDOWN) { 152 } else if (message == SocketClose.SERVERSHUTDOWN) {
153 Expect.equals(SocketClose.ITERATIONS/2, _dataEvents); 153 Expect.equals(SocketClose.ITERATIONS/2, _dataEvents);
154 Expect.equals(0, _closeEvents); 154 Expect.equals(0, _closeEvents);
155 Expect.equals(0, _errorEvents); 155 Expect.equals(0, _errorEvents);
156 _server.close(); 156 _server.close();
157 this.port.close(); 157 this.port.close();
158 } 158 }
159 }); 159 });
160 } 160 }
161 161
162 ServerSocket _server; 162 ServerSocket _server;
163 int _errorEvents; 163 int _errorEvents;
164 int _dataEvents; 164 int _dataEvents;
165 int _closeEvents; 165 int _closeEvents;
166 int _iterations; 166 int _iterations;
167 } 167 }
168 168
169 169
170 main() { 170 main() {
171 SocketCloseTest.testMain(); 171 SocketCloseTest.testMain();
172 } 172 }
OLDNEW
« no previous file with comments | « tests/standalone/src/EchoServerTest.dart ('k') | tests/standalone/src/SocketManyConnectionsTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698