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

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

Issue 16240008: Make StreamController be a StreamSink, not just an EventSink. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 ..expectData(37, () { 457 ..expectData(37, () {
458 test.close(); 458 test.close();
459 }) 459 })
460 ..expectDone() 460 ..expectDone()
461 ..expectCancel(test.terminate); 461 ..expectCancel(test.terminate);
462 test.listen(); 462 test.listen();
463 }); 463 });
464 464
465 test("broadcast-controller-individual-pause", () { 465 test("broadcast-controller-individual-pause", () {
466 StreamProtocolTest test = new StreamProtocolTest.broadcast(); 466 StreamProtocolTest test = new StreamProtocolTest.broadcast();
467 test.trace = true;
468 var sub1; 467 var sub1;
469 test..expectListen() 468 test..expectListen()
470 ..expectData(42) 469 ..expectData(42)
471 ..expectData(42, () { sub1.pause(); }) 470 ..expectData(42, () { sub1.pause(); })
472 ..expectData(43, () { 471 ..expectData(43, () {
473 sub1.cancel(); 472 sub1.cancel();
474 test.listen(); 473 test.listen();
475 test.add(44); 474 test.add(44);
476 test.expectData(44); 475 test.expectData(44);
477 test.expectData(44, test.terminate); 476 test.expectData(44, test.terminate);
(...skipping 13 matching lines...) Expand all
491 test.add(87); 490 test.add(87);
492 sub.cancel(); 491 sub.cancel();
493 }); 492 });
494 test.expectCancel(() { 493 test.expectCancel(() {
495 test.add(37); 494 test.add(37);
496 test.terminate(); 495 test.terminate();
497 }); 496 });
498 }); 497 });
499 } 498 }
500 499
500 void testSink(bool sync, bool broadcast, bool asBroadcast) {
501 String type = "${sync?"S":"A"}${broadcast?"B":"S"}${asBroadcast?"aB":""}";
502 test("$type-controller-sink", () {
503 var done = expectAsync0((){});
504 var c = broadcast ? new StreamController(sync: sync)
505 : new StreamController.broadcast(sync: sync);
506 var expected = new Events()
507 ..add(42)..error("error")
508 ..add(1)..add(2)..add(3)..add(4)..add(5)
509 ..add(43)..close();
510 var actual = new Events.capture(asBroadcast ? c.stream
511 : c.stream.asBroadcastStream());
512 var sink = c.sink;
513 sink.add(42);
514 sink.addError("error");
515 sink.addStream(new Stream.fromIterable([1, 2, 3, 4, 5]))
516 .then((_) {
517 sink.add(43);
518 return sink.close();
519 })
520 .then((_) {
521 Expect.listEquals(expected.events, actual.events);
522 done();
523 });
524 });
525
526 test("$type-controller-sink-canceled", () {
527 var done = expectAsync0((){});
528 var c = broadcast ? new StreamController(sync: sync)
529 : new StreamController.broadcast(sync: sync);
530 var expected = new Events()
531 ..add(42)..error("error")
532 ..add(1)..add(2)..add(3);
533 var stream = asBroadcast ? c.stream : c.stream.asBroadcastStream();
534 var actual = new Events();
535 var sub;
536 sub = stream.listen((v) {
537 if (v == 3) sub.cancel();
538 actual.add(v);
539 }, onError: actual.error);
540 var sink = c.sink;
541 sink.add(42);
542 sink.addError("error");
543 sink.addStream(new Stream.fromIterable([1, 2, 3, 4, 5]))
544 .then((_) {
545 return sink.done;
546 })
547 .then((_) {
548 Expect.listEquals(expected.events, actual.events);
549 done();
550 });
551 });
552
553 test("$type-controller-sink-paused", () {
554 var done = expectAsync0((){});
555 var c = broadcast ? new StreamController(sync: sync)
556 : new StreamController.broadcast(sync: sync);
557 var expected = new Events()
558 ..add(42)..error("error")
559 ..add(1)..add(2)..add(3);
560 // This is wrong, it should get more events before being done.
floitsch 2013/06/06 15:08:29 Don't understand. The subscription is only paused.
561 var stream = asBroadcast ? c.stream : c.stream.asBroadcastStream();
562 var actual = new Events();
563 var sub;
564 sub = stream.listen((v) {
565 if (v == 3) {
566 sub.pause(new Future.delayed(const Duration(milliseconds: 15), () {} ));
floitsch 2013/06/06 15:08:29 long line.
567 }
568 actual.add(v);
569 },
570 onError: actual.error,
571 onDone: actual.close);
572 var sink = c.sink;
573 sink.add(42);
574 sink.addError("error");
575 sink.addStream(new Stream.fromIterable([1, 2, 3, 4, 5]))
576 .then((_) {
577 sink.add(43);
578 sink.close();
579 return sink.done;
580 })
581 .then((_) {
582 Expect.listEquals(expected.events, actual.events);
583 done();
584 });
585 });
586 }
587
501 main() { 588 main() {
502 testController(); 589 testController();
503 testSingleController(); 590 testSingleController();
504 testExtraMethods(); 591 testExtraMethods();
505 testPause(); 592 testPause();
506 testRethrow(); 593 testRethrow();
507 testBroadcastController(); 594 testBroadcastController();
595 testSink(true, false, false);
596 testSink(false, false, false);
597 testSink(true, false, true);
598 testSink(false, false, true);
599 testSink(true, true, false);
600 testSink(false, true, false);
508 } 601 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698