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 ProcessStdoutTest { | 12 class ProcessStdoutTest { |
13 | 13 |
14 static void testExit() { | 14 static void testStdout() { |
15 Process process = new Process("out/Debug_ia32//process_test", | 15 Process process = new Process("out/Debug_ia32//process_test", |
16 const ["0", "1", "99", "0"]); | 16 const ["0", "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.stdout; | 25 InputStream input = process.stdout; |
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 print(buffer.length); |
Mads Ager (google)
2011/10/26 10:56:07
Remove?
Søren Gjesse
2011/10/26 12:03:31
Done.
| |
36 for (int i = 0; i < buffer.length; i++) { | |
37 Expect.equals(data[received + i], buffer[i]); | |
36 } | 38 } |
37 process.close(); | 39 received += buffer.length; |
40 if (received == BUFFERSIZE) { | |
41 process.close(); | |
42 } | |
38 } | 43 } |
39 | 44 |
40 bool read = input.read(readBuffer, 0, BUFFERSIZE, readData); | 45 void streamClosed() { |
41 if (read) { | 46 Expect.equals(BUFFERSIZE, received); |
42 readData(); | |
43 } | 47 } |
48 | |
49 input.dataHandler = readData; | |
50 input.closeHandler = streamClosed; | |
44 } | 51 } |
45 bool written = output.write(buffer, 0, BUFFERSIZE, dataWritten); | 52 |
53 bool written = output.write(data, 0, BUFFERSIZE, dataWritten); | |
46 if (written) { | 54 if (written) { |
47 dataWritten(); | 55 dataWritten(); |
48 } | 56 } |
49 } | 57 } |
50 | 58 |
51 static void testMain() { | 59 static void testMain() { |
52 testExit(); | 60 testStdout(); |
53 } | 61 } |
54 } | 62 } |
55 | 63 |
56 main() { | 64 main() { |
57 ProcessStdoutTest.testMain(); | 65 ProcessStdoutTest.testMain(); |
58 } | 66 } |
OLD | NEW |