OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // Test the basic StreamController and StreamController.singleSubscription. |
| 6 library stream_single_test; |
| 7 |
| 8 import "package:expect/expect.dart"; |
| 9 import 'dart:async'; |
| 10 import 'package:unittest/unittest.dart'; |
| 11 import 'event_helper.dart'; |
| 12 |
| 13 main() { |
| 14 test("tomulti 1", () { |
| 15 StreamController c = new StreamController<int>(sync: true); |
| 16 Stream<int> multi = c.stream.asBroadcastStream(); |
| 17 // Listen twice. |
| 18 multi.listen(expectAsync((v) => Expect.equals(42, v))); |
| 19 multi.listen(expectAsync((v) => Expect.equals(42, v))); |
| 20 c.add(42); |
| 21 }); |
| 22 |
| 23 test("tomulti 2", () { |
| 24 StreamController c = new StreamController<int>(sync: true); |
| 25 Stream<int> multi = c.stream.asBroadcastStream(); |
| 26 Events expected = new Events.fromIterable([1, 2, 3, 4, 5]); |
| 27 Events actual1 = new Events.capture(multi); |
| 28 Events actual2 = new Events.capture(multi); |
| 29 actual1.onDone(expectAsync(() { |
| 30 Expect.listEquals(expected.events, actual1.events); |
| 31 })); |
| 32 actual2.onDone(expectAsync(() { |
| 33 Expect.listEquals(expected.events, actual2.events); |
| 34 })); |
| 35 expected.replay(c); |
| 36 }); |
| 37 |
| 38 test("tomulti no-op", () { |
| 39 StreamController c = new StreamController<int>(sync: true); |
| 40 Stream<int> multi = c.stream.asBroadcastStream(); |
| 41 Events expected = new Events.fromIterable([1, 2, 3, 4, 5]); |
| 42 Events actual1 = new Events.capture(multi); |
| 43 Events actual2 = new Events.capture(multi); |
| 44 actual1.onDone(expectAsync(() { |
| 45 Expect.listEquals(expected.events, actual1.events); |
| 46 })); |
| 47 actual2.onDone(expectAsync(() { |
| 48 Expect.listEquals(expected.events, actual2.events); |
| 49 })); |
| 50 expected.replay(c); |
| 51 }); |
| 52 } |
OLD | NEW |