Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: tests/lib_strong/async/stream_state_test.dart

Issue 2802973005: Migrate async tests to strong (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Test the event/callback protocol of the stream implementations.
6 library stream_state_test;
7
8 import "package:unittest/unittest.dart";
9 import "stream_state_helper.dart";
10
11 const ms5 = const Duration(milliseconds: 5);
12
13 main() {
14 mainTest(sync: true, asBroadcast: false);
15 mainTest(sync: true, asBroadcast: true);
16 mainTest(sync: false, asBroadcast: false);
17 mainTest(sync: false, asBroadcast: true);
18 }
19
20 void terminateWithDone(t, asBroadcast) {
21 if (asBroadcast) {
22 t..expectCancel()
23 ..expectDone()
24 ..expectBroadcastCancel((_) => t.terminate());
25 } else {
26 t..expectCancel()
27 ..expectDone(t.terminate);
28 }
29 }
30
31 mainTest({bool sync, bool asBroadcast}) {
32 var p = (sync ? "S" : "AS") + (asBroadcast ? "BC" : "SC");
33 test("$p-sub-data-done", () {
34 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync)
35 : new StreamProtocolTest(sync: sync);
36 t..expectListen()
37 ..expectBroadcastListenOpt()
38 ..expectData(42);
39 terminateWithDone(t, asBroadcast);
40 t..listen()..add(42)..close();
41 });
42
43 test("$p-data-done-sub-sync", () {
44 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync)
45 : new StreamProtocolTest(sync: sync);
46 t..expectListen()
47 ..expectBroadcastListenOpt()
48 ..expectData(42);
49 terminateWithDone(t, asBroadcast);
50 t..add(42)..close()..listen();
51 });
52
53 test("$p-data-done-sub-async", () {
54 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync)
55 : new StreamProtocolTest(sync: sync);
56 t..expectListen()
57 ..expectBroadcastListenOpt()
58 ..expectData(42);
59 terminateWithDone(t, asBroadcast);
60 t..add(42)..close()..listen();
61 });
62
63 test("$p-sub-data/pause+resume-done", () {
64 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync)
65 : new StreamProtocolTest(sync: sync);
66 t..expectListen()
67 ..expectBroadcastListenOpt()
68 ..expectData(42, () {
69 t.pause();
70 t.resume();
71 t.close();
72 });
73 terminateWithDone(t, asBroadcast);
74 t..listen()..add(42);
75 });
76
77 test("$p-sub-data-unsubonerror", () {
78 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync)
79 : new StreamProtocolTest(sync: sync);
80 if (asBroadcast) {
81 t..expectListen()
82 ..expectBroadcastListen()
83 ..expectData(42)
84 ..expectError("bad")
85 ..expectBroadcastCancel()
86 ..expectCancel(t.terminate);
87 } else {
88 t..expectListen()
89 ..expectData(42)
90 ..expectCancel()
91 ..expectError("bad", t.terminate);
92 }
93 t..listen(cancelOnError: true)
94 ..add(42)
95 ..error("bad")
96 ..add(43)
97 ..close();
98 });
99
100 test("$p-sub-data-no-unsubonerror", () {
101 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync)
102 : new StreamProtocolTest(sync: sync);
103 t..expectListen()
104 ..expectBroadcastListenOpt()
105 ..expectData(42)
106 ..expectError("bad")
107 ..expectData(43);
108 terminateWithDone(t, asBroadcast);
109 t..listen(cancelOnError: false)
110 ..add(42)
111 ..error("bad")
112 ..add(43)
113 ..close();
114 });
115
116 test("$p-pause-resume-during-event", () {
117 var t = asBroadcast ? new StreamProtocolTest.broadcast(sync: sync)
118 : new StreamProtocolTest(sync: sync);
119 t..expectListen()
120 ..expectBroadcastListenOpt()
121 ..expectData(42, () {
122 t.pause();
123 t.resume();
124 });
125 if (!asBroadcast && !sync) {
126 t..expectPause();
127 }
128 if (asBroadcast && sync) {
129 t..expectDone()
130 ..expectCancel(t.terminate);
131 } else {
132 t..expectCancel()
133 ..expectDone(t.terminate);
134 }
135 t..listen()
136 ..add(42)
137 ..close();
138 });
139
140 test("$p-cancel-on-data", () {
141 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync)
142 : new StreamProtocolTest(sync: sync);
143 t..expectListen()
144 ..expectBroadcastListenOpt()
145 ..expectData(42, t.cancel)
146 ..expectBroadcastCancelOpt()
147 ..expectCancel(t.terminate);
148 t..listen(cancelOnError: false)
149 ..add(42)
150 ..close();
151 });
152
153 test("$p-cancel-on-error", () {
154 var t = asBroadcast ? new StreamProtocolTest.asBroadcast(sync: sync)
155 : new StreamProtocolTest(sync: sync);
156 t..expectListen()
157 ..expectBroadcastListenOpt()
158 ..expectError(42, t.cancel)
159 ..expectBroadcastCancelOpt()
160 ..expectCancel(t.terminate);
161 t..listen(cancelOnError: false)
162 ..error(42)
163 ..close();
164 });
165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698