| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 var events = []; | 10 var events = []; |
| 11 | 11 |
| 12 void testSocketException() { | 12 Future testSocketException() { |
| 13 var completer = new Completer(); | 13 var completer = new Completer(); |
| 14 runZonedExperimental(() { | 14 runZonedExperimental(() { |
| 15 Socket.connect("4", 1).then((Socket s) { | 15 Socket.connect("4", 1).then((Socket s) { |
| 16 Expect.fail("Socket should not be able to connect"); | 16 Expect.fail("Socket should not be able to connect"); |
| 17 }); | 17 }); |
| 18 }, onError: (err) { | 18 }, onError: (err) { |
| 19 if (err is! SocketException) Expect.fail("Not expected error: $err"); | 19 if (err is! SocketException) Expect.fail("Not expected error: $err"); |
| 20 completer.complete("socket test, ok."); | 20 completer.complete("socket test, ok."); |
| 21 events.add("SocketException"); | 21 events.add("SocketException"); |
| 22 }); | 22 }); |
| 23 return completer.future; | 23 return completer.future; |
| 24 } | 24 } |
| 25 | 25 |
| 26 void testFileException() { | 26 Future testFileException() { |
| 27 var completer = new Completer(); | 27 var completer = new Completer(); |
| 28 runZonedExperimental(() { | 28 runZonedExperimental(() { |
| 29 new File("lol it's not a file\n").openRead().listen(null); | 29 new File("lol it's not a file\n").openRead().listen(null); |
| 30 }, onError: (err) { | 30 }, onError: (err) { |
| 31 if (err is! FileException) Expect.fail("Not expected error: $err"); | 31 if (err is! FileException) Expect.fail("Not expected error: $err"); |
| 32 completer.complete("file test, ok."); | 32 completer.complete("file test, ok."); |
| 33 events.add("FileException"); | 33 events.add("FileException"); |
| 34 }); | 34 }); |
| 35 return completer.future; | 35 return completer.future; |
| 36 } | 36 } |
| 37 | 37 |
| 38 main() { | 38 main() { |
| 39 // We keep a ReceivePort open until all tests are done. This way the VM will | 39 // We keep a ReceivePort open until all tests are done. This way the VM will |
| 40 // hang if the callbacks are not invoked and the test will time out. | 40 // hang if the callbacks are not invoked and the test will time out. |
| 41 var timeOutPort = new ReceivePort(); | 41 var timeOutPort = new ReceivePort(); |
| 42 testSocketException() | 42 testSocketException() |
| 43 .then((_) => testFileException()) | 43 .then((_) => testFileException()) |
| 44 .then((_) { | 44 .then((_) { |
| 45 timeOutPort.close(); | 45 timeOutPort.close(); |
| 46 Expect.listEquals(["SocketException", "FileException"], | 46 Expect.listEquals(["SocketException", "FileException"], |
| 47 events); | 47 events); |
| 48 }); | 48 }); |
| 49 } | 49 } |
| OLD | NEW |