Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import "package:expect/expect.dart"; | |
| 6 import 'dart:async'; | |
| 7 import 'dart:isolate'; | |
| 8 import 'dart:io'; | |
| 9 | |
| 10 var events = []; | |
| 11 | |
| 12 void testSocketException() { | |
| 13 var completer = new Completer(); | |
| 14 runZonedExperimental(() { | |
| 15 Socket.connect("4", 1).then((Socket s) { | |
| 16 Expect.fail("Socket should not be able to connect"); | |
| 17 }); | |
| 18 }, onError: (err) { | |
| 19 if (err is! SocketException) Expect.fail("Not expected error: $err"); | |
| 20 completer.complete("socket test, ok."); | |
| 21 events.add("SocketException"); | |
| 22 }); | |
| 23 return completer.future; | |
| 24 } | |
| 25 | |
| 26 void testFileException() { | |
| 27 var completer = new Completer(); | |
| 28 runZonedExperimental(() { | |
| 29 new File("lol it's not a file\n").openRead().listen(null); | |
| 30 }, onError: (err) { | |
| 31 if (err is! FileException) Expect.fail("Not expected error: $err"); | |
| 32 completer.complete("file test, ok."); | |
| 33 events.add("FileException"); | |
| 34 }); | |
| 35 return completer.future; | |
| 36 } | |
| 37 | |
| 38 main() { | |
| 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. | |
| 41 var timeOutPort = new ReceivePort(); | |
| 42 testSocketException() | |
|
Anders Johnsen
2013/07/11 13:43:37
Just an idea, but you could remove events and chan
floitsch
2013/07/11 14:06:22
Yes. But frequently I add events at other location
| |
| 43 .then((_) => testFileException()) | |
| 44 .then((_) { | |
| 45 timeOutPort.close(); | |
| 46 Expect.listEquals(["SocketException", "FileException"], | |
| 47 events); | |
| 48 }); | |
| 49 } | |
| OLD | NEW |