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