| 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_test; | 6 library stream_controller_test; |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 } | 666 } |
| 667 int i = 1; | 667 int i = 1; |
| 668 c = new StreamController.broadcast(onListen: send, sync: true); | 668 c = new StreamController.broadcast(onListen: send, sync: true); |
| 669 c.stream.listen((v) { | 669 c.stream.listen((v) { |
| 670 Expect.equals(i++, v); | 670 Expect.equals(i++, v); |
| 671 }, onDone: asyncEnd); | 671 }, onDone: asyncEnd); |
| 672 c.add(2); | 672 c.add(2); |
| 673 c.close(); | 673 c.close(); |
| 674 } | 674 } |
| 675 | 675 |
| 676 void testSyncControllerNotReentrant() { |
| 677 Stream emptyStream = (new StreamController.broadcast()..close()).stream; |
| 678 asyncStart(); |
| 679 for (int listenerCount = 1; listenerCount <= 2; listenerCount++) { |
| 680 StreamController c = new StreamController.broadcast(sync: true); |
| 681 for (int i = 0; i < listenerCount; i++) { |
| 682 asyncStart(); |
| 683 asyncStart(); |
| 684 c.stream.listen((v) { |
| 685 Expect.equals(42, v); |
| 686 Expect.throws(() { |
| 687 c.add(37); |
| 688 }); |
| 689 Expect.throws(() { |
| 690 c.addError(37); |
| 691 }); |
| 692 Expect.throws(() { |
| 693 c.addStream(emptyStream); |
| 694 }); |
| 695 Expect.throws(() { |
| 696 c.close(); |
| 697 }); |
| 698 asyncEnd(); |
| 699 }, onError: (e, s) { |
| 700 Expect.equals(87, e); |
| 701 Expect.throws(() { |
| 702 c.add(37); |
| 703 }); |
| 704 Expect.throws(() { |
| 705 c.addError(37); |
| 706 }); |
| 707 Expect.throws(() { |
| 708 c.addStream(emptyStream); |
| 709 }); |
| 710 Expect.throws(() { |
| 711 c.close(); |
| 712 }); |
| 713 asyncEnd(); |
| 714 }); |
| 715 } |
| 716 c.add(42); |
| 717 c.addError(87); |
| 718 } |
| 719 asyncEnd(); |
| 720 } |
| 721 |
| 676 main() { | 722 main() { |
| 677 asyncStart(); | 723 asyncStart(); |
| 678 testMultiController(); | 724 testMultiController(); |
| 679 testSingleController(); | 725 testSingleController(); |
| 680 testExtraMethods(); | 726 testExtraMethods(); |
| 681 testClosed(); | 727 testClosed(); |
| 682 testCloseFuture(); | 728 testCloseFuture(); |
| 683 testCloseFuture2(); | 729 testCloseFuture2(); |
| 684 testCloseFuture3(); | 730 testCloseFuture3(); |
| 685 testStreamEquals(); | 731 testStreamEquals(); |
| 686 testCancelThrow(); | 732 testCancelThrow(); |
| 687 testCancelThrow2(); | 733 testCancelThrow2(); |
| 688 testCancelThrow3(); | 734 testCancelThrow3(); |
| 689 testBroadcastListenAfterClose(); | 735 testBroadcastListenAfterClose(); |
| 690 testBroadcastListenAfterClosePaused(); | 736 testBroadcastListenAfterClosePaused(); |
| 691 testAsBroadcastListenAfterClose(); | 737 testAsBroadcastListenAfterClose(); |
| 692 testAsBroadcastListenAfterClosePaused(); | 738 testAsBroadcastListenAfterClosePaused(); |
| 693 testEventInListen(); | 739 testEventInListen(); |
| 740 testSyncControllerNotReentrant(); |
| 694 asyncEnd(); | 741 asyncEnd(); |
| 695 } | 742 } |
| OLD | NEW |