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

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

Issue 48733002: Fix bugs in StreamController.addStream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Added test. Fixed typos. Created 7 years, 1 month 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
« no previous file with comments | « tests/co19/co19-co19.status ('k') | tests/lib/async/stream_from_iterable_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'dart:async'; 8 import 'dart:async';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 actual.onDone(() { 668 actual.onDone(() {
669 Expect.listEquals(expected.events, actual.events); 669 Expect.listEquals(expected.events, actual.events);
670 done(); 670 done();
671 }); 671 });
672 } else { 672 } else {
673 Expect.listEquals(expected.events, actual.events); 673 Expect.listEquals(expected.events, actual.events);
674 done(); 674 done();
675 } 675 }
676 }); 676 });
677 }); 677 });
678
679 test("$type-controller-addstream-error-stop", () {
680 // Check that addStream defaults to ending after the first error.
681 var done = expectAsync0((){});
682 var c = broadcast ? new StreamController.broadcast(sync: sync)
683 : new StreamController(sync: sync);
684 var stream = asBroadcast ? c.stream.asBroadcastStream() : c.stream;
685 var actual = new Events.capture(stream);
686
687 var source = new Events();
688 source..add(1)..add(2)..error("BAD")..add(3)..error("FAIL")..close();
689
690 var expected = new Events()..add(1)..add(2)..error("BAD")..close();
691 StreamController sourceController = new StreamController();
692 c.addStream(sourceController.stream).then((_) {
693 c.close().then((_) {
694 Expect.listEquals(expected.events, actual.events);
695 done();
696 });
697 });
698
699 source.replay(sourceController);
700 });
701
702 test("$type-controller-addstream-error-forward", () {
703 // Check that addStream with cancelOnError:false passes all data and errors
704 // to the controller.
705 var done = expectAsync0((){});
706 var c = broadcast ? new StreamController.broadcast(sync: sync)
707 : new StreamController(sync: sync);
708 var stream = asBroadcast ? c.stream.asBroadcastStream() : c.stream;
709 var actual = new Events.capture(stream);
710
711 var source = new Events();
712 source..add(1)..add(2)..addError("BAD")..add(3)..addError("FAIL")..close();
713
714 StreamController sourceController = new StreamController();
715 c.addStream(sourceController.stream, cancelOnError: false).then((_) {
716 c.close().then((_) {
717 Expect.listEquals(source.events, actual.events);
718 done();
719 });
720 });
721
722 source.replay(sourceController);
723 });
724
725 test("$type-controller-addstream-twice", () {
726 // Using addStream twice on the same stream
727 var done = expectAsync0((){});
728 var c = broadcast ? new StreamController.broadcast(sync: sync)
729 : new StreamController(sync: sync);
730 var stream = asBroadcast ? c.stream.asBroadcastStream() : c.stream;
731 var actual = new Events.capture(stream);
732
733 // Streams of five events, throws on 3.
734 Stream s1 = new Stream.fromIterable([1,2,3,4,5])
735 .map((x) => (x == 3 ? throw x : x));
736 Stream s2 = new Stream.fromIterable([1,2,3,4,5])
737 .map((x) => (x == 3 ? throw x : x));
738
739 Events expected = new Events();
740 expected..add(1)..add(2)..error(3);
741 expected..add(1)..add(2)..error(3)..add(4)..add(5);
742 expected..close();
743
744 c.addStream(s1).then((_) {
745 c.addStream(s2, cancelOnError: false).then((_) {
746 c.close().then((_) {
747 Expect.listEquals(expected.events, actual.events);
748 done();
749 });
750 });
751 });
752 });
678 } 753 }
679 754
680 main() { 755 main() {
681 testController(); 756 testController();
682 testSingleController(); 757 testSingleController();
683 testExtraMethods(); 758 testExtraMethods();
684 testPause(); 759 testPause();
685 testRethrow(); 760 testRethrow();
686 testBroadcastController(); 761 testBroadcastController();
687 testAsBroadcast(); 762 testAsBroadcast();
688 testSink(sync: true, broadcast: false, asBroadcast: false); 763 testSink(sync: true, broadcast: false, asBroadcast: false);
689 testSink(sync: true, broadcast: false, asBroadcast: true); 764 testSink(sync: true, broadcast: false, asBroadcast: true);
690 testSink(sync: true, broadcast: true, asBroadcast: false); 765 testSink(sync: true, broadcast: true, asBroadcast: false);
691 testSink(sync: false, broadcast: false, asBroadcast: false); 766 testSink(sync: false, broadcast: false, asBroadcast: false);
692 testSink(sync: false, broadcast: false, asBroadcast: true); 767 testSink(sync: false, broadcast: false, asBroadcast: true);
693 testSink(sync: false, broadcast: true, asBroadcast: false); 768 testSink(sync: false, broadcast: true, asBroadcast: false);
694 } 769 }
OLDNEW
« no previous file with comments | « tests/co19/co19-co19.status ('k') | tests/lib/async/stream_from_iterable_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698