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

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

Issue 14150002: Remove StreamSink(replaced by EventSink) and make IOSink extend EventSink. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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) 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 // Tests socket exceptions. 5 // Tests socket exceptions.
6 6
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import "dart:async"; 8 import "dart:async";
9 import "dart:isolate"; 9 import "dart:isolate";
10 import "dart:io"; 10 import "dart:io";
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } on SocketIOException catch(ex) { 82 } on SocketIOException catch(ex) {
83 exceptionCaught = true; 83 exceptionCaught = true;
84 } catch (ex) { 84 } catch (ex) {
85 print(ex); 85 print(ex);
86 wrongExceptionCaught = true; 86 wrongExceptionCaught = true;
87 } 87 }
88 Expect.isFalse(exceptionCaught); 88 Expect.isFalse(exceptionCaught);
89 Expect.isFalse(wrongExceptionCaught); 89 Expect.isFalse(wrongExceptionCaught);
90 try { 90 try {
91 List<int> buffer = new List<int>(10); 91 List<int> buffer = new List<int>(10);
92 client.writeBytes(buffer); 92 client.add(buffer);
93 } on StateError catch (ex) { 93 } on StateError catch (ex) {
94 exceptionCaught = true; 94 exceptionCaught = true;
95 } catch (ex) { 95 } catch (ex) {
96 wrongExceptionCaught = true; 96 wrongExceptionCaught = true;
97 } 97 }
98 Expect.isTrue(exceptionCaught); 98 Expect.isTrue(exceptionCaught);
99 Expect.isFalse(wrongExceptionCaught); 99 Expect.isFalse(wrongExceptionCaught);
100 100
101 server.close(); 101 server.close();
102 }); 102 });
(...skipping 12 matching lines...) Expand all
115 }); 115 });
116 } 116 }
117 117
118 static void clientSocketAddDestroyNoErrorTest() { 118 static void clientSocketAddDestroyNoErrorTest() {
119 ServerSocket.bind().then((server) { 119 ServerSocket.bind().then((server) {
120 server.listen((socket) { 120 server.listen((socket) {
121 // Passive block data by not sobscribing to socket. 121 // Passive block data by not sobscribing to socket.
122 }); 122 });
123 Socket.connect("127.0.0.1", server.port).then((client) { 123 Socket.connect("127.0.0.1", server.port).then((client) {
124 client.listen((data) {}, onDone: server.close); 124 client.listen((data) {}, onDone: server.close);
125 client.writeBytes(new List.filled(1024 * 1024, 0)); 125 client.add(new List.filled(1024 * 1024, 0));
126 client.destroy(); 126 client.destroy();
127 }); 127 });
128 }); 128 });
129 } 129 }
130 130
131 static void clientSocketAddCloseNoErrorTest() { 131 static void clientSocketAddCloseNoErrorTest() {
132 ServerSocket.bind().then((server) { 132 ServerSocket.bind().then((server) {
133 var completer = new Completer(); 133 var completer = new Completer();
134 server.listen((socket) { 134 server.listen((socket) {
135 // The socket is 'paused' until the future completes. 135 // The socket is 'paused' until the future completes.
136 completer.future.then((_) => socket.pipe(socket)); 136 completer.future.then((_) => socket.pipe(socket));
137 }); 137 });
138 Socket.connect("127.0.0.1", server.port).then((client) { 138 Socket.connect("127.0.0.1", server.port).then((client) {
139 const int SIZE = 1024 * 1024; 139 const int SIZE = 1024 * 1024;
140 int count = 0; 140 int count = 0;
141 client.listen( 141 client.listen(
142 (data) => count += data.length, 142 (data) => count += data.length,
143 onDone: () { 143 onDone: () {
144 Expect.equals(SIZE, count); 144 Expect.equals(SIZE, count);
145 server.close(); 145 server.close();
146 }); 146 });
147 client.writeBytes(new List.filled(SIZE, 0)); 147 client.add(new List.filled(SIZE, 0));
148 client.close(); 148 client.close();
149 // Start piping now. 149 // Start piping now.
150 completer.complete(null); 150 completer.complete(null);
151 }); 151 });
152 }); 152 });
153 } 153 }
154 154
155 static void clientSocketAddCloseErrorTest() { 155 static void clientSocketAddCloseErrorTest() {
156 ServerSocket.bind().then((server) { 156 ServerSocket.bind().then((server) {
157 var completer = new Completer(); 157 var completer = new Completer();
(...skipping 10 matching lines...) Expand all
168 errors++; 168 errors++;
169 }, 169 },
170 onDone: () { 170 onDone: () {
171 // We get either a close or an error followed by a close 171 // We get either a close or an error followed by a close
172 // on the socket. Whether we get both depends on 172 // on the socket. Whether we get both depends on
173 // whether the system notices the error for the read 173 // whether the system notices the error for the read
174 // event or only for the write event. 174 // event or only for the write event.
175 Expect.isTrue(errors <= 1); 175 Expect.isTrue(errors <= 1);
176 server.close(); 176 server.close();
177 }); 177 });
178 client.writeBytes(new List.filled(SIZE, 0)); 178 client.add(new List.filled(SIZE, 0));
179 // Destroy other socket now. 179 // Destroy other socket now.
180 completer.complete(null); 180 completer.complete(null);
181 var port = new ReceivePort(); 181 var port = new ReceivePort();
182 client.done.then( 182 client.done.then(
183 (_) { 183 (_) {
184 Expect.fail("Expected error"); 184 Expect.fail("Expected error");
185 }, 185 },
186 onError: (error) { 186 onError: (error) {
187 Expect.isTrue(error.error is SocketIOException); 187 Expect.isTrue(error.error is SocketIOException);
188 port.close(); 188 port.close();
189 }); 189 });
190 }); 190 });
191 }); 191 });
192 } 192 }
193 193
194 static void clientSocketAddCloseResultErrorTest() { 194 static void clientSocketAddCloseResultErrorTest() {
195 ServerSocket.bind().then((server) { 195 ServerSocket.bind().then((server) {
196 var completer = new Completer(); 196 var completer = new Completer();
197 server.listen((socket) { 197 server.listen((socket) {
198 completer.future.then((_) => socket.destroy()); 198 completer.future.then((_) => socket.destroy());
199 }); 199 });
200 Socket.connect("127.0.0.1", server.port).then((client) { 200 Socket.connect("127.0.0.1", server.port).then((client) {
201 const int SIZE = 1024 * 1024; 201 const int SIZE = 1024 * 1024;
202 int errors = 0; 202 int errors = 0;
203 client.writeBytes(new List.filled(SIZE, 0)); 203 client.add(new List.filled(SIZE, 0));
204 client.close(); 204 client.close();
205 client.done.catchError((error) { 205 client.done.catchError((error) {
206 server.close(); 206 server.close();
207 }); 207 });
208 // Destroy other socket now. 208 // Destroy other socket now.
209 completer.complete(null); 209 completer.complete(null);
210 }); 210 });
211 }); 211 });
212 } 212 }
213 213
(...skipping 19 matching lines...) Expand all
233 clientSocketAddCloseErrorTest(); 233 clientSocketAddCloseErrorTest();
234 clientSocketAddCloseResultErrorTest(); 234 clientSocketAddCloseResultErrorTest();
235 unknownHostTest(); 235 unknownHostTest();
236 } 236 }
237 } 237 }
238 238
239 main() { 239 main() {
240 SocketExceptionTest.testMain(); 240 SocketExceptionTest.testMain();
241 } 241 }
242 242
OLDNEW
« no previous file with comments | « tests/standalone/io/secure_socket_test.dart ('k') | tests/standalone/io/socket_invalid_arguments_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698