| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library stream_state_helper; | 5 library stream_state_helper; |
| 6 | 6 |
| 7 import "../../../pkg/unittest/lib/unittest.dart"; | 7 import "../../../pkg/unittest/lib/unittest.dart"; |
| 8 import "dart:async"; | 8 import "dart:async"; |
| 9 import "dart:collection"; | 9 import "dart:collection"; |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 int _subscriptionIdCounter = 0; | 57 int _subscriptionIdCounter = 0; |
| 58 Function _onComplete; | 58 Function _onComplete; |
| 59 | 59 |
| 60 StreamProtocolTest.broadcast({ bool sync: false }) | 60 StreamProtocolTest.broadcast({ bool sync: false }) |
| 61 : isBroadcast = true, isAsBroadcast = false { | 61 : isBroadcast = true, isAsBroadcast = false { |
| 62 _controller = new StreamController.broadcast( | 62 _controller = new StreamController.broadcast( |
| 63 sync: sync, | 63 sync: sync, |
| 64 onListen: _onListen, | 64 onListen: _onListen, |
| 65 onCancel: _onCancel); | 65 onCancel: _onCancel); |
| 66 _controllerStream = _controller.stream; | 66 _controllerStream = _controller.stream; |
| 67 _onComplete = expectAsync0((){ | 67 _onComplete = expectAsync((){ |
| 68 _onComplete = null; // Being null marks the test as being complete. | 68 _onComplete = null; // Being null marks the test as being complete. |
| 69 }); | 69 }); |
| 70 } | 70 } |
| 71 | 71 |
| 72 StreamProtocolTest({ bool sync: false }) | 72 StreamProtocolTest({ bool sync: false }) |
| 73 : isBroadcast = false, isAsBroadcast = false { | 73 : isBroadcast = false, isAsBroadcast = false { |
| 74 _controller = new StreamController( | 74 _controller = new StreamController( |
| 75 sync: sync, | 75 sync: sync, |
| 76 onListen: _onListen, | 76 onListen: _onListen, |
| 77 onPause: _onPause, | 77 onPause: _onPause, |
| 78 onResume: _onResume, | 78 onResume: _onResume, |
| 79 onCancel: _onCancel); | 79 onCancel: _onCancel); |
| 80 _controllerStream = _controller.stream; | 80 _controllerStream = _controller.stream; |
| 81 _onComplete = expectAsync0((){ | 81 _onComplete = expectAsync((){ |
| 82 _onComplete = null; // Being null marks the test as being complete. | 82 _onComplete = null; // Being null marks the test as being complete. |
| 83 }); | 83 }); |
| 84 } | 84 } |
| 85 | 85 |
| 86 StreamProtocolTest.asBroadcast({ bool sync: false }) | 86 StreamProtocolTest.asBroadcast({ bool sync: false }) |
| 87 : isBroadcast = false, isAsBroadcast = true { | 87 : isBroadcast = false, isAsBroadcast = true { |
| 88 _controller = new StreamController( | 88 _controller = new StreamController( |
| 89 sync: sync, | 89 sync: sync, |
| 90 onListen: _onListen, | 90 onListen: _onListen, |
| 91 onPause: _onPause, | 91 onPause: _onPause, |
| 92 onResume: _onResume, | 92 onResume: _onResume, |
| 93 onCancel: _onCancel); | 93 onCancel: _onCancel); |
| 94 _controllerStream = _controller.stream.asBroadcastStream( | 94 _controllerStream = _controller.stream.asBroadcastStream( |
| 95 onListen: _onBroadcastListen, | 95 onListen: _onBroadcastListen, |
| 96 onCancel: _onBroadcastCancel); | 96 onCancel: _onBroadcastCancel); |
| 97 _onComplete = expectAsync0((){ | 97 _onComplete = expectAsync((){ |
| 98 _onComplete = null; // Being null marks the test as being complete. | 98 _onComplete = null; // Being null marks the test as being complete. |
| 99 }); | 99 }); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Actions on the stream and controller. | 102 // Actions on the stream and controller. |
| 103 void add(var data) { _controller.add(data); } | 103 void add(var data) { _controller.add(data); } |
| 104 void error(var error) { _controller.addError(error); } | 104 void error(var error) { _controller.addError(error); } |
| 105 void close() { _controller.close(); } | 105 void close() { _controller.close(); } |
| 106 | 106 |
| 107 SubscriptionProtocolTest listen({bool cancelOnError : false}) { | 107 SubscriptionProtocolTest listen({bool cancelOnError : false}) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 buf.write("\n"); | 366 buf.write("\n"); |
| 367 } | 367 } |
| 368 throw "Unexpected event:\n$message\nAll expectations:\n$buf"; | 368 throw "Unexpected event:\n$message\nAll expectations:\n$buf"; |
| 369 } | 369 } |
| 370 } | 370 } |
| 371 | 371 |
| 372 class Event { | 372 class Event { |
| 373 Function _action; | 373 Function _action; |
| 374 StackTrace _stackTrace; | 374 StackTrace _stackTrace; |
| 375 Event(void action()) | 375 Event(void action()) |
| 376 : _action = (action == null) ? null : expectAsync0(action) { | 376 : _action = (action == null) ? null : expectAsync(action) { |
| 377 try { throw 0; } catch (_, s) { _stackTrace = s; } | 377 try { throw 0; } catch (_, s) { _stackTrace = s; } |
| 378 } | 378 } |
| 379 Event.broadcast(void action(StreamSubscription sub)) | 379 Event.broadcast(void action(StreamSubscription sub)) |
| 380 : _action = (action == null) ? null : expectAsync1(action) { | 380 : _action = (action == null) ? null : expectAsync(action) { |
| 381 try { throw 0; } catch (_, s) { _stackTrace = s; } | 381 try { throw 0; } catch (_, s) { _stackTrace = s; } |
| 382 } | 382 } |
| 383 | 383 |
| 384 bool matchData(int id, var data) { | 384 bool matchData(int id, var data) { |
| 385 return false; | 385 return false; |
| 386 } | 386 } |
| 387 | 387 |
| 388 bool matchError(int id, e) { | 388 bool matchError(int id, e) { |
| 389 return false; | 389 return false; |
| 390 } | 390 } |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 } | 580 } |
| 581 | 581 |
| 582 bool _testBroadcastCancel() { | 582 bool _testBroadcastCancel() { |
| 583 _actual = "*[BroadcastCancel]"; | 583 _actual = "*[BroadcastCancel]"; |
| 584 return true; | 584 return true; |
| 585 } | 585 } |
| 586 | 586 |
| 587 /** Returns a representation of the event it was tested against. */ | 587 /** Returns a representation of the event it was tested against. */ |
| 588 String toString() => _actual; | 588 String toString() => _actual; |
| 589 } | 589 } |
| OLD | NEW |