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(false); | 14 mainTest(false); |
15 // TODO(floitsch): reenable? | 15 // TODO(floitsch): reenable? |
16 // mainTest(true); | 16 // mainTest(true); |
17 } | 17 } |
18 | 18 |
19 mainTest(bool broadcast) { | 19 mainTest(bool broadcast) { |
20 var p = broadcast ? "BC" : "SC"; | 20 var p = broadcast ? "BC" : "SC"; |
21 test("$p-sub-data-done", () { | 21 test("$p-sub-data-done", () { |
22 var t = new StreamProtocolTest(broadcast); | 22 var t = new StreamProtocolTest(broadcast); |
23 t..expectSubscription(true, false) | 23 t..expectSubscription() |
24 ..expectData(42) | 24 ..expectData(42) |
25 ..expectDone() | 25 ..expectDone() |
26 ..expectSubscription(false, false); | 26 ..expectCancel(); |
27 t..subscribe()..add(42)..close(); | 27 t..subscribe()..add(42)..close(); |
28 }); | 28 }); |
29 | 29 |
30 test("$p-data-done-sub", () { | 30 test("$p-data-done-sub", () { |
31 var t = new StreamProtocolTest(broadcast); | 31 var t = new StreamProtocolTest(broadcast); |
32 if (broadcast) { | 32 if (broadcast) { |
33 t..expectDone(); | 33 t..expectDone(); |
34 } else { | 34 } else { |
35 t..expectSubscription(true, false) | 35 t..expectSubscription() |
36 ..expectData(42) | 36 ..expectData(42) |
37 ..expectDone() | 37 ..expectDone() |
38 ..expectSubscription(false, false); | 38 ..expectCancel(); |
39 } | 39 } |
40 t..add(42)..close()..subscribe(); | 40 t..add(42)..close()..subscribe(); |
41 }); | 41 }); |
42 | 42 |
43 test("$p-sub-data/pause+resume-done", () { | 43 test("$p-sub-data/pause+resume-done", () { |
44 var t = new StreamProtocolTest(broadcast); | 44 var t = new StreamProtocolTest(broadcast); |
45 t..expectSubscription(true, false) | 45 t..expectSubscription() |
46 ..expectData(42, () { | 46 ..expectData(42, () { |
47 t.pause(); | 47 t.pause(); |
48 t.resume(); | 48 t.resume(); |
49 t.close(); | 49 t.close(); |
50 }) | 50 }) |
51 ..expectDone() | 51 ..expectDone() |
52 ..expectSubscription(false, false); | 52 ..expectCancel(); |
53 t..subscribe()..add(42); | 53 t..subscribe()..add(42); |
54 }); | 54 }); |
55 | 55 |
56 test("$p-sub-data-unsubonerror", () { | 56 test("$p-sub-data-unsubonerror", () { |
57 var t = new StreamProtocolTest(broadcast); | 57 var t = new StreamProtocolTest(broadcast); |
58 t..expectSubscription(true, false) | 58 t..expectSubscription() |
59 ..expectData(42) | 59 ..expectData(42) |
60 ..expectError("bad") | 60 ..expectError("bad") |
61 ..expectSubscription(false, !broadcast); | 61 ..expectCancel(); |
62 t..subscribe(cancelOnError: true) | 62 t..subscribe(cancelOnError: true) |
63 ..add(42) | 63 ..add(42) |
64 ..error("bad") | 64 ..error("bad") |
65 ..add(43) | 65 ..add(43) |
66 ..close(); | 66 ..close(); |
67 }); | 67 }); |
68 | 68 |
69 test("$p-sub-data-no-unsubonerror", () { | 69 test("$p-sub-data-no-unsubonerror", () { |
70 var t = new StreamProtocolTest(broadcast); | 70 var t = new StreamProtocolTest(broadcast); |
71 t..expectSubscription(true, false) | 71 t..expectSubscription() |
72 ..expectData(42) | 72 ..expectData(42) |
73 ..expectError("bad") | 73 ..expectError("bad") |
74 ..expectData(43) | 74 ..expectData(43) |
75 ..expectDone() | 75 ..expectDone() |
76 ..expectSubscription(false, false); | 76 ..expectCancel(); |
77 t..subscribe(cancelOnError: false) | 77 t..subscribe(cancelOnError: false) |
78 ..add(42) | 78 ..add(42) |
79 ..error("bad") | 79 ..error("bad") |
80 ..add(43) | 80 ..add(43) |
81 ..close(); | 81 ..close(); |
82 }); | 82 }); |
83 | 83 |
84 test("$p-pause-resume-during-event", () { | 84 test("$p-pause-resume-during-event", () { |
85 var t = new StreamProtocolTest(broadcast); | 85 var t = new StreamProtocolTest(broadcast); |
86 t..expectSubscription(true, false) | 86 t..expectSubscription() |
87 ..expectData(42, () { | 87 ..expectData(42, () { |
88 t.pause(); | 88 t.pause(); |
89 t.resume(); | 89 t.resume(); |
90 }) | 90 }) |
91 ..expectDone() | 91 ..expectDone() |
92 ..expectSubscription(false, false); | 92 ..expectCancel(); |
93 t..subscribe() | 93 t..subscribe() |
94 ..add(42) | 94 ..add(42) |
95 ..close(); | 95 ..close(); |
96 }); | 96 }); |
97 | |
98 test("$p-cancel-sub-during-event", () { | |
99 var t = new StreamProtocolTest(broadcast); | |
100 t..expectSubscription(true, false) | |
101 ..expectData(42, () { | |
102 t.cancel(); | |
103 t.subscribe(); | |
104 }) | |
105 ..expectData(43) | |
106 ..expectDone() | |
107 ..expectSubscription(false, false); | |
108 t..subscribe() | |
109 ..add(42) | |
110 ..add(43) | |
111 ..close(); | |
112 }); | |
113 | |
114 test("$p-cancel-sub-during-callback", () { | |
115 var t = new StreamProtocolTest(broadcast); | |
116 t..expectSubscription(true, false) | |
117 ..expectData(42, () { | |
118 t.pause(); | |
119 }) | |
120 ..expectPause(true, () { | |
121 t.cancel(); // Cancels pause | |
122 t.subscribe(); | |
123 }) | |
124 ..expectPause(false) | |
125 ..expectData(43) | |
126 ..expectDone() | |
127 ..expectSubscription(false, false); | |
128 t..subscribe() | |
129 ..add(42) | |
130 ..add(43) | |
131 ..close(); | |
132 }); | |
133 | |
134 test("$p-sub-after-done-is-done", () { | |
135 var t = new StreamProtocolTest(broadcast); | |
136 t..expectSubscription(true, false) | |
137 ..expectDone() | |
138 ..expectSubscription(false, false) | |
139 ..expectDone(); | |
140 t..subscribe() | |
141 ..close() | |
142 ..subscribe(); // Subscribe after done does not cause callbacks at all. | |
143 }); | |
144 } | 97 } |
OLD | NEW |