| 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_single_test; | 6 library stream_single_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 'dart:isolate'; | 10 import 'dart:isolate'; |
| 11 import '../../../pkg/unittest/lib/unittest.dart'; | 11 import '../../../pkg/unittest/lib/unittest.dart'; |
| 12 import 'event_helper.dart'; | 12 import 'event_helper.dart'; |
| 13 | 13 |
| 14 main() { | 14 main() { |
| 15 test("tomulti 1", () { | 15 test("tomulti 1", () { |
| 16 StreamController c = new StreamController<int>(); | 16 StreamController c = new StreamController<int>(sync: true); |
| 17 Stream<int> multi = c.stream.asBroadcastStream(); | 17 Stream<int> multi = c.stream.asBroadcastStream(); |
| 18 // Listen twice. | 18 // Listen twice. |
| 19 multi.listen(expectAsync1((v) => Expect.equals(42, v))); | 19 multi.listen(expectAsync1((v) => Expect.equals(42, v))); |
| 20 multi.listen(expectAsync1((v) => Expect.equals(42, v))); | 20 multi.listen(expectAsync1((v) => Expect.equals(42, v))); |
| 21 c.add(42); | 21 c.add(42); |
| 22 }); | 22 }); |
| 23 | 23 |
| 24 test("tomulti 2", () { | 24 test("tomulti 2", () { |
| 25 StreamController c = new StreamController<int>(); | 25 StreamController c = new StreamController<int>(sync: true); |
| 26 Stream<int> multi = c.stream.asBroadcastStream(); | 26 Stream<int> multi = c.stream.asBroadcastStream(); |
| 27 Events expected = new Events.fromIterable([1, 2, 3, 4, 5]); | 27 Events expected = new Events.fromIterable([1, 2, 3, 4, 5]); |
| 28 Events actual1 = new Events.capture(multi); | 28 Events actual1 = new Events.capture(multi); |
| 29 Events actual2 = new Events.capture(multi); | 29 Events actual2 = new Events.capture(multi); |
| 30 actual1.onDone(expectAsync0(() { | 30 actual1.onDone(expectAsync0(() { |
| 31 Expect.listEquals(expected.events, actual1.events); | 31 Expect.listEquals(expected.events, actual1.events); |
| 32 })); | 32 })); |
| 33 actual2.onDone(expectAsync0(() { | 33 actual2.onDone(expectAsync0(() { |
| 34 Expect.listEquals(expected.events, actual2.events); | 34 Expect.listEquals(expected.events, actual2.events); |
| 35 })); | 35 })); |
| 36 expected.replay(c); | 36 expected.replay(c); |
| 37 }); | 37 }); |
| 38 | 38 |
| 39 test("tomulti no-op", () { | 39 test("tomulti no-op", () { |
| 40 StreamController c = new StreamController<int>(); | 40 StreamController c = new StreamController<int>(sync: true); |
| 41 Stream<int> multi = c.stream.asBroadcastStream(); | 41 Stream<int> multi = c.stream.asBroadcastStream(); |
| 42 Events expected = new Events.fromIterable([1, 2, 3, 4, 5]); | 42 Events expected = new Events.fromIterable([1, 2, 3, 4, 5]); |
| 43 Events actual1 = new Events.capture(multi); | 43 Events actual1 = new Events.capture(multi); |
| 44 Events actual2 = new Events.capture(multi); | 44 Events actual2 = new Events.capture(multi); |
| 45 actual1.onDone(expectAsync0(() { | 45 actual1.onDone(expectAsync0(() { |
| 46 Expect.listEquals(expected.events, actual1.events); | 46 Expect.listEquals(expected.events, actual1.events); |
| 47 })); | 47 })); |
| 48 actual2.onDone(expectAsync0(() { | 48 actual2.onDone(expectAsync0(() { |
| 49 Expect.listEquals(expected.events, actual2.events); | 49 Expect.listEquals(expected.events, actual2.events); |
| 50 })); | 50 })); |
| 51 expected.replay(c); | 51 expected.replay(c); |
| 52 }); | 52 }); |
| 53 } | 53 } |
| OLD | NEW |