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 "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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 testStreamError("handleError", (s, act) => s.handleError(act)); | 422 testStreamError("handleError", (s, act) => s.handleError(act)); |
423 testStreamError("handleTest", (s, act) => s.handleError((v) {}, test: act)); | 423 testStreamError("handleTest", (s, act) => s.handleError((v) {}, test: act)); |
424 testFuture("forEach", (s, act) => s.forEach(act)); | 424 testFuture("forEach", (s, act) => s.forEach(act)); |
425 testFuture("every", (s, act) => s.every(act)); | 425 testFuture("every", (s, act) => s.every(act)); |
426 testFuture("any", (s, act) => s.any(act)); | 426 testFuture("any", (s, act) => s.any(act)); |
427 testFuture("reduce", (s, act) => s.reduce((a,b) => act(b))); | 427 testFuture("reduce", (s, act) => s.reduce((a,b) => act(b))); |
428 testFuture("fold", (s, act) => s.fold(0, (a,b) => act(b))); | 428 testFuture("fold", (s, act) => s.fold(0, (a,b) => act(b))); |
429 testFuture("drain", (s, act) => s.drain().then(act)); | 429 testFuture("drain", (s, act) => s.drain().then(act)); |
430 } | 430 } |
431 | 431 |
| 432 void testMultiplex() { |
| 433 test("multiplex-basic", () { |
| 434 StreamController<int> c = new StreamController.multiplex( |
| 435 onListen: expectAsync0(() {}), |
| 436 onCancel: expectAsync0(() {}) |
| 437 ); |
| 438 Stream<int> s = c.stream; |
| 439 s.listen(expectAsync1((x) { expect(x, equals(42)); })); |
| 440 c.add(42); |
| 441 c.close(); |
| 442 }); |
| 443 |
| 444 test("multiplex-listen-twice", () { |
| 445 StreamController<int> c = new StreamController.multiplex( |
| 446 onListen: expectAsync0(() {}), |
| 447 onCancel: expectAsync0(() {}) |
| 448 ); |
| 449 c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }, count: 2)); |
| 450 c.add(42); |
| 451 c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); |
| 452 c.add(42); |
| 453 c.close(); |
| 454 }); |
| 455 |
| 456 test("multiplex-listen-twice-non-overlap", () { |
| 457 StreamController<int> c = new StreamController.multiplex( |
| 458 onListen: expectAsync0(() {}, count: 2), |
| 459 onCancel: expectAsync0(() {}, count: 2) |
| 460 ); |
| 461 var sub = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); |
| 462 c.add(42); |
| 463 sub.cancel(); |
| 464 c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); |
| 465 c.add(42); |
| 466 c.close(); |
| 467 }); |
| 468 |
| 469 test("multiplex-individual-pause", () { |
| 470 StreamController<int> c = new StreamController.multiplex( |
| 471 onListen: expectAsync0(() {}), |
| 472 onCancel: expectAsync0(() {}) |
| 473 ); |
| 474 var sub1 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); |
| 475 var sub2 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }, |
| 476 count: 3)); |
| 477 c.add(42); |
| 478 sub1.pause(); |
| 479 c.add(42); |
| 480 sub1.cancel(); |
| 481 var sub3 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); |
| 482 c.add(42); |
| 483 c.close(); |
| 484 }); |
| 485 } |
| 486 |
432 main() { | 487 main() { |
433 testController(); | 488 testController(); |
434 testSingleController(); | 489 testSingleController(); |
435 testExtraMethods(); | 490 testExtraMethods(); |
436 testPause(); | 491 testPause(); |
437 testRethrow(); | 492 testRethrow(); |
| 493 testMultiplex(); |
438 } | 494 } |
OLD | NEW |