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