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