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 "dart:async"; | |
6 import "dart:io"; | |
7 | |
8 import "package:async_helper/async_helper.dart"; | |
9 import "package:expect/expect.dart"; | |
10 | |
11 void testPauseResumeCancelStream() { | |
12 asyncStart(); | |
13 Directory.systemTemp.createTemp('file_stream').then((d) { | |
14 var file = new File("${d.path}/file"); | |
15 new File(Platform.executable).openRead().pipe(file.openWrite()) | |
16 .then((_) { | |
17 var subscription; | |
18 subscription = file.openRead().listen((data) { | |
19 subscription.pause(); | |
20 subscription.resume(); | |
21 void close() { | |
22 d.deleteSync(recursive: true); | |
23 asyncEnd(); | |
24 } | |
25 var future = subscription.cancel(); | |
26 if (future != null) { | |
27 future.whenComplete(close); | |
28 } else { | |
29 close(); | |
30 } | |
31 }, onDone: () { | |
32 Expect.fail('the stream was canceled, onDone should not happend'); | |
33 }); | |
34 }); | |
35 }); | |
36 } | |
37 | |
38 void testStreamIsEmpty() { | |
39 asyncStart(); | |
40 Directory.systemTemp.createTemp('file_stream').then((d) { | |
41 var file = new File("${d.path}/file"); | |
42 new File(Platform.executable).openRead().pipe(file.openWrite()) | |
43 .then((_) { | |
Søren Gjesse
2013/10/30 11:39:13
Maybe add a comment here (and in the test from yes
Anders Johnsen
2013/10/30 11:40:45
Done.
| |
44 file.openRead().isEmpty.then((empty) { | |
45 Expect.isFalse(empty); | |
46 d.deleteSync(recursive: true); | |
47 asyncEnd(); | |
48 }); | |
49 }); | |
50 }); | |
51 } | |
52 | |
53 void main() { | |
54 testPauseResumeCancelStream(); | |
55 testStreamIsEmpty(); | |
56 } | |
OLD | NEW |