diff --git a/LibTest/async/MultiStreamController/addErrorSync_A01_t01.dart b/LibTest/async/MultiStreamController/addErrorSync_A01_t01.dart new file mode 100644 index 0000000000..f89aac8717 --- /dev/null +++ b/LibTest/async/MultiStreamController/addErrorSync_A01_t01.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void addErrorSync( Object error, [ StackTrace? stackTrace ]) +/// Adds and delivers an error event. +/// +/// Adds an error like [addError] and attempts to deliver it immediately. +/// Delivery can be delayed if other previously added events are still pending +/// delivery, if the subscription is paused, or if the subscription isn't +/// listening yet. +/// +/// @description Checks that this method sends an error event. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller.add(1); + controller.addErrorSync(2); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int i = 1; + bool delivered = false; + stream.listen((v) { + Expect.equals(i, v); + i += 2; + }, onError: (e) { + delivered = true; + Expect.equals(2, e); + }, onDone: () { + Expect.isTrue(delivered); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addErrorSync_A01_t02.dart b/LibTest/async/MultiStreamController/addErrorSync_A01_t02.dart new file mode 100644 index 0000000000..a01e5f34ae --- /dev/null +++ b/LibTest/async/MultiStreamController/addErrorSync_A01_t02.dart @@ -0,0 +1,46 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void addErrorSync( Object error, [ StackTrace? stackTrace ]) +/// Adds and delivers an error event. +/// +/// Adds an error like [addError] and attempts to deliver it immediately. +/// Delivery can be delayed if other previously added events are still pending +/// delivery, if the subscription is paused, or if the subscription isn't +/// listening yet. +/// +/// @description Checks that this method sends an error event and a stack trace. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +StackTrace st = StackTrace.fromString("Stack trace"); + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller.add(1); + controller.addErrorSync(2, st); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int i = 1; + bool delivered = false; + stream.listen((v) { + Expect.equals(i, v); + i += 2; + }, onError: (e, _st) { + delivered = true; + Expect.equals("Stack trace", _st.toString()); + }, onDone: () { + Expect.isTrue(delivered); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addErrorSync_A02_t01.dart b/LibTest/async/MultiStreamController/addErrorSync_A02_t01.dart new file mode 100644 index 0000000000..9cdef3ba23 --- /dev/null +++ b/LibTest/async/MultiStreamController/addErrorSync_A02_t01.dart @@ -0,0 +1,47 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void addErrorSync( Object error, [ StackTrace? stackTrace ]) +/// Adds and delivers an error event. +/// +/// Adds an error like [addError] and attempts to deliver it immediately. +/// Delivery can be delayed if other previously added events are still pending +/// delivery, if the subscription is paused, or if the subscription isn't +/// listening yet. +/// +/// @description Checks that delivery can be delayed if subscription is paused. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller.add(1); + controller.addErrorSync(2); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int i = 1; + bool delivered = false; + StreamSubscription ss = stream.listen((v) { + Expect.equals(i, v); + i += 2; + }, onError: (e) { + delivered = true; + Expect.equals(2, e); + }, onDone: () { + Expect.isTrue(delivered); + asyncEnd(); + }); + ss.pause(Future.delayed(Duration(milliseconds: 100), () { + ss.resume(); + })); +} diff --git a/LibTest/async/MultiStreamController/addError_A01_t01.dart b/LibTest/async/MultiStreamController/addError_A01_t01.dart new file mode 100644 index 0000000000..7402759e1e --- /dev/null +++ b/LibTest/async/MultiStreamController/addError_A01_t01.dart @@ -0,0 +1,39 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void addError( Object error, [ StackTrace? stackTrace ]) +/// Sends or enqueues an error event. +/// +/// @description Checks that this method sends an error event. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller.add(1); + controller.addError(2); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int i = 1; + bool delivered = false; + stream.listen((v) { + Expect.equals(i, v); + i += 2; + }, onError: (e) { + delivered = true; + Expect.equals(2, e); + }, onDone: () { + Expect.isTrue(delivered); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addError_A01_t02.dart b/LibTest/async/MultiStreamController/addError_A01_t02.dart new file mode 100644 index 0000000000..14c41bc869 --- /dev/null +++ b/LibTest/async/MultiStreamController/addError_A01_t02.dart @@ -0,0 +1,41 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void addError( Object error, [ StackTrace? stackTrace ]) +/// Sends or enqueues an error event. +/// +/// @description Checks that this method sends an error event and a stack trace. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +StackTrace st = StackTrace.fromString("Stack trace"); + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller.add(1); + controller.addError(2, st); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int i = 1; + bool delivered = false; + stream.listen((v) { + Expect.equals(i, v); + i += 2; + }, onError: (e, _st) { + delivered = true; + Expect.equals("Stack trace", _st.toString()); + }, onDone: () { + Expect.isTrue(delivered); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A01_t01.dart b/LibTest/async/MultiStreamController/addStream_A01_t01.dart new file mode 100644 index 0000000000..84b7591812 --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A01_t01.dart @@ -0,0 +1,52 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that this method receives events from source and puts +/// them into this controller's stream. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller.addStream(Stream.fromIterable([1, 2, 3])).then((_) { + controller.close(); + }); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int i = 1; + stream.listen((v) { + Expect.equals(i++, v); + }, onDone: () { + Expect.equals(4, i); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A02_t01.dart b/LibTest/async/MultiStreamController/addStream_A02_t01.dart new file mode 100644 index 0000000000..79250df2d1 --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A02_t01.dart @@ -0,0 +1,59 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that it is a run-time error if events are added to the +/// controller via `add` until the returned future is complete. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller + .addStream( + Stream.fromFuture(Future.delayed(Duration(seconds: 1), () => 42))) + .then((_) { + controller.close(); + }); + Expect.throws(() { + controller.add(1); + }); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int callCount = 0; + stream.listen((v) { + callCount++; + Expect.equals(42, v); + }, onDone: () { + Expect.equals(1, callCount); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A02_t02.dart b/LibTest/async/MultiStreamController/addStream_A02_t02.dart new file mode 100644 index 0000000000..0e6791fb98 --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A02_t02.dart @@ -0,0 +1,59 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that it is a run-time error if events are added to the +/// controller via `addSync` until the returned future is complete. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller + .addStream( + Stream.fromFuture(Future.delayed(Duration(seconds: 1), () => 42))) + .then((_) { + controller.close(); + }); + Expect.throws(() { + controller.addSync(1); + }); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int callCount = 0; + stream.listen((v) { + callCount++; + Expect.equals(42, v); + }, onDone: () { + Expect.equals(1, callCount); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A02_t03.dart b/LibTest/async/MultiStreamController/addStream_A02_t03.dart new file mode 100644 index 0000000000..24776cc68b --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A02_t03.dart @@ -0,0 +1,61 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that it is a run-time error if events are added to the +/// controller via `addError` until the returned future is complete. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller + .addStream( + Stream.fromFuture(Future.delayed(Duration(seconds: 1), () => 42))) + .then((_) { + controller.close(); + }); + Expect.throws(() { + controller.addError("Ups!"); + }); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int callCount = 0; + stream.listen((v) { + callCount++; + Expect.equals(42, v); + }, onError: (e) { + Expect.fail("No error event expected, but received $e"); + }, onDone: () { + Expect.equals(1, callCount); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A02_t04.dart b/LibTest/async/MultiStreamController/addStream_A02_t04.dart new file mode 100644 index 0000000000..45b7c2f9f0 --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A02_t04.dart @@ -0,0 +1,61 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that it is a run-time error if events are added to the +/// controller via `addErrorSync` until the returned future is complete. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller + .addStream( + Stream.fromFuture(Future.delayed(Duration(seconds: 1), () => 42))) + .then((_) { + controller.close(); + }); + Expect.throws(() { + controller.addErrorSync("Ups!"); + }); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int callCount = 0; + stream.listen((v) { + callCount++; + Expect.equals(42, v); + }, onError: (e) { + Expect.fail("No error event expected, but received $e"); + }, onDone: () { + Expect.equals(1, callCount); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A02_t05.dart b/LibTest/async/MultiStreamController/addStream_A02_t05.dart new file mode 100644 index 0000000000..bbb744d464 --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A02_t05.dart @@ -0,0 +1,59 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that it is a run-time error if events are added to the +/// controller via `close` until the returned future is complete. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller + .addStream( + Stream.fromFuture(Future.delayed(Duration(seconds: 1), () => 42))) + .then((_) { + controller.close(); + }); + Expect.throws(() { + controller.close(); + }); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int callCount = 0; + stream.listen((v) { + callCount++; + Expect.equals(42, v); + }, onDone: () { + Expect.equals(1, callCount); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A02_t06.dart b/LibTest/async/MultiStreamController/addStream_A02_t06.dart new file mode 100644 index 0000000000..93acbdb449 --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A02_t06.dart @@ -0,0 +1,59 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that it is a run-time error if events are added to the +/// controller via `closeSync` until the returned future is complete. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller + .addStream( + Stream.fromFuture(Future.delayed(Duration(seconds: 1), () => 42))) + .then((_) { + controller.close(); + }); + Expect.throws(() { + controller.closeSync(); + }); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int callCount = 0; + stream.listen((v) { + callCount++; + Expect.equals(42, v); + }, onDone: () { + Expect.equals(1, callCount); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A02_t07.dart b/LibTest/async/MultiStreamController/addStream_A02_t07.dart new file mode 100644 index 0000000000..d4b072c09f --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A02_t07.dart @@ -0,0 +1,59 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that it is a run-time error if events are added to the +/// controller via `addStream` until the returned future is complete. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller + .addStream( + Stream.fromFuture(Future.delayed(Duration(seconds: 1), () => 42))) + .then((_) { + controller.close(); + }); + Expect.throws(() { + controller.addStream(Stream.fromIterable([1, 2, 3])); + }); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int callCount = 0; + stream.listen((v) { + callCount++; + Expect.equals(42, v); + }, onDone: () { + Expect.equals(1, callCount); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A03_t01.dart b/LibTest/async/MultiStreamController/addStream_A03_t01.dart new file mode 100644 index 0000000000..1714603f3b --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A03_t01.dart @@ -0,0 +1,63 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that if `cancelOnError` is `false` all errors are +/// forwarded and only a done event ends the `addStream`. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(); + var source = StreamController(); + source.add(1); + source.add(2); + source.addError(-1); + source.add(3); + source.addError(-2); + source.close(); + + var stream = Stream.multi((controller) { + controller.addStream(source.stream, cancelOnError: false).then((_) { + controller.close(); + }); + }); + listen(stream); +} + +void listen(Stream stream) { + int eventsCounter = 0; + int errorsCounter = 0; + stream.listen((v) { + Expect.equals(++eventsCounter, v); + }, onError: (e) { + Expect.equals(--errorsCounter, e); + }, onDone: () { + Expect.equals(3, eventsCounter); + Expect.equals(-2, errorsCounter); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A03_t02.dart b/LibTest/async/MultiStreamController/addStream_A03_t02.dart new file mode 100644 index 0000000000..4bba21eaee --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A03_t02.dart @@ -0,0 +1,63 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that if `cancelOnError` is omitted it defaults to +/// `false`. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(); + var source = StreamController(); + source.add(1); + source.add(2); + source.addError(-1); + source.add(3); + source.addError(-2); + source.close(); + + var stream = Stream.multi((controller) { + controller.addStream(source.stream).then((_) { + controller.close(); + }); + }); + listen(stream); +} + +void listen(Stream stream) { + int eventsCounter = 0; + int errorsCounter = 0; + stream.listen((v) { + Expect.equals(++eventsCounter, v); + }, onError: (e) { + Expect.equals(--errorsCounter, e); + }, onDone: () { + Expect.equals(3, eventsCounter); + Expect.equals(-2, errorsCounter); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A03_t03.dart b/LibTest/async/MultiStreamController/addStream_A03_t03.dart new file mode 100644 index 0000000000..36b017db40 --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A03_t03.dart @@ -0,0 +1,62 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that if `cancelOnError` is null it defaults to `false`. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(); + var source = StreamController(); + source.add(1); + source.add(2); + source.addError(-1); + source.add(3); + source.addError(-2); + source.close(); + + var stream = Stream.multi((controller) { + controller.addStream(source.stream, cancelOnError: null).then((_) { + controller.close(); + }); + }); + listen(stream); +} + +void listen(Stream stream) { + int eventsCounter = 0; + int errorsCounter = 0; + stream.listen((v) { + Expect.equals(++eventsCounter, v); + }, onError: (e) { + Expect.equals(--errorsCounter, e); + }, onDone: () { + Expect.equals(3, eventsCounter); + Expect.equals(-2, errorsCounter); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A03_t04.dart b/LibTest/async/MultiStreamController/addStream_A03_t04.dart new file mode 100644 index 0000000000..e0f8cef99c --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A03_t04.dart @@ -0,0 +1,65 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that if `cancelOnError` is `true`, only the first error +/// on source is forwarded to the controller's stream, and the `addStream` ends +/// after this. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(); + var source = StreamController(); + source.add(1); + source.add(2); + source.addError(-1); + source.add(3); + source.addError(-2); + source.close(); + + var stream = Stream.multi((controller) { + controller.addStream(source.stream, cancelOnError: true).then((_) { + controller.close(); + }); + }); + listen(stream); +} + +void listen(Stream stream) { + int eventsCounter = 0; + int errorsCounter = 0; + stream.listen((v) { + Expect.equals(++eventsCounter, v); + }, onError: (e) { + --errorsCounter; + Expect.equals(-1, e); + }, onDone: () { + Expect.equals(2, eventsCounter); + Expect.equals(-1, errorsCounter); + asyncEnd(); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A03_t05.dart b/LibTest/async/MultiStreamController/addStream_A03_t05.dart new file mode 100644 index 0000000000..84552cc320 --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A03_t05.dart @@ -0,0 +1,68 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that if `cancelOnError` is `true`, only the first error +/// on source is forwarded to the controller's stream, and the `addStream` ends +/// after this. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(); + Completer completer = Completer(); + completer.future.then((_) { + asyncEnd(); + }); + var source = StreamController(); + source.add(1); + source.add(2); + source.add(3); + source.addError(-1); + // No source.close(); here. The first error should complete the future + + var stream = Stream.multi((controller) { + controller.addStream(source.stream, cancelOnError: true).then((_) { + completer.complete(); + controller.close(); + }); + }); + listen(stream); +} + +void listen(Stream stream) { + int eventsCounter = 0; + int errorsCounter = 0; + stream.listen((v) { + Expect.equals(++eventsCounter, v); + }, onError: (e) { + --errorsCounter; + Expect.equals(-1, e); + }, onDone: () { + Expect.equals(3, eventsCounter); + Expect.equals(-1, errorsCounter); + }); +} diff --git a/LibTest/async/MultiStreamController/addStream_A04_t01.dart b/LibTest/async/MultiStreamController/addStream_A04_t01.dart new file mode 100644 index 0000000000..40d62525ca --- /dev/null +++ b/LibTest/async/MultiStreamController/addStream_A04_t01.dart @@ -0,0 +1,59 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion Future addStream( +/// Stream source, { +/// bool? cancelOnError, +/// }) +/// Receives events from source and puts them into this controller's stream. +/// +/// Returns a future which completes when the source stream is done. +/// +/// Events must not be added directly to this controller using `add`, +/// `addError`, `close` or `addStream`, until the returned future is complete. +/// +/// Data and error events are forwarded to this controller's stream. A done +/// event on the source will end the addStream operation and complete the +/// returned future. +/// +/// If `cancelOnError` is `true`, only the first error on `source` is forwarded +/// to the controller's stream, and the `addStream` ends after this. If +/// `cancelOnError` is `false`, all errors are forwarded and only a done event +/// will end the `addStream`. If `cancelOnError` is omitted or null, it defaults +/// to `false`. +/// +/// @description Checks that without done event on source the `addStream` +/// operation is not ended and the returned future is not completed. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(); + var source = StreamController(); + source.add(1); + source.add(2); + source.add(3); + // No source.close() here. + + var stream = Stream.multi((controller) { + controller.addStream(source.stream).then((_) { + Expect.fail("Future unexpectedly completed"); + }); + }); + listen(stream); +} + +void listen(Stream stream) { + int eventsCounter = 0; + stream.listen((v) { + Expect.equals(++eventsCounter, v); + if (v == 3) { + Future.delayed(Duration(milliseconds: 100), asyncEnd); + } + }, onDone: () { + Expect.fail("Unexpected onDone"); + }); +} diff --git a/LibTest/async/MultiStreamController/add_A01_t01.dart b/LibTest/async/MultiStreamController/add_A01_t01.dart new file mode 100644 index 0000000000..6669fffaa5 --- /dev/null +++ b/LibTest/async/MultiStreamController/add_A01_t01.dart @@ -0,0 +1,34 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion void add(T event) +/// Send a data event to a stream. +/// +/// @description Checks that this method sends a data event to a stream. +/// @author sgrekhov22@gmail.com + +import "dart:async"; +import "../../../Utils/expect.dart"; + +main() { + asyncStart(2); + var stream = Stream.multi((controller) { + controller.add(1); + controller.add(2); + controller.add(3); + controller.close(); + }); + listen(stream); + listen(stream); +} + +void listen(Stream stream) { + int i = 1; + stream.listen((v) { + Expect.equals(i++, v); + }, onDone: () { + Expect.equals(4, i); + asyncEnd(); + }); +}