| 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 272 |
| 273 StreamProtocolTest test = new StreamProtocolTest(); | 273 StreamProtocolTest test = new StreamProtocolTest(); |
| 274 Completer completer = new Completer(); | 274 Completer completer = new Completer(); |
| 275 test..expectListen() | 275 test..expectListen() |
| 276 ..expectData(42, () { test.pause(completer.future); }) | 276 ..expectData(42, () { test.pause(completer.future); }) |
| 277 ..expectPause(() { | 277 ..expectPause(() { |
| 278 completer.complete(null); | 278 completer.complete(null); |
| 279 }) | 279 }) |
| 280 ..expectData(43) | 280 ..expectData(43) |
| 281 ..expectData(44) | 281 ..expectData(44) |
| 282 ..expectDone() | 282 ..expectCancel() |
| 283 ..expectCancel(test.terminate); | 283 ..expectDone(test.terminate); |
| 284 test.listen(); | 284 test.listen(); |
| 285 test.add(42); | 285 test.add(42); |
| 286 test.add(43); | 286 test.add(43); |
| 287 test.add(44); | 287 test.add(44); |
| 288 test.close(); | 288 test.close(); |
| 289 }); | 289 }); |
| 290 | 290 |
| 291 test("pause twice event-unpause", () { | 291 test("pause twice event-unpause", () { |
| 292 StreamProtocolTest test = new StreamProtocolTest(); | 292 StreamProtocolTest test = new StreamProtocolTest(); |
| 293 Completer completer = new Completer(); | 293 Completer completer = new Completer(); |
| 294 Completer completer2 = new Completer(); | 294 Completer completer2 = new Completer(); |
| 295 test..expectListen() | 295 test..expectListen() |
| 296 ..expectData(42, () { | 296 ..expectData(42, () { |
| 297 test.pause(completer.future); | 297 test.pause(completer.future); |
| 298 test.pause(completer2.future); | 298 test.pause(completer2.future); |
| 299 }) | 299 }) |
| 300 ..expectPause(() { | 300 ..expectPause(() { |
| 301 completer.future.then(completer2.complete); | 301 completer.future.then(completer2.complete); |
| 302 completer.complete(null); | 302 completer.complete(null); |
| 303 }) | 303 }) |
| 304 ..expectData(43) | 304 ..expectData(43) |
| 305 ..expectData(44) | 305 ..expectData(44) |
| 306 ..expectDone() | 306 ..expectCancel() |
| 307 ..expectCancel(test.terminate); | 307 ..expectDone(test.terminate); |
| 308 test..listen() | 308 test..listen() |
| 309 ..add(42) | 309 ..add(42) |
| 310 ..add(43) | 310 ..add(43) |
| 311 ..add(44) | 311 ..add(44) |
| 312 ..close(); | 312 ..close(); |
| 313 }); | 313 }); |
| 314 | 314 |
| 315 test("pause twice direct-unpause", () { | 315 test("pause twice direct-unpause", () { |
| 316 StreamProtocolTest test = new StreamProtocolTest(); | 316 StreamProtocolTest test = new StreamProtocolTest(); |
| 317 test..expectListen() | 317 test..expectListen() |
| 318 ..expectData(42, () { | 318 ..expectData(42, () { |
| 319 test.pause(); | 319 test.pause(); |
| 320 test.pause(); | 320 test.pause(); |
| 321 }) | 321 }) |
| 322 ..expectPause(() { | 322 ..expectPause(() { |
| 323 test.resume(); | 323 test.resume(); |
| 324 test.resume(); | 324 test.resume(); |
| 325 }) | 325 }) |
| 326 ..expectData(43) | 326 ..expectData(43) |
| 327 ..expectData(44) | 327 ..expectData(44) |
| 328 ..expectDone() | 328 ..expectCancel() |
| 329 ..expectCancel(test.terminate); | 329 ..expectDone(test.terminate); |
| 330 test..listen() | 330 test..listen() |
| 331 ..add(42) | 331 ..add(42) |
| 332 ..add(43) | 332 ..add(43) |
| 333 ..add(44) | 333 ..add(44) |
| 334 ..close(); | 334 ..close(); |
| 335 }); | 335 }); |
| 336 | 336 |
| 337 test("pause twice direct-event-unpause", () { | 337 test("pause twice direct-event-unpause", () { |
| 338 StreamProtocolTest test = new StreamProtocolTest(); | 338 StreamProtocolTest test = new StreamProtocolTest(); |
| 339 Completer completer = new Completer(); | 339 Completer completer = new Completer(); |
| 340 test..expectListen() | 340 test..expectListen() |
| 341 ..expectData(42, () { | 341 ..expectData(42, () { |
| 342 test.pause(); | 342 test.pause(); |
| 343 test.pause(completer.future); | 343 test.pause(completer.future); |
| 344 test.add(43); | 344 test.add(43); |
| 345 test.add(44); | 345 test.add(44); |
| 346 test.close(); | 346 test.close(); |
| 347 }) | 347 }) |
| 348 ..expectPause(() { | 348 ..expectPause(() { |
| 349 completer.future.then((v) => test.resume()); | 349 completer.future.then((v) => test.resume()); |
| 350 completer.complete(null); | 350 completer.complete(null); |
| 351 }) | 351 }) |
| 352 ..expectData(43) | 352 ..expectData(43) |
| 353 ..expectData(44) | 353 ..expectData(44) |
| 354 ..expectDone() | 354 ..expectCancel() |
| 355 ..expectCancel(test.terminate); | 355 ..expectDone(test.terminate); |
| 356 test..listen() | 356 test..listen() |
| 357 ..add(42); | 357 ..add(42); |
| 358 }); | 358 }); |
| 359 } | 359 } |
| 360 | 360 |
| 361 class TestError { const TestError(); } | 361 class TestError { const TestError(); } |
| 362 | 362 |
| 363 testRethrow() { | 363 testRethrow() { |
| 364 TestError error = const TestError(); | 364 TestError error = const TestError(); |
| 365 | 365 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 testFuture("reduce", (s, act) => s.reduce((a,b) => act(b))); | 410 testFuture("reduce", (s, act) => s.reduce((a,b) => act(b))); |
| 411 testFuture("fold", (s, act) => s.fold(0, (a,b) => act(b))); | 411 testFuture("fold", (s, act) => s.fold(0, (a,b) => act(b))); |
| 412 testFuture("drain", (s, act) => s.drain().then(act)); | 412 testFuture("drain", (s, act) => s.drain().then(act)); |
| 413 } | 413 } |
| 414 | 414 |
| 415 void testBroadcastController() { | 415 void testBroadcastController() { |
| 416 test("broadcast-controller-basic", () { | 416 test("broadcast-controller-basic", () { |
| 417 StreamProtocolTest test = new StreamProtocolTest.broadcast(); | 417 StreamProtocolTest test = new StreamProtocolTest.broadcast(); |
| 418 test..expectListen() | 418 test..expectListen() |
| 419 ..expectData(42) | 419 ..expectData(42) |
| 420 ..expectDone() | 420 ..expectCancel() |
| 421 ..expectCancel(test.terminate); | 421 ..expectDone(test.terminate); |
| 422 test..listen() | 422 test..listen() |
| 423 ..add(42) | 423 ..add(42) |
| 424 ..close(); | 424 ..close(); |
| 425 }); | 425 }); |
| 426 | 426 |
| 427 test("broadcast-controller-listen-twice", () { | 427 test("broadcast-controller-listen-twice", () { |
| 428 StreamProtocolTest test = new StreamProtocolTest.broadcast(); | 428 StreamProtocolTest test = new StreamProtocolTest.broadcast(); |
| 429 test..expectListen() | 429 test..expectListen() |
| 430 ..expectData(42, () { | 430 ..expectData(42, () { |
| 431 test.listen(); | 431 test.listen(); |
| 432 test.add(37); | 432 test.add(37); |
| 433 test.close(); | 433 test.close(); |
| 434 }) | 434 }) |
| 435 // Order is not guaranteed between subscriptions if not sync. | 435 // Order is not guaranteed between subscriptions if not sync. |
| 436 ..expectData(37) | 436 ..expectData(37) |
| 437 ..expectData(37) | 437 ..expectData(37) |
| 438 ..expectDone() | 438 ..expectDone() |
| 439 ..expectDone() | 439 ..expectCancel() |
| 440 ..expectCancel(test.terminate); | 440 ..expectDone(test.terminate); |
| 441 test.listen(); | 441 test.listen(); |
| 442 test.add(42); | 442 test.add(42); |
| 443 }); | 443 }); |
| 444 | 444 |
| 445 test("broadcast-controller-listen-twice-non-overlap", () { | 445 test("broadcast-controller-listen-twice-non-overlap", () { |
| 446 StreamProtocolTest test = new StreamProtocolTest.broadcast(); | 446 StreamProtocolTest test = new StreamProtocolTest.broadcast(); |
| 447 test | 447 test |
| 448 ..expectListen(() { | 448 ..expectListen(() { |
| 449 test.add(42); | 449 test.add(42); |
| 450 }) | 450 }) |
| 451 ..expectData(42, () { | 451 ..expectData(42, () { |
| 452 test.cancel(); | 452 test.cancel(); |
| 453 }) | 453 }) |
| 454 ..expectCancel(() { | 454 ..expectCancel(() { |
| 455 test.listen(); | 455 test.listen(); |
| 456 })..expectListen(() { | 456 })..expectListen(() { |
| 457 test.add(37); | 457 test.add(37); |
| 458 }) | 458 }) |
| 459 ..expectData(37, () { | 459 ..expectData(37, () { |
| 460 test.close(); | 460 test.close(); |
| 461 }) | 461 }) |
| 462 ..expectDone() | 462 ..expectCancel() |
| 463 ..expectCancel(test.terminate); | 463 ..expectDone(test.terminate); |
| 464 test.listen(); | 464 test.listen(); |
| 465 }); | 465 }); |
| 466 | 466 |
| 467 test("broadcast-controller-individual-pause", () { | 467 test("broadcast-controller-individual-pause", () { |
| 468 StreamProtocolTest test = new StreamProtocolTest.broadcast(); | 468 StreamProtocolTest test = new StreamProtocolTest.broadcast(); |
| 469 var sub1; | 469 var sub1; |
| 470 test..expectListen() | 470 test..expectListen() |
| 471 ..expectData(42) | 471 ..expectData(42) |
| 472 ..expectData(42, () { sub1.pause(); }) | 472 ..expectData(42, () { sub1.pause(); }) |
| 473 ..expectData(43, () { | 473 ..expectData(43, () { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 ..expectPause(() { | 553 ..expectPause(() { |
| 554 sub = test.listen(); | 554 sub = test.listen(); |
| 555 }) | 555 }) |
| 556 ..expectBroadcastListen((originalSub) { | 556 ..expectBroadcastListen((originalSub) { |
| 557 originalSub.resume(); | 557 originalSub.resume(); |
| 558 }) | 558 }) |
| 559 ..expectData(43) | 559 ..expectData(43) |
| 560 ..expectResume(() { | 560 ..expectResume(() { |
| 561 test.close(); | 561 test.close(); |
| 562 }) | 562 }) |
| 563 ..expectCancel() |
| 563 ..expectDone() | 564 ..expectDone() |
| 564 ..expectBroadcastCancel() | 565 ..expectBroadcastCancel((_) => test.terminate()); |
| 565 ..expectCancel(test.terminate); | |
| 566 sub = test.listen(); | 566 sub = test.listen(); |
| 567 }); | 567 }); |
| 568 } | 568 } |
| 569 | 569 |
| 570 void testSink({bool sync, bool broadcast, bool asBroadcast}) { | 570 void testSink({bool sync, bool broadcast, bool asBroadcast}) { |
| 571 String type = "${sync?"S":"A"}${broadcast?"B":"S"}${asBroadcast?"aB":""}"; | 571 String type = "${sync?"S":"A"}${broadcast?"B":"S"}${asBroadcast?"aB":""}"; |
| 572 test("$type-controller-sink", () { | 572 test("$type-controller-sink", () { |
| 573 var done = expectAsync0((){}); | 573 var done = expectAsync0((){}); |
| 574 var c = broadcast ? new StreamController.broadcast(sync: sync) | 574 var c = broadcast ? new StreamController.broadcast(sync: sync) |
| 575 : new StreamController(sync: sync); | 575 : new StreamController(sync: sync); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 testRethrow(); | 685 testRethrow(); |
| 686 testBroadcastController(); | 686 testBroadcastController(); |
| 687 testAsBroadcast(); | 687 testAsBroadcast(); |
| 688 testSink(sync: true, broadcast: false, asBroadcast: false); | 688 testSink(sync: true, broadcast: false, asBroadcast: false); |
| 689 testSink(sync: true, broadcast: false, asBroadcast: true); | 689 testSink(sync: true, broadcast: false, asBroadcast: true); |
| 690 testSink(sync: true, broadcast: true, asBroadcast: false); | 690 testSink(sync: true, broadcast: true, asBroadcast: false); |
| 691 testSink(sync: false, broadcast: false, asBroadcast: false); | 691 testSink(sync: false, broadcast: false, asBroadcast: false); |
| 692 testSink(sync: false, broadcast: false, asBroadcast: true); | 692 testSink(sync: false, broadcast: false, asBroadcast: true); |
| 693 testSink(sync: false, broadcast: true, asBroadcast: false); | 693 testSink(sync: false, broadcast: true, asBroadcast: false); |
| 694 } | 694 } |
| OLD | NEW |