| 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 class ProcessStderrTest { | 12 class ProcessStderrTest { |
| 13 | 13 |
| 14 static void testExit() { | 14 static void testExit() { |
| 15 Process process = new Process("out/Debug_ia32/process_test", | 15 Process process = new Process("out/Debug_ia32/process_test", |
| 16 const ["1", "1", "99", "0"]); | 16 const ["1", "1", "99", "0"]); |
| 17 final int BUFFERSIZE = 10; | 17 final int BUFFERSIZE = 10; |
| 18 final int STARTCHAR = 65; | 18 final int STARTCHAR = 65; |
| 19 List<int> buffer = new List<int>(BUFFERSIZE); | 19 List<int> data = new List<int>(BUFFERSIZE); |
| 20 for (int i = 0; (i < BUFFERSIZE - 1); i++) { | 20 for (int i = 0; (i < BUFFERSIZE - 1); i++) { |
| 21 buffer[i] = STARTCHAR + i; | 21 data[i] = STARTCHAR + i; |
| 22 } | 22 } |
| 23 buffer[BUFFERSIZE - 1] = 10; | 23 data[BUFFERSIZE - 1] = 10; |
| 24 | 24 |
| 25 InputStream input = process.stderr; | 25 InputStream input = process.stderr; |
| 26 OutputStream output = process.stdin; | 26 OutputStream output = process.stdin; |
| 27 | 27 |
| 28 process.start(); | 28 process.start(); |
| 29 | 29 |
| 30 List<int> readBuffer = new List<int>(BUFFERSIZE); | 30 int received = 0; |
| 31 | 31 |
| 32 void dataWritten() { | 32 void dataWritten() { |
| 33 void readData() { | 33 void readData() { |
| 34 for (int i = 0; i < BUFFERSIZE; i++) { | 34 List<int> buffer = input.read(); |
| 35 Expect.equals(buffer[i], readBuffer[i]); | 35 for (int i = 0; i < buffer.length; i++) { |
| 36 Expect.equals(data[received + i], buffer[i]); |
| 36 } | 37 } |
| 37 process.close(); | 38 received += buffer.length; |
| 39 if (received == BUFFERSIZE) { |
| 40 process.close(); |
| 41 } |
| 38 } | 42 } |
| 39 | 43 |
| 40 bool read = input.read(readBuffer, 0, BUFFERSIZE, readData); | 44 input.dataHandler = readData; |
| 41 if (read) { | |
| 42 readData(); | |
| 43 } | |
| 44 } | 45 } |
| 45 bool written = output.write(buffer, 0, BUFFERSIZE, dataWritten); | 46 |
| 47 bool written = output.write(data, 0, BUFFERSIZE, dataWritten); |
| 46 if (written) { | 48 if (written) { |
| 47 dataWritten(); | 49 dataWritten(); |
| 48 } | 50 } |
| 49 } | 51 } |
| 50 | 52 |
| 51 static void testMain() { | 53 static void testMain() { |
| 52 testExit(); | 54 testExit(); |
| 53 } | 55 } |
| 54 } | 56 } |
| 55 | 57 |
| 56 main() { | 58 main() { |
| 57 ProcessStderrTest.testMain(); | 59 ProcessStderrTest.testMain(); |
| 58 } | 60 } |
| OLD | NEW |