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

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

Issue 16007003: Optimize internals of multiplex-streams. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Now relative to correct base Created 7 years, 6 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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() { 432 void testBroadcastController() {
433 test("multiplex-basic", () { 433 test("broadcast-controller-basic", () {
434 StreamController<int> c = new StreamController.multiplex( 434 StreamController<int> c = new StreamController.broadcast(
435 onListen: expectAsync0(() {}), 435 onListen: expectAsync0(() {}),
436 onCancel: expectAsync0(() {}) 436 onCancel: expectAsync0(() {})
437 ); 437 );
438 Stream<int> s = c.stream; 438 Stream<int> s = c.stream;
439 s.listen(expectAsync1((x) { expect(x, equals(42)); })); 439 s.listen(expectAsync1((x) { expect(x, equals(42)); }));
440 c.add(42); 440 c.add(42);
441 c.close(); 441 c.close();
442 }); 442 });
443 443
444 test("multiplex-listen-twice", () { 444 test("broadcast-controller-listen-twice", () {
445 StreamController<int> c = new StreamController.multiplex( 445 StreamController<int> c = new StreamController.broadcast(
446 onListen: expectAsync0(() {}), 446 onListen: expectAsync0(() {}),
447 onCancel: expectAsync0(() {}) 447 onCancel: expectAsync0(() {})
448 ); 448 );
449 c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }, count: 2)); 449 c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }, count: 2));
450 c.add(42); 450 c.add(42);
451 c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); 451 c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }));
452 c.add(42); 452 c.add(42);
453 c.close(); 453 c.close();
454 }); 454 });
455 455
456 test("multiplex-listen-twice-non-overlap", () { 456 test("broadcast-controller-listen-twice-non-overlap", () {
457 StreamController<int> c = new StreamController.multiplex( 457 StreamController<int> c = new StreamController.broadcast(
458 onListen: expectAsync0(() {}, count: 2), 458 onListen: expectAsync0(() {}, count: 2),
459 onCancel: expectAsync0(() {}, count: 2) 459 onCancel: expectAsync0(() {}, count: 2)
460 ); 460 );
461 var sub = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); 461 var sub = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }));
462 c.add(42); 462 c.add(42);
463 sub.cancel(); 463 sub.cancel();
464 c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); 464 c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }));
465 c.add(42); 465 c.add(42);
466 c.close(); 466 c.close();
467 }); 467 });
468 468
469 test("multiplex-individual-pause", () { 469 test("broadcast-controller-individual-pause", () {
470 StreamController<int> c = new StreamController.multiplex( 470 StreamController<int> c = new StreamController.broadcast(
471 onListen: expectAsync0(() {}), 471 onListen: expectAsync0(() {}),
472 onCancel: expectAsync0(() {}) 472 onCancel: expectAsync0(() {})
473 ); 473 );
474 var sub1 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); 474 var sub1 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }));
475 var sub2 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }, 475 var sub2 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); },
476 count: 3)); 476 count: 3));
477 c.add(42); 477 c.add(42);
478 sub1.pause(); 478 sub1.pause();
479 c.add(42); 479 c.add(42);
480 sub1.cancel(); 480 sub1.cancel();
481 var sub3 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); })); 481 var sub3 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }));
482 c.add(42); 482 c.add(42);
483 c.close(); 483 c.close();
484 }); 484 });
485 } 485 }
486 486
487 main() { 487 main() {
488 testController(); 488 testController();
489 testSingleController(); 489 testSingleController();
490 testExtraMethods(); 490 testExtraMethods();
491 testPause(); 491 testPause();
492 testRethrow(); 492 testRethrow();
493 testMultiplex(); 493 testBroadcastController();
494 } 494 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698