Chromium Code Reviews| 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 library stream_controller_test; | 6 library stream_controller_test; |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'event_helper.dart'; | 10 import 'event_helper.dart'; |
| 11 | 11 |
| 12 void testMultiController() { | 12 void testMultiController() { |
| 13 // Test normal flow. | 13 // Test normal flow. |
| 14 var c = new StreamController(sync: true); | 14 var c = new StreamController(sync: true); |
| 15 Events expectedEvents = new Events() | 15 Events expectedEvents = new Events() |
| 16 ..add(42) | 16 ..add(42) |
| 17 ..add("dibs") | 17 ..add("dibs") |
| 18 ..error("error!") | 18 ..error("error!") |
| 19 ..error("error too!") | 19 ..error("error too!") |
| 20 ..close(); | 20 ..close(); |
| 21 Events actualEvents = new Events.capture(c.stream.asBroadcastStream()); | 21 CaptureEvents actualEvents = new Events.capture(c.stream.asBroadcastStream()); |
|
Lasse Reichstein Nielsen
2013/11/01 09:37:36
Ah, due to using the subscription field.
floitsch
2013/11/01 16:57:25
yes.
| |
| 22 expectedEvents.replay(c); | 22 expectedEvents.replay(c); |
| 23 Expect.listEquals(expectedEvents.events, actualEvents.events); | 23 Expect.listEquals(expectedEvents.events, actualEvents.events); |
| 24 | 24 |
| 25 // Test automatic unsubscription on error. | 25 // Test automatic unsubscription on error. |
| 26 c = new StreamController(sync: true); | 26 c = new StreamController(sync: true); |
| 27 expectedEvents = new Events()..add(42)..error("error"); | 27 expectedEvents = new Events()..add(42)..error("error"); |
| 28 actualEvents = new Events.capture(c.stream.asBroadcastStream(), | 28 actualEvents = new Events.capture(c.stream.asBroadcastStream(), |
| 29 cancelOnError: true); | 29 cancelOnError: true); |
| 30 Events sentEvents = | 30 Events sentEvents = |
| 31 new Events()..add(42)..error("error")..add("Are you there?"); | 31 new Events()..add(42)..error("error")..add("Are you there?"); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 | 160 |
| 161 testSingleController() { | 161 testSingleController() { |
| 162 // Test normal flow. | 162 // Test normal flow. |
| 163 var c = new StreamController(sync: true); | 163 var c = new StreamController(sync: true); |
| 164 Events expectedEvents = new Events() | 164 Events expectedEvents = new Events() |
| 165 ..add(42) | 165 ..add(42) |
| 166 ..add("dibs") | 166 ..add("dibs") |
| 167 ..error("error!") | 167 ..error("error!") |
| 168 ..error("error too!") | 168 ..error("error too!") |
| 169 ..close(); | 169 ..close(); |
| 170 Events actualEvents = new Events.capture(c.stream); | 170 CaptureEvents actualEvents = new Events.capture(c.stream); |
| 171 expectedEvents.replay(c); | 171 expectedEvents.replay(c); |
| 172 Expect.listEquals(expectedEvents.events, actualEvents.events); | 172 Expect.listEquals(expectedEvents.events, actualEvents.events); |
| 173 | 173 |
| 174 // Test automatic unsubscription on error. | 174 // Test automatic unsubscription on error. |
| 175 c = new StreamController(sync: true); | 175 c = new StreamController(sync: true); |
| 176 expectedEvents = new Events()..add(42)..error("error"); | 176 expectedEvents = new Events()..add(42)..error("error"); |
| 177 actualEvents = new Events.capture(c.stream, cancelOnError: true); | 177 actualEvents = new Events.capture(c.stream, cancelOnError: true); |
| 178 Events sentEvents = | 178 Events sentEvents = |
| 179 new Events()..add(42)..error("error")..add("Are you there?"); | 179 new Events()..add(42)..error("error")..add("Are you there?"); |
| 180 sentEvents.replay(c); | 180 sentEvents.replay(c); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 Expect.equals(c.stream, c.stream); | 436 Expect.equals(c.stream, c.stream); |
| 437 } | 437 } |
| 438 | 438 |
| 439 main() { | 439 main() { |
| 440 testMultiController(); | 440 testMultiController(); |
| 441 testSingleController(); | 441 testSingleController(); |
| 442 testExtraMethods(); | 442 testExtraMethods(); |
| 443 testClosed(); | 443 testClosed(); |
| 444 testStreamEquals(); | 444 testStreamEquals(); |
| 445 } | 445 } |
| OLD | NEW |