| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Test the basic StreamController and StreamController.singleSubscription. | 5 // Test the basic StreamController and StreamController.singleSubscription. |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
| 8 import '../../../pkg/unittest/lib/unittest.dart'; | 8 import '../../../pkg/unittest/lib/unittest.dart'; |
| 9 import 'event_helper.dart'; | 9 import 'event_helper.dart'; |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 test("Single-subscription StreamController subscription changes", () { | 77 test("Single-subscription StreamController subscription changes", () { |
| 78 StreamController c = new StreamController.singleSubscription(); | 78 StreamController c = new StreamController.singleSubscription(); |
| 79 StreamSink sink = c.sink; | 79 StreamSink sink = c.sink; |
| 80 Stream stream = c.stream; | 80 Stream stream = c.stream; |
| 81 int counter = 0; | 81 int counter = 0; |
| 82 var subscription; | 82 var subscription; |
| 83 subscription = stream.listen((data) { | 83 subscription = stream.listen((data) { |
| 84 counter += data; | 84 counter += data; |
| 85 Expect.throws(() => stream.listen(null), (e) => e is StateError); | 85 Expect.throws(() => stream.listen(null), (e) => e is StateError); |
| 86 subscription.unsubscribe(); | 86 subscription.cancel(); |
| 87 stream.listen((data) { | 87 stream.listen((data) { |
| 88 counter += data * 10; | 88 counter += data * 10; |
| 89 }, | 89 }, |
| 90 onDone: expectAsync0(() { | 90 onDone: expectAsync0(() { |
| 91 Expect.equals(1 + 20, counter); | 91 Expect.equals(1 + 20, counter); |
| 92 })); | 92 })); |
| 93 }); | 93 }); |
| 94 sink.add(1); | 94 sink.add(1); |
| 95 sink.add(2); | 95 sink.add(2); |
| 96 sink.close(); | 96 sink.close(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 118 // Test subscription changes while firing. | 118 // Test subscription changes while firing. |
| 119 test("Single-subscription StreamController subscription changes while firing", | 119 test("Single-subscription StreamController subscription changes while firing", |
| 120 () { | 120 () { |
| 121 StreamController c = new StreamController.singleSubscription(); | 121 StreamController c = new StreamController.singleSubscription(); |
| 122 StreamSink sink = c.sink; | 122 StreamSink sink = c.sink; |
| 123 Stream stream = c.stream; | 123 Stream stream = c.stream; |
| 124 int counter = 0; | 124 int counter = 0; |
| 125 var subscription = stream.listen(null); | 125 var subscription = stream.listen(null); |
| 126 subscription.onData(expectAsync1((data) { | 126 subscription.onData(expectAsync1((data) { |
| 127 counter += data; | 127 counter += data; |
| 128 subscription.unsubscribe(); | 128 subscription.cancel(); |
| 129 stream.listen((data) { | 129 stream.listen((data) { |
| 130 counter += 10 * data; | 130 counter += 10 * data; |
| 131 }, | 131 }, |
| 132 onDone: expectAsync0(() { | 132 onDone: expectAsync0(() { |
| 133 Expect.equals(1 + 20 + 30 + 40 + 50, counter); | 133 Expect.equals(1 + 20 + 30 + 40 + 50, counter); |
| 134 })); | 134 })); |
| 135 Expect.throws(() => stream.listen(null), (e) => e is StateError); | 135 Expect.throws(() => stream.listen(null), (e) => e is StateError); |
| 136 })); | 136 })); |
| 137 sink.add(1); // seen by stream 1 | 137 sink.add(1); // seen by stream 1 |
| 138 sink.add(2); // seen by stream 10 and 100 | 138 sink.add(2); // seen by stream 10 and 100 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 actualEvents.resume(); | 389 actualEvents.resume(); |
| 390 }); | 390 }); |
| 391 } | 391 } |
| 392 | 392 |
| 393 main() { | 393 main() { |
| 394 testController(); | 394 testController(); |
| 395 testSingleController(); | 395 testSingleController(); |
| 396 testExtraMethods(); | 396 testExtraMethods(); |
| 397 testPause(); | 397 testPause(); |
| 398 } | 398 } |
| OLD | NEW |