OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 /// Mock VM implementation used for testing VM connections. | 5 /// Mock VM implementation used for testing VM connections. |
6 library fletchc.test.client.mock_vm; | 6 library dartino_compiler.test.client.mock_vm; |
7 | 7 |
8 import 'dart:async' show | 8 import 'dart:async' show |
9 Future, | 9 Future, |
10 StreamIterator; | 10 StreamIterator; |
11 | 11 |
12 import 'dart:io' show | 12 import 'dart:io' show |
13 InternetAddress, | 13 InternetAddress, |
14 ServerSocket, | 14 ServerSocket, |
15 Socket; | 15 Socket; |
16 | 16 |
17 import 'dart:isolate' show | 17 import 'dart:isolate' show |
18 ReceivePort, | 18 ReceivePort, |
19 SendPort; | 19 SendPort; |
20 | 20 |
21 import 'dart:typed_data' show | 21 import 'dart:typed_data' show |
22 ByteData; | 22 ByteData; |
23 | 23 |
24 import 'package:fletchc/src/shared_command_infrastructure.dart' show | 24 import 'package:dartino_compiler/src/shared_command_infrastructure.dart' show |
25 CommandTransformerBuilder, | 25 CommandTransformerBuilder, |
26 toUint8ListView; | 26 toUint8ListView; |
27 | 27 |
28 import 'package:fletchc/vm_commands.dart' show | 28 import 'package:dartino_compiler/vm_commands.dart' show |
29 VmCommand, | 29 VmCommand, |
30 VmCommandCode, | 30 VmCommandCode, |
31 CommitChangesResult, | 31 CommitChangesResult, |
32 HandShakeResult, | 32 HandShakeResult, |
33 ProcessTerminated; | 33 ProcessTerminated; |
34 | 34 |
35 import 'package:dart_isolate/ports.dart' show | 35 import 'package:dart_isolate/ports.dart' show |
36 singleResponseFuture; | 36 singleResponseFuture; |
37 | 37 |
38 import 'package:dart_isolate/isolate_runner.dart' show | 38 import 'package:dart_isolate/isolate_runner.dart' show |
39 IsolateRunner; | 39 IsolateRunner; |
40 | 40 |
41 import 'package:fletchc/src/zone_helper.dart' show | 41 import 'package:dartino_compiler/src/zone_helper.dart' show |
42 runGuarded; | 42 runGuarded; |
43 | 43 |
44 /// Represents state associated with a mocked VM. | 44 /// Represents state associated with a mocked VM. |
45 class MockVm { | 45 class MockVm { |
46 /// Port number the mock VM is listening on. Host is always 127.0.0.1. | 46 /// Port number the mock VM is listening on. Host is always 127.0.0.1. |
47 final int port; | 47 final int port; |
48 | 48 |
49 /// Future completes with VM's exit code. | 49 /// Future completes with VM's exit code. |
50 final Future<int> exitCode; | 50 final Future<int> exitCode; |
51 | 51 |
(...skipping 27 matching lines...) Expand all Loading... |
79 .whenComplete(stdout.close) | 79 .whenComplete(stdout.close) |
80 .whenComplete(isolate.close); | 80 .whenComplete(isolate.close); |
81 }); | 81 }); |
82 return new MockVm(port, isolate, exitCode); | 82 return new MockVm(port, isolate, exitCode); |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 /// Encodes arguments to [mockVm]. | 86 /// Encodes arguments to [mockVm]. |
87 class MockVmArguments { | 87 class MockVmArguments { |
88 // Keep this class simple. See notice in `SharedTask` in | 88 // Keep this class simple. See notice in `SharedTask` in |
89 // `package:fletchc/src/verbs/infrastructure.dart`. | 89 // `package:dartino_compiler/src/verbs/infrastructure.dart`. |
90 | 90 |
91 final SendPort port; | 91 final SendPort port; |
92 final bool closeImmediately; | 92 final bool closeImmediately; |
93 final int closeAfterFirstIndex; | 93 final int closeAfterFirstIndex; |
94 final SendPort stdout; | 94 final SendPort stdout; |
95 | 95 |
96 const MockVmArguments( | 96 const MockVmArguments( |
97 this.port, | 97 this.port, |
98 this.closeImmediately, | 98 this.closeImmediately, |
99 this.closeAfterFirstIndex, | 99 this.closeAfterFirstIndex, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 return new CommitChangesResult( | 171 return new CommitChangesResult( |
172 true, "Successfully applied program update."); | 172 true, "Successfully applied program update."); |
173 | 173 |
174 case VmCommandCode.ProcessRun: | 174 case VmCommandCode.ProcessRun: |
175 return const ProcessTerminated(); | 175 return const ProcessTerminated(); |
176 | 176 |
177 default: | 177 default: |
178 return null; | 178 return null; |
179 } | 179 } |
180 } | 180 } |
OLD | NEW |