| OLD | NEW |
| 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 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 678 |
| 679 test("$type-controller-addstream-error-stop", () { | 679 test("$type-controller-addstream-error-stop", () { |
| 680 // Check that addStream defaults to ending after the first error. | 680 // Check that addStream defaults to ending after the first error. |
| 681 var done = expectAsync0((){}); | 681 var done = expectAsync0((){}); |
| 682 var c = broadcast ? new StreamController.broadcast(sync: sync) | 682 StreamController c = broadcast |
| 683 : new StreamController(sync: sync); | 683 ? new StreamController.broadcast(sync: sync) |
| 684 var stream = asBroadcast ? c.stream.asBroadcastStream() : c.stream; | 684 : new StreamController(sync: sync); |
| 685 Stream stream = asBroadcast ? c.stream.asBroadcastStream() : c.stream; |
| 685 var actual = new Events.capture(stream); | 686 var actual = new Events.capture(stream); |
| 686 | 687 |
| 687 var source = new Events(); | 688 var source = new Events(); |
| 688 source..add(1)..add(2)..error("BAD")..add(3)..error("FAIL")..close(); | 689 source..add(1)..add(2)..error("BAD")..add(3)..error("FAIL")..close(); |
| 689 | 690 |
| 690 var expected = new Events()..add(1)..add(2)..error("BAD")..close(); | 691 var expected = new Events()..add(1)..add(2)..error("BAD")..close(); |
| 691 StreamController sourceController = new StreamController(); | 692 StreamController sourceController = new StreamController(); |
| 692 c.addStream(sourceController.stream).then((_) { | 693 c.addStream(sourceController.stream).then((_) { |
| 693 c.close().then((_) { | 694 c.close().then((_) { |
| 694 Expect.listEquals(expected.events, actual.events); | 695 Expect.listEquals(expected.events, actual.events); |
| 695 done(); | 696 done(); |
| 696 }); | 697 }); |
| 697 }); | 698 }); |
| 698 | 699 |
| 699 source.replay(sourceController); | 700 source.replay(sourceController); |
| 700 }); | 701 }); |
| 701 | 702 |
| 702 test("$type-controller-addstream-error-forward", () { | 703 test("$type-controller-addstream-error-forward", () { |
| 703 // Check that addStream with cancelOnError:false passes all data and errors | 704 // Check that addStream with cancelOnError:false passes all data and errors |
| 704 // to the controller. | 705 // to the controller. |
| 705 var done = expectAsync0((){}); | 706 var done = expectAsync0((){}); |
| 706 var c = broadcast ? new StreamController.broadcast(sync: sync) | 707 StreamController c = broadcast |
| 707 : new StreamController(sync: sync); | 708 ? new StreamController.broadcast(sync: sync) |
| 708 var stream = asBroadcast ? c.stream.asBroadcastStream() : c.stream; | 709 : new StreamController(sync: sync); |
| 710 Stream stream = asBroadcast ? c.stream.asBroadcastStream() : c.stream; |
| 709 var actual = new Events.capture(stream); | 711 var actual = new Events.capture(stream); |
| 710 | 712 |
| 711 var source = new Events(); | 713 var source = new Events(); |
| 712 source..add(1)..add(2)..addError("BAD")..add(3)..addError("FAIL")..close(); | 714 source..add(1)..add(2)..addError("BAD")..add(3)..addError("FAIL")..close(); |
| 713 | 715 |
| 714 StreamController sourceController = new StreamController(); | 716 StreamController sourceController = new StreamController(); |
| 715 c.addStream(sourceController.stream, cancelOnError: false).then((_) { | 717 c.addStream(sourceController.stream, cancelOnError: false).then((_) { |
| 716 c.close().then((_) { | 718 c.close().then((_) { |
| 717 Expect.listEquals(source.events, actual.events); | 719 Expect.listEquals(source.events, actual.events); |
| 718 done(); | 720 done(); |
| 719 }); | 721 }); |
| 720 }); | 722 }); |
| 721 | 723 |
| 722 source.replay(sourceController); | 724 source.replay(sourceController); |
| 723 }); | 725 }); |
| 724 | 726 |
| 725 test("$type-controller-addstream-twice", () { | 727 test("$type-controller-addstream-twice", () { |
| 726 // Using addStream twice on the same stream | 728 // Using addStream twice on the same stream |
| 727 var done = expectAsync0((){}); | 729 var done = expectAsync0((){}); |
| 728 var c = broadcast ? new StreamController.broadcast(sync: sync) | 730 StreamController c = broadcast |
| 729 : new StreamController(sync: sync); | 731 ? new StreamController.broadcast(sync: sync) |
| 730 var stream = asBroadcast ? c.stream.asBroadcastStream() : c.stream; | 732 : new StreamController(sync: sync); |
| 733 Stream stream = asBroadcast ? c.stream.asBroadcastStream() : c.stream; |
| 731 var actual = new Events.capture(stream); | 734 var actual = new Events.capture(stream); |
| 732 | 735 |
| 733 // Streams of five events, throws on 3. | 736 // Streams of five events, throws on 3. |
| 734 Stream s1 = new Stream.fromIterable([1,2,3,4,5]) | 737 Stream s1 = new Stream.fromIterable([1,2,3,4,5]) |
| 735 .map((x) => (x == 3 ? throw x : x)); | 738 .map((x) => (x == 3 ? throw x : x)); |
| 736 Stream s2 = new Stream.fromIterable([1,2,3,4,5]) | 739 Stream s2 = new Stream.fromIterable([1,2,3,4,5]) |
| 737 .map((x) => (x == 3 ? throw x : x)); | 740 .map((x) => (x == 3 ? throw x : x)); |
| 738 | 741 |
| 739 Events expected = new Events(); | 742 Events expected = new Events(); |
| 740 expected..add(1)..add(2)..error(3); | 743 expected..add(1)..add(2)..error(3); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 760 testRethrow(); | 763 testRethrow(); |
| 761 testBroadcastController(); | 764 testBroadcastController(); |
| 762 testAsBroadcast(); | 765 testAsBroadcast(); |
| 763 testSink(sync: true, broadcast: false, asBroadcast: false); | 766 testSink(sync: true, broadcast: false, asBroadcast: false); |
| 764 testSink(sync: true, broadcast: false, asBroadcast: true); | 767 testSink(sync: true, broadcast: false, asBroadcast: true); |
| 765 testSink(sync: true, broadcast: true, asBroadcast: false); | 768 testSink(sync: true, broadcast: true, asBroadcast: false); |
| 766 testSink(sync: false, broadcast: false, asBroadcast: false); | 769 testSink(sync: false, broadcast: false, asBroadcast: false); |
| 767 testSink(sync: false, broadcast: false, asBroadcast: true); | 770 testSink(sync: false, broadcast: false, asBroadcast: true); |
| 768 testSink(sync: false, broadcast: true, asBroadcast: false); | 771 testSink(sync: false, broadcast: true, asBroadcast: false); |
| 769 } | 772 } |
| OLD | NEW |