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

Side by Side Diff: tests/lib/async/stream_controller_async_test.dart

Issue 14753009: Make StreamSubscription be the active part of a stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
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_controller_async_test; 6 library stream_controller_async_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';
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 }); 46 });
47 47
48 test("Single-subscription StreamController.fold throws", () { 48 test("Single-subscription StreamController.fold throws", () {
49 StreamController c = new StreamController(); 49 StreamController c = new StreamController();
50 Stream stream = c.stream; 50 Stream stream = c.stream;
51 stream.fold(0, (a,b) { throw "Fnyf!"; }) 51 stream.fold(0, (a,b) { throw "Fnyf!"; })
52 .catchError(expectAsync1((e) { Expect.equals("Fnyf!", e); })); 52 .catchError(expectAsync1((e) { Expect.equals("Fnyf!", e); }));
53 c.add(42); 53 c.add(42);
54 }); 54 });
55 55
56 test("Single-subscription StreamController subscription changes", () {
57 StreamController c = new StreamController();
58 EventSink sink = c.sink;
59 Stream stream = c.stream;
60 int counter = 0;
61 var subscription;
62 subscription = stream.listen((data) {
63 counter += data;
64 Expect.throws(() => stream.listen(null), (e) => e is StateError);
65 subscription.cancel();
66 stream.listen((data) {
67 counter += data * 10;
68 },
69 onDone: expectAsync0(() {
70 Expect.equals(1 + 20, counter);
71 }));
72 });
73 sink.add(1);
74 sink.add(2);
75 sink.close();
76 });
77
78 test("Single-subscription StreamController events are buffered when" 56 test("Single-subscription StreamController events are buffered when"
79 " there is no subscriber", 57 " there is no subscriber",
80 () { 58 () {
81 StreamController c = new StreamController(); 59 StreamController c = new StreamController();
82 EventSink sink = c.sink; 60 EventSink sink = c.sink;
83 Stream stream = c.stream; 61 Stream stream = c.stream;
84 int counter = 0; 62 int counter = 0;
85 sink.add(1); 63 sink.add(1);
86 sink.add(2); 64 sink.add(2);
87 sink.close(); 65 sink.close();
88 stream.listen( 66 stream.listen(
89 (data) { 67 (data) {
90 counter += data; 68 counter += data;
91 }, 69 },
92 onDone: expectAsync0(() { 70 onDone: expectAsync0(() {
93 Expect.equals(3, counter); 71 Expect.equals(3, counter);
94 })); 72 }));
95 }); 73 });
96
97 // Test subscription changes while firing.
98 test("Single-subscription StreamController subscription changes while firing",
99 () {
100 StreamController c = new StreamController();
101 EventSink sink = c.sink;
102 Stream stream = c.stream;
103 int counter = 0;
104 var subscription = stream.listen(null);
105 subscription.onData(expectAsync1((data) {
106 counter += data;
107 subscription.cancel();
108 stream.listen((data) {
109 counter += 10 * data;
110 },
111 onDone: expectAsync0(() {
112 Expect.equals(1 + 20 + 30 + 40 + 50, counter);
113 }));
114 Expect.throws(() => stream.listen(null), (e) => e is StateError);
115 }));
116 sink.add(1); // seen by stream 1
117 sink.add(2); // seen by stream 10 and 100
118 sink.add(3); // -"-
119 sink.add(4); // -"-
120 sink.add(5); // seen by stream 10
121 sink.close();
122 });
123 } 74 }
124 75
125 testExtraMethods() { 76 testExtraMethods() {
126 Events sentEvents = new Events()..add(7)..add(9)..add(13)..add(87)..close(); 77 Events sentEvents = new Events()..add(7)..add(9)..add(13)..add(87)..close();
127 78
128 test("forEach", () { 79 test("forEach", () {
129 StreamController c = new StreamController(); 80 StreamController c = new StreamController();
130 Events actualEvents = new Events(); 81 Events actualEvents = new Events();
131 Future f = c.stream.forEach(actualEvents.add); 82 Future f = c.stream.forEach(actualEvents.add);
132 f.then(expectAsync1((_) { 83 f.then(expectAsync1((_) {
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 testFuture("drain", (s, act) => s.drain().then(act)); 429 testFuture("drain", (s, act) => s.drain().then(act));
479 } 430 }
480 431
481 main() { 432 main() {
482 testController(); 433 testController();
483 testSingleController(); 434 testSingleController();
484 testExtraMethods(); 435 testExtraMethods();
485 testPause(); 436 testPause();
486 testRethrow(); 437 testRethrow();
487 } 438 }
OLDNEW
« no previous file with comments | « sdk/lib/mdv_observe_impl/mdv_observe_impl.dart ('k') | tests/lib/async/stream_state_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698