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((_) { |
| 44 // isEmpty will cancel the stream after first data event. |
| 45 file.openRead().isEmpty.then((empty) { |
| 46 Expect.isFalse(empty); |
| 47 d.deleteSync(recursive: true); |
| 48 asyncEnd(); |
| 49 }); |
| 50 }); |
| 51 }); |
| 52 } |
| 53 |
| 54 void main() { |
| 55 testPauseResumeCancelStream(); |
| 56 testStreamIsEmpty(); |
| 57 } |
OLD | NEW |