Chromium Code Reviews| Index: tests/lib/async/stream_controller_async_test.dart |
| diff --git a/tests/lib/async/stream_controller_async_test.dart b/tests/lib/async/stream_controller_async_test.dart |
| index 65e658f32b259b8cf2f236ae969566fe3061d698..2ff57bf558c9129c39da95461f1ffb5ad9dcbe6a 100644 |
| --- a/tests/lib/async/stream_controller_async_test.dart |
| +++ b/tests/lib/async/stream_controller_async_test.dart |
| @@ -10,6 +10,7 @@ import 'dart:async'; |
| import 'dart:isolate'; |
| import '../../../pkg/unittest/lib/unittest.dart'; |
| import 'event_helper.dart'; |
| +import 'stream_state_helper.dart'; |
| testController() { |
| // Test fold |
| @@ -266,111 +267,92 @@ testExtraMethods() { |
| testPause() { |
| test("pause event-unpause", () { |
| - StreamController c = new StreamController(); |
| - Events actualEvents = new Events.capture(c.stream); |
| - Events expectedEvents = new Events(); |
| - expectedEvents.add(42); |
| - c.add(42); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| + StreamProtocolTest test = new StreamProtocolTest(); |
| Completer completer = new Completer(); |
| - actualEvents.pause(completer.future); |
| - c..add(43)..add(44)..close(); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - completer.complete(); |
| - expectedEvents..add(43)..add(44)..close(); |
| - actualEvents.onDone(expectAsync0(() { |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - })); |
| + test..expectListen() |
| + ..expectData(42, () { test.pause(completer.future); }) |
| + ..expectPause(() { |
| + completer.complete(null); |
| + }) |
| + ..expectData(43) |
| + ..expectData(44) |
| + ..expectDone() |
| + ..expectCancel(); |
| + test.listen(); |
| + test.add(42); |
| + test.add(43); |
| + test.add(44); |
| + test.close(); |
| }); |
| test("pause twice event-unpause", () { |
| - StreamController c = new StreamController(); |
| - Events actualEvents = new Events.capture(c.stream); |
| - Events expectedEvents = new Events(); |
| - expectedEvents.add(42); |
| - c.add(42); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| + StreamProtocolTest test = new StreamProtocolTest(); |
| Completer completer = new Completer(); |
| Completer completer2 = new Completer(); |
| - actualEvents.pause(completer.future); |
| - actualEvents.pause(completer2.future); |
| - c..add(43)..add(44)..close(); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - completer.complete(); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - completer2.complete(); |
| - expectedEvents..add(43)..add(44)..close(); |
| - actualEvents.onDone(expectAsync0((){ |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - })); |
| + test..expectListen() |
| + ..expectData(42, () { |
| + test.pause(completer.future); |
|
floitsch
2013/05/30 12:13:48
indent + 2
Lasse Reichstein Nielsen
2013/05/31 05:51:59
Done.
|
| + test.pause(completer2.future); |
| + }) |
| + ..expectPause(() { |
| + completer.future.then(completer2.complete); |
| + completer.complete(null); |
| + }) |
| + ..expectData(43) |
| + ..expectData(44) |
| + ..expectDone() |
| + ..expectCancel(); |
| + test..listen() |
| + ..add(42) |
| + ..add(43) |
| + ..add(44) |
| + ..close(); |
| }); |
| test("pause twice direct-unpause", () { |
| - StreamController c = new StreamController(); |
| - Events actualEvents = new Events.capture(c.stream); |
| - Events expectedEvents = new Events(); |
| - expectedEvents.add(42); |
| - c.add(42); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - actualEvents.pause(); |
| - actualEvents.pause(); |
| - c.add(43); |
| - c.add(44); |
| - c.close(); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - actualEvents.resume(); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - expectedEvents..add(43)..add(44)..close(); |
| - actualEvents.onDone(expectAsync0(() { |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - })); |
| - actualEvents.resume(); |
| + StreamProtocolTest test = new StreamProtocolTest(); |
| + test..expectListen() |
| + ..expectData(42, () { |
| + test.pause(); |
| + test.pause(); |
| + }) |
| + ..expectPause(() { |
| + test.resume(); |
| + test.resume(); |
| + }) |
| + ..expectResume() // This one resumes inpuot because resume is synchronous. |
|
floitsch
2013/05/30 12:13:48
... input... long line.
Lasse Reichstein Nielsen
2013/05/31 05:51:59
Done.
|
| + ..expectData(43) |
| + ..expectData(44) |
| + ..expectDone() |
| + ..expectCancel(); |
| + test..listen() |
| + ..add(42) |
| + ..add(43) |
| + ..add(44) |
| + ..close(); |
| }); |
| test("pause twice direct-event-unpause", () { |
| - StreamController c = new StreamController(); |
| - Events actualEvents = new Events.capture(c.stream); |
| - Events expectedEvents = new Events(); |
| - expectedEvents.add(42); |
| - c.add(42); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| + StreamProtocolTest test = new StreamProtocolTest(); |
| Completer completer = new Completer(); |
| - actualEvents.pause(completer.future); |
| - actualEvents.pause(); |
| - c.add(43); |
| - c.add(44); |
| - c.close(); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - actualEvents.resume(); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - expectedEvents..add(43)..add(44)..close(); |
| - actualEvents.onDone(expectAsync0(() { |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - })); |
| - completer.complete(); |
| - }); |
| - |
| - test("pause twice direct-unpause", () { |
| - StreamController c = new StreamController(); |
| - Events actualEvents = new Events.capture(c.stream); |
| - Events expectedEvents = new Events(); |
| - expectedEvents.add(42); |
| - c.add(42); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - Completer completer = new Completer(); |
| - actualEvents.pause(completer.future); |
| - actualEvents.pause(); |
| - c.add(43); |
| - c.add(44); |
| - c.close(); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - completer.complete(); |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - expectedEvents..add(43)..add(44)..close(); |
| - actualEvents.onDone(expectAsync0(() { |
| - Expect.listEquals(expectedEvents.events, actualEvents.events); |
| - })); |
| - actualEvents.resume(); |
| + test..expectListen() |
| + ..expectData(42, () { |
| + test.pause(); |
| + test.pause(completer.future); |
| + test.add(43); |
| + test.add(44); |
| + test.close(); |
| + }) |
| + ..expectPause(() { |
| + completer.future.then((v) => test.resume()); |
| + completer.complete(null); |
| + }) |
| + ..expectData(43) |
| + ..expectData(44) |
| + ..expectDone() |
| + ..expectCancel(); |
| + test..listen() |
| + ..add(42); |
| }); |
| } |
| @@ -431,75 +413,88 @@ testRethrow() { |
| void testBroadcastController() { |
| test("broadcast-controller-basic", () { |
| - StreamController<int> c = new StreamController.broadcast( |
| - onListen: expectAsync0(() {}), |
| - onCancel: expectAsync0(() {}) |
| - ); |
| - Stream<int> s = c.stream; |
| - s.listen(expectAsync1((x) { expect(x, equals(42)); })); |
| - c.add(42); |
| - c.close(); |
| + StreamProtocolTest test = new StreamProtocolTest.broadcast(); |
| + test..expectListen() |
| + ..expectData(42) |
| + ..expectDone() |
| + ..expectCancel(test.terminate); |
| + test..listen() |
| + ..add(42) |
| + ..close(); |
| }); |
| test("broadcast-controller-listen-twice", () { |
| - StreamController<int> c = new StreamController.broadcast( |
| - onListen: expectAsync0(() {}), |
| - onCancel: expectAsync0(() {}) |
| - ); |
| - c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }, count: 2)); |
| - c.add(42); |
| - c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); |
| - c.add(42); |
| - c.close(); |
| + StreamProtocolTest test = new StreamProtocolTest.broadcast(); |
| + test.expectListen(); |
| + var sub1 = test.listen(); |
| + sub1.expectData(42, () { |
| + var sub2 = test.listen(); |
| + sub1.expectData(37); |
| + sub2.expectData(37); |
| + sub1.expectDone(); |
| + sub2.expectDone(); |
| + test.expectCancel(test.terminate); |
| + |
| + test.add(37); |
| + test.close(); |
| + }); |
| + test.add(42); |
| }); |
| test("broadcast-controller-listen-twice-non-overlap", () { |
| - StreamController<int> c = new StreamController.broadcast( |
| - onListen: expectAsync0(() {}, count: 2), |
| - onCancel: expectAsync0(() {}, count: 2) |
| - ); |
| - var sub = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); |
| - c.add(42); |
| - sub.cancel(); |
| - c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); |
| - c.add(42); |
| - c.close(); |
| + StreamProtocolTest test = new StreamProtocolTest.broadcast(); |
| + test |
| + ..expectListen(() { |
| + test.add(42); |
| + }) |
| + ..expectData(42, () { |
| + test.cancel(); |
| + }) |
| + ..expectCancel(() { |
| + test.listen(); |
| + })..expectListen(() { |
| + test.add(37); |
| + }) |
| + ..expectData(37, () { |
| + test.close(); |
| + }) |
| + ..expectDone() |
| + ..expectCancel(test.terminate); |
| + test.listen(); |
| }); |
| test("broadcast-controller-individual-pause", () { |
| - StreamController<int> c = new StreamController.broadcast( |
| - onListen: expectAsync0(() {}), |
| - onCancel: expectAsync0(() {}) |
| - ); |
| - var sub1 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); |
| - var sub2 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }, |
| - count: 3)); |
| - c.add(42); |
| - sub1.pause(); |
| - c.add(42); |
| - sub1.cancel(); |
| - var sub3 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); |
| - c.add(42); |
| - c.close(); |
| + StreamProtocolTest test = new StreamProtocolTest.broadcast(); |
| + test.expectListen(); |
| + var sub1 = test.listen(); |
| + var sub2 = test.listen(); |
| + var sub3; |
| + sub1.expectData(42, sub1.pause); |
| + sub2.expectData(42); |
| + sub2.expectData(43, () { |
| + sub1.cancel(); |
| + sub3 = test.listen(); |
| + sub2.expectData(44); |
| + sub3.expectData(44, test.terminate); |
| + }); |
| + test.add(42); |
| + test.add(43); |
| + test.add(44); |
| }); |
| test("broadcast-controller-add-in-callback", () { |
| - StreamController<int> c; |
| - c = new StreamController( |
| - onListen: expectAsync0(() {}), |
| - onCancel: expectAsync0(() { |
| - c.add(42); |
| - }) |
| - ); |
| - var sub; |
| - sub = c.stream.asBroadcastStream().listen(expectAsync1((v) { |
| - Expect.equals(37, v); |
| - c.add(21); |
| + StreamProtocolTest test = new StreamProtocolTest.broadcast(); |
| + test.expectListen(); |
| + var sub = test.listen(); |
| + test.add(42); |
| + sub.expectData(42, () { |
| + test.add(87); |
| sub.cancel(); |
| - })); |
| - c.add(37); // Triggers listener, which adds 21 and removes itself. |
| - // Removing listener triggers onCancel which adds another 42. |
| - // Both 21 and 42 are lost because there are no listeners. |
| + }); |
| + test.expectCancel(() { |
| + test.add(37); |
| + test.terminate(); |
| + }); |
| }); |
| } |