OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 event/callback protocol of the stream implementations. | 5 // Test the event/callback protocol of the stream implementations. |
6 library stream_state_test; | 6 library stream_state_test; |
7 | 7 |
8 import "../../../pkg/unittest/lib/unittest.dart"; | 8 import "../../../pkg/unittest/lib/unittest.dart"; |
9 import "stream_state_helper.dart"; | 9 import "stream_state_helper.dart"; |
10 | 10 |
11 const ms5 = const Duration(milliseconds: 5); | 11 const ms5 = const Duration(milliseconds: 5); |
12 | 12 |
13 main() { | 13 main() { |
14 mainTest(sync: true, broadcast: false); | 14 mainTest(sync: true, asBroadcast: false); |
15 mainTest(sync: true, broadcast: true); | 15 mainTest(sync: true, asBroadcast: true); |
16 mainTest(sync: false, broadcast: false); | 16 mainTest(sync: false, asBroadcast: false); |
17 mainTest(sync: false, broadcast: true); | 17 mainTest(sync: false, asBroadcast: true); |
18 } | 18 } |
19 | 19 |
20 mainTest({bool sync, bool broadcast}) { | 20 mainTest({bool sync, bool asBroadcast}) { |
21 var p = (sync ? "S" : "AS") + (broadcast ? "BC" : "SC"); | 21 var p = (sync ? "S" : "AS") + (asBroadcast ? "BC" : "SC"); |
22 test("$p-sub-data-done", () { | 22 test("$p-sub-data-done", () { |
23 var t = new StreamProtocolTest(sync: sync, broadcast: broadcast); | 23 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync) |
| 24 : new StreamProtocolTest(sync: sync); |
24 t..expectListen() | 25 t..expectListen() |
| 26 ..expectBroadcastListenOpt() |
25 ..expectData(42) | 27 ..expectData(42) |
26 ..expectDone() | 28 ..expectDone() |
27 ..expectCancel(); | 29 ..expectBroadcastCancelOpt() |
| 30 ..expectCancel(t.terminate); |
28 t..listen()..add(42)..close(); | 31 t..listen()..add(42)..close(); |
29 }); | 32 }); |
30 | 33 |
31 test("$p-data-done-sub-sync", () { | 34 test("$p-data-done-sub-sync", () { |
32 var t = new StreamProtocolTest(sync: sync, broadcast: broadcast); | 35 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync) |
| 36 : new StreamProtocolTest(sync: sync); |
| 37 t.trace = true; |
33 t..expectListen() | 38 t..expectListen() |
| 39 ..expectBroadcastListenOpt() |
34 ..expectData(42) | 40 ..expectData(42) |
35 ..expectDone() | 41 ..expectDone() |
36 ..expectCancel(); | 42 ..expectBroadcastCancelOpt() |
| 43 ..expectCancel(t.terminate); |
37 t..add(42)..close()..listen(); | 44 t..add(42)..close()..listen(); |
38 }); | 45 }); |
39 | 46 |
40 test("$p-data-done-sub-async", () { | 47 test("$p-data-done-sub-async", () { |
41 var t = new StreamProtocolTest(sync: sync, broadcast: broadcast); | 48 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync) |
| 49 : new StreamProtocolTest(sync: sync); |
42 t..expectListen() | 50 t..expectListen() |
| 51 ..expectBroadcastListenOpt() |
43 ..expectData(42) | 52 ..expectData(42) |
44 ..expectDone() | 53 ..expectDone() |
45 ..expectCancel(); | 54 ..expectBroadcastCancelOpt() |
| 55 ..expectCancel(t.terminate); |
46 t..add(42)..close()..listen(); | 56 t..add(42)..close()..listen(); |
47 }); | 57 }); |
48 | 58 |
49 test("$p-sub-data/pause+resume-done", () { | 59 test("$p-sub-data/pause+resume-done", () { |
50 var t = new StreamProtocolTest(sync: sync, broadcast: broadcast); | 60 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync) |
| 61 : new StreamProtocolTest(sync: sync); |
51 t..expectListen() | 62 t..expectListen() |
| 63 ..expectBroadcastListenOpt() |
52 ..expectData(42, () { | 64 ..expectData(42, () { |
53 t.pause(); | 65 t.pause(); |
54 t.resume(); | 66 t.resume(); |
55 t.close(); | 67 t.close(); |
56 }) | 68 }) |
57 ..expectDone() | 69 ..expectDone() |
58 ..expectCancel(); | 70 ..expectBroadcastCancelOpt() |
| 71 ..expectCancel(t.terminate); |
59 t..listen()..add(42); | 72 t..listen()..add(42); |
60 }); | 73 }); |
61 | 74 |
62 test("$p-sub-data-unsubonerror", () { | 75 test("$p-sub-data-unsubonerror", () { |
63 var t = new StreamProtocolTest(sync: sync, broadcast: broadcast); | 76 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync) |
| 77 : new StreamProtocolTest(sync: sync); |
64 t..expectListen() | 78 t..expectListen() |
| 79 ..expectBroadcastListenOpt() |
65 ..expectData(42) | 80 ..expectData(42) |
66 ..expectError("bad") | 81 ..expectError("bad") |
67 ..expectCancel(); | 82 ..expectBroadcastCancelOpt() |
| 83 ..expectCancel(t.terminate); |
68 t..listen(cancelOnError: true) | 84 t..listen(cancelOnError: true) |
69 ..add(42) | 85 ..add(42) |
70 ..error("bad") | 86 ..error("bad") |
71 ..add(43) | 87 ..add(43) |
72 ..close(); | 88 ..close(); |
73 }); | 89 }); |
74 | 90 |
75 test("$p-sub-data-no-unsubonerror", () { | 91 test("$p-sub-data-no-unsubonerror", () { |
76 var t = new StreamProtocolTest(sync: sync, broadcast: broadcast); | 92 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync) |
| 93 : new StreamProtocolTest(sync: sync); |
77 t..expectListen() | 94 t..expectListen() |
| 95 ..expectBroadcastListenOpt() |
78 ..expectData(42) | 96 ..expectData(42) |
79 ..expectError("bad") | 97 ..expectError("bad") |
80 ..expectData(43) | 98 ..expectData(43) |
81 ..expectDone() | 99 ..expectDone() |
82 ..expectCancel(); | 100 ..expectBroadcastCancelOpt() |
| 101 ..expectCancel(t.terminate); |
83 t..listen(cancelOnError: false) | 102 t..listen(cancelOnError: false) |
84 ..add(42) | 103 ..add(42) |
85 ..error("bad") | 104 ..error("bad") |
86 ..add(43) | 105 ..add(43) |
87 ..close(); | 106 ..close(); |
88 }); | 107 }); |
89 | 108 |
90 test("$p-pause-resume-during-event", () { | 109 test("$p-pause-resume-during-event", () { |
91 var t = new StreamProtocolTest(sync: sync, broadcast: broadcast); | 110 var t = asBroadcast ? new StreamProtocolTest.broadcast(sync: sync) |
| 111 : new StreamProtocolTest(sync: sync); |
92 t..expectListen() | 112 t..expectListen() |
| 113 ..expectBroadcastListenOpt() |
93 ..expectData(42, () { | 114 ..expectData(42, () { |
94 t.pause(); | 115 t.pause(); |
95 t.resume(); | 116 t.resume(); |
96 }); | 117 }); |
97 if (!broadcast && !sync) { | 118 if (!asBroadcast && !sync) { |
98 t..expectPause(); | 119 t..expectPause(); |
99 } | 120 } |
100 t..expectDone() | 121 t..expectDone() |
101 ..expectCancel(); | 122 ..expectBroadcastCancelOpt() |
| 123 ..expectCancel(t.terminate); |
102 t..listen() | 124 t..listen() |
103 ..add(42) | 125 ..add(42) |
104 ..close(); | 126 ..close(); |
105 }); | 127 }); |
106 } | 128 } |
OLD | NEW |