| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 |
| 11 | 11 |
| 12 #library("ProcessStderrTest"); | 12 #library("ProcessStderrTest"); |
| 13 #source("ProcessTestUtil.dart"); | 13 #source("ProcessTestUtil.dart"); |
| 14 | 14 |
| 15 void test(Process process) { | 15 void test(Process process) { |
| 16 List<int> data = "ABCDEFGHI\n".charCodes(); | 16 // Wait for the process to start and then interact with it. |
| 17 final int dataSize = data.length; | 17 process.startHandler = () { |
| 18 List<int> data = "ABCDEFGHI\n".charCodes(); |
| 19 final int dataSize = data.length; |
| 18 | 20 |
| 19 InputStream input = process.stderr; | 21 InputStream input = process.stderr; |
| 20 OutputStream output = process.stdin; | 22 OutputStream output = process.stdin; |
| 21 | 23 |
| 22 process.start(); | 24 int received = 0; |
| 25 List<int> buffer = []; |
| 23 | 26 |
| 24 int received = 0; | 27 void readData() { |
| 25 List<int> buffer = []; | 28 buffer.addAll(input.read()); |
| 26 | 29 for (int i = received; |
| 27 void readData() { | 30 i < Math.min(data.length, buffer.length) - 1; |
| 28 buffer.addAll(input.read()); | 31 i++) { |
| 29 for (int i = received; i < Math.min(data.length, buffer.length) - 1; i++) { | 32 Expect.equals(data[i], buffer[i]); |
| 30 Expect.equals(data[i], buffer[i]); | 33 } |
| 31 } | 34 received = buffer.length; |
| 32 received = buffer.length; | 35 if (received >= dataSize) { |
| 33 if (received >= dataSize) { | 36 // We expect an extra character on windows due to carriage return. |
| 34 // We expect an extra character on windows due to carriage return. | 37 if (13 === buffer[dataSize - 1] && dataSize + 1 === received) { |
| 35 if (13 === buffer[dataSize - 1] && dataSize + 1 === received) { | 38 Expect.equals(13, buffer[dataSize - 1]); |
| 36 Expect.equals(13, buffer[dataSize - 1]); | 39 Expect.equals(10, buffer[dataSize]); |
| 37 Expect.equals(10, buffer[dataSize]); | 40 buffer.removeLast(); |
| 38 buffer.removeLast(); | 41 process.close(); |
| 39 process.close(); | 42 } else if (received === dataSize) { |
| 40 } else if (received === dataSize) { | 43 process.close(); |
| 41 process.close(); | 44 } |
| 42 } | 45 } |
| 43 } | 46 } |
| 44 } | |
| 45 | 47 |
| 46 output.write(data); | 48 output.write(data); |
| 47 output.close(); | 49 output.close(); |
| 48 input.dataHandler = readData; | 50 input.dataHandler = readData; |
| 51 }; |
| 49 } | 52 } |
| 50 | 53 |
| 51 main() { | 54 main() { |
| 52 // Run the test using the process_test binary. | 55 // Run the test using the process_test binary. |
| 53 test(new Process(getProcessTestFileName(), | 56 test(new Process.start(getProcessTestFileName(), |
| 54 const ["1", "1", "99", "0"])); | 57 const ["1", "1", "99", "0"])); |
| 55 | 58 |
| 56 // Run the test using the dart binary with an echo script. | 59 // Run the test using the dart binary with an echo script. |
| 57 // 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. |
| 58 var scriptFile = new File("tests/standalone/src/ProcessStdIOScript.dart"); | 61 var scriptFile = new File("tests/standalone/src/ProcessStdIOScript.dart"); |
| 59 if (!scriptFile.existsSync()) { | 62 if (!scriptFile.existsSync()) { |
| 60 scriptFile = new File("../tests/standalone/src/ProcessStdIOScript.dart"); | 63 scriptFile = new File("../tests/standalone/src/ProcessStdIOScript.dart"); |
| 61 } | 64 } |
| 62 Expect.isTrue(scriptFile.existsSync()); | 65 Expect.isTrue(scriptFile.existsSync()); |
| 63 test(new Process(getDartFileName(), [scriptFile.name, "1"])); | 66 test(new Process.start(getDartFileName(), [scriptFile.name, "1"])); |
| 64 } | 67 } |
| OLD | NEW |