| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
| 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.md file. | |
| 4 | |
| 5 import 'dart:async'; | |
| 6 | |
| 7 import 'dart:typed_data'; | |
| 8 | |
| 9 import 'package:expect/expect.dart'; | |
| 10 | |
| 11 import 'package:fletchc/src/hub/client_commands.dart'; | |
| 12 | |
| 13 import 'package:fletchc/src/hub/hub_main.dart'; | |
| 14 | |
| 15 const List<int> stdinCommandData = const <int>[4, 0, 0, 0, 0, 0, 0, 0, 0]; | |
| 16 | |
| 17 Future<Null> testControlStream() async { | |
| 18 StreamController<Uint8List> controller = new StreamController<Uint8List>(); | |
| 19 | |
| 20 // Test that one byte at the time is handled. | |
| 21 for (int byte in stdinCommandData) { | |
| 22 controller.add(new Uint8List.fromList([byte])); | |
| 23 } | |
| 24 | |
| 25 // Test that two bytes at the time are handled. | |
| 26 for (int i = 0; i < stdinCommandData.length; i += 2) { | |
| 27 if (i + 1 < stdinCommandData.length) { | |
| 28 controller.add( | |
| 29 new Uint8List.fromList( | |
| 30 [stdinCommandData[i], stdinCommandData[i + 1]])); | |
| 31 } else { | |
| 32 controller.add(new Uint8List.fromList([stdinCommandData[i]])); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 // Test that data from the next command isn't discarded (when the next | |
| 37 // command is chunked). | |
| 38 var testData = <int>[] | |
| 39 ..addAll(stdinCommandData) | |
| 40 ..addAll(stdinCommandData.sublist(0, 5)); | |
| 41 controller | |
| 42 ..add(new Uint8List.fromList(testData)) | |
| 43 ..add(new Uint8List.fromList(stdinCommandData.sublist(5))); | |
| 44 | |
| 45 // Test that data from the next command isn't discarded (when there are more | |
| 46 // than one complete command in the buffer). | |
| 47 testData = <int>[] | |
| 48 ..addAll(stdinCommandData) | |
| 49 ..addAll(stdinCommandData); | |
| 50 controller.add(new Uint8List.fromList(testData)); | |
| 51 | |
| 52 StreamTransformer<List<int>, ClientCommand> transformer = | |
| 53 new ClientCommandTransformerBuilder().build(); | |
| 54 Future<List<ClientCommand>> commandsFuture = | |
| 55 controller.stream.transform(transformer).toList(); | |
| 56 | |
| 57 await controller.close(); | |
| 58 | |
| 59 List<ClientCommand> commands = await commandsFuture; | |
| 60 Expect.equals(6, commands.length); | |
| 61 for (ClientCommand command in commands) { | |
| 62 Expect.stringEquals( | |
| 63 'ClientCommand(ClientCommandCode.Stdin, [])', | |
| 64 '$command'); | |
| 65 } | |
| 66 } | |
| OLD | NEW |