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 ProcessStderrTest { | 7 class ProcessStderrTest { |
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 ["1", "1", "99", "0"]); | 11 const ["1", "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.stderrStream; | 20 SocketInputStream input = process.stderrStream; |
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 void readData() { | 28 void readData() { |
29 for (int i = 0; i < BUFFERSIZE; i++) { | 29 for (int i = 0; i < BUFFERSIZE - 1; i++) { |
30 Expect.equals(buffer[i], readBuffer[i]); | 30 Expect.equals(buffer[i], readBuffer[i]); |
31 } | 31 } |
32 process.close(); | 32 process.close(); |
33 } | 33 } |
34 | 34 |
35 bool read = input.read(readBuffer, 0, BUFFERSIZE, readData); | 35 bool read = input.read(readBuffer, 0, BUFFERSIZE, readData); |
36 if (read) { | 36 if (read) { |
37 readData(); | 37 readData(); |
38 } | 38 } |
39 } | 39 } |
40 bool written = output.write(buffer, 0, BUFFERSIZE, dataWritten); | 40 bool written = output.write(buffer, 0, BUFFERSIZE, dataWritten); |
41 if (written) { | 41 if (written) { |
42 dataWritten(); | 42 dataWritten(); |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 static void testMain() { | 46 static void testMain() { |
47 testExit(); | 47 testExit(); |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 main() { | 51 main() { |
52 ProcessStderrTest.testMain(); | 52 ProcessStderrTest.testMain(); |
53 } | 53 } |
OLD | NEW |