| 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 #source("ProcessTestUtil.dart"); | 12 #source("ProcessTestUtil.dart"); |
| 13 | 13 |
| 14 class ProcessStdoutTest { | 14 void test(Process process) { |
| 15 List<int> data = "ABCDEFGHI\n".charCodes(); |
| 16 final int dataSize = data.length; |
| 15 | 17 |
| 16 static void testExit() { | 18 InputStream input = process.stdout; |
| 17 Process process = new Process(getProcessTestFileName(), | 19 OutputStream output = process.stdin; |
| 18 const ["0", "1", "99", "0"]); | 20 process.start(); |
| 19 final int BUFFERSIZE = 10; | 21 |
| 20 final int STARTCHAR = 65; | 22 int received = 0; |
| 21 List<int> data = new List<int>(BUFFERSIZE); | 23 List<int> buffer = []; |
| 22 for (int i = 0; (i < BUFFERSIZE - 1); i++) { | 24 |
| 23 data[i] = STARTCHAR + i; | 25 void readData() { |
| 26 buffer.addAll(input.read()); |
| 27 for (int i = received; i < Math.min(data.length, buffer.length) - 1; i++) { |
| 28 Expect.equals(data[i], buffer[i]); |
| 24 } | 29 } |
| 25 data[BUFFERSIZE - 1] = 10; | 30 received = buffer.length; |
| 26 | 31 if (received >= dataSize) { |
| 27 InputStream input = process.stdout; | 32 // We expect an extra character on windows due to carriage return. |
| 28 OutputStream output = process.stdin; | 33 if (13 === buffer[dataSize - 1] && dataSize + 1 === received) { |
| 29 | 34 Expect.equals(13, buffer[dataSize - 1]); |
| 30 process.start(); | 35 Expect.equals(10, buffer[dataSize]); |
| 31 | 36 buffer.removeLast(); |
| 32 int received = 0; | 37 process.close(); |
| 33 List<int> buffer = []; | 38 } else if (received === dataSize) { |
| 34 | 39 process.close(); |
| 35 void readData() { | |
| 36 buffer.addAll(input.read()); | |
| 37 for (int i = received; i < Math.min(data.length, buffer.length) - 1; i++)
{ | |
| 38 Expect.equals(data[i], buffer[i]); | |
| 39 } | |
| 40 received = buffer.length; | |
| 41 if (received >= BUFFERSIZE) { | |
| 42 // We expect an extra character on windows due to carriage return. | |
| 43 if (13 === buffer[BUFFERSIZE - 1] && BUFFERSIZE + 1 === received) { | |
| 44 Expect.equals(13, buffer[BUFFERSIZE - 1]); | |
| 45 Expect.equals(10, buffer[BUFFERSIZE]); | |
| 46 buffer.removeLast(); | |
| 47 process.close(); | |
| 48 } else if (received === BUFFERSIZE) { | |
| 49 process.close(); | |
| 50 } | |
| 51 } | 40 } |
| 52 } | 41 } |
| 53 | |
| 54 void streamClosed() { | |
| 55 Expect.equals(BUFFERSIZE, received); | |
| 56 } | |
| 57 | |
| 58 output.write(data); | |
| 59 output.close(); | |
| 60 input.dataHandler = readData; | |
| 61 input.closeHandler = streamClosed; | |
| 62 } | 42 } |
| 63 | 43 |
| 64 static void testMain() { | 44 output.write(data); |
| 65 testExit(); | 45 output.close(); |
| 66 } | 46 input.dataHandler = readData; |
| 67 } | 47 } |
| 68 | 48 |
| 69 main() { | 49 main() { |
| 70 ProcessStdoutTest.testMain(); | 50 // Run the test using the process_test binary. |
| 51 test(new Process(getProcessTestFileName(), |
| 52 const ["0", "1", "99", "0"])); |
| 53 |
| 54 // Run the test using the dart binary with an echo script. |
| 55 // The test runner can be run from either the root or from runtime. |
| 56 var scriptFile = new File("tests/standalone/src/ProcessStdIOScript.dart"); |
| 57 if (!scriptFile.existsSync()) { |
| 58 scriptFile = new File("../tests/standalone/src/ProcessStdIOScript.dart"); |
| 59 } |
| 60 Expect.isTrue(scriptFile.existsSync()); |
| 61 test(new Process(getDartFileName(), [scriptFile.name, "0"])); |
| 71 } | 62 } |
| OLD | NEW |