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