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 // Process test program to test process communication. | 5 // Process test program to test process communication. |
6 // | 6 // |
7 // VMOptions= | 7 // VMOptions= |
8 // VMOptions=--short_socket_read | 8 // VMOptions=--short_socket_read |
9 // VMOptions=--short_socket_write | 9 // VMOptions=--short_socket_write |
10 // VMOptions=--short_socket_read --short_socket_write | 10 // VMOptions=--short_socket_read --short_socket_write |
(...skipping 12 matching lines...) Expand all Loading... |
23 }); | 23 }); |
24 | 24 |
25 List<int> data = "ABCDEFGHI\n".codeUnits; | 25 List<int> data = "ABCDEFGHI\n".codeUnits; |
26 final int dataSize = data.length; | 26 final int dataSize = data.length; |
27 | 27 |
28 int received = 0; | 28 int received = 0; |
29 List<int> buffer = []; | 29 List<int> buffer = []; |
30 | 30 |
31 void readData(data) { | 31 void readData(data) { |
32 buffer.addAll(data); | 32 buffer.addAll(data); |
33 for (int i = received; | 33 for (int i = received; i < min(data.length, buffer.length) - 1; i++) { |
34 i < min(data.length, buffer.length) - 1; | |
35 i++) { | |
36 Expect.equals(data[i], buffer[i]); | 34 Expect.equals(data[i], buffer[i]); |
37 } | 35 } |
38 received = buffer.length; | 36 received = buffer.length; |
39 if (received >= dataSize) { | 37 if (received >= dataSize) { |
40 // We expect an extra character on windows due to carriage return. | 38 // We expect an extra character on windows due to carriage return. |
41 if (13 == buffer[dataSize - 1] && dataSize + 1 == received) { | 39 if (13 == buffer[dataSize - 1] && dataSize + 1 == received) { |
42 Expect.equals(13, buffer[dataSize - 1]); | 40 Expect.equals(13, buffer[dataSize - 1]); |
43 Expect.equals(10, buffer[dataSize]); | 41 Expect.equals(10, buffer[dataSize]); |
44 buffer.removeLast(); | 42 buffer.removeLast(); |
45 } | 43 } |
46 } | 44 } |
47 } | 45 } |
48 | 46 |
49 process.stderr.listen((_) {}); | 47 process.stderr.listen((_) {}); |
50 process.stdin.add(data); | 48 process.stdin.add(data); |
51 process.stdin.flush().then((_) => process.stdin.close()); | 49 process.stdin.flush().then((_) => process.stdin.close()); |
52 process.stdout.listen(readData); | 50 process.stdout.listen(readData); |
53 }); | 51 }); |
54 } | 52 } |
55 | 53 |
56 main() { | 54 main() { |
57 // Run the test using the process_test binary. | 55 // Run the test using the process_test binary. |
58 test(Process.start(getProcessTestFileName(), | 56 test( |
59 const ["0", "1", "99", "0"]), 99); | 57 Process.start(getProcessTestFileName(), const ["0", "1", "99", "0"]), 99); |
60 | 58 |
61 // Run the test using the dart binary with an echo script. | 59 // Run the test using the dart binary with an echo script. |
62 // The test runner can be run from either the root or from runtime. | 60 // The test runner can be run from either the root or from runtime. |
63 var scriptFile = new File("tests/standalone/io/process_std_io_script.dart"); | 61 var scriptFile = new File("tests/standalone/io/process_std_io_script.dart"); |
64 if (!scriptFile.existsSync()) { | 62 if (!scriptFile.existsSync()) { |
65 scriptFile = new File("../tests/standalone/io/process_std_io_script.dart"); | 63 scriptFile = new File("../tests/standalone/io/process_std_io_script.dart"); |
66 } | 64 } |
67 Expect.isTrue(scriptFile.existsSync()); | 65 Expect.isTrue(scriptFile.existsSync()); |
68 test(Process.start(Platform.executable, [scriptFile.path, "0"]), 0); | 66 test(Process.start(Platform.executable, [scriptFile.path, "0"]), 0); |
69 } | 67 } |
OLD | NEW |