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 #source("ProcessTestUtil.dart"); | |
13 | |
12 class ProcessStderrTest { | 14 class ProcessStderrTest { |
13 | 15 |
14 static void testExit() { | 16 static void testExit() { |
15 Process process = new Process("out/Debug_ia32/process_test", | 17 Process process = new Process(getProcessTestFileName(), |
16 const ["1", "1", "99", "0"]); | 18 const ["1", "1", "99", "0"]); |
17 final int BUFFERSIZE = 10; | 19 final int BUFFERSIZE = 10; |
18 final int STARTCHAR = 65; | 20 final int STARTCHAR = 65; |
19 List<int> buffer = new List<int>(BUFFERSIZE); | 21 List<int> buffer = new List<int>(BUFFERSIZE); |
20 for (int i = 0; (i < BUFFERSIZE - 1); i++) { | 22 for (int i = 0; (i < BUFFERSIZE - 1); i++) { |
21 buffer[i] = STARTCHAR + i; | 23 buffer[i] = STARTCHAR + i; |
22 } | 24 } |
23 buffer[BUFFERSIZE - 1] = 10; | 25 buffer[BUFFERSIZE - 1] = 10; |
24 | 26 |
25 SocketInputStream input = process.stderrStream; | 27 SocketInputStream input = process.stderrStream; |
26 SocketOutputStream output = process.stdinStream; | 28 SocketOutputStream output = process.stdinStream; |
27 | 29 |
28 process.start(); | 30 process.start(); |
29 | 31 |
30 List<int> readBuffer = new List<int>(BUFFERSIZE); | 32 List<int> readBuffer = new List<int>(BUFFERSIZE); |
31 | 33 |
32 void dataWritten() { | 34 void dataWritten() { |
33 void readData() { | 35 void readData() { |
34 for (int i = 0; i < BUFFERSIZE; i++) { | 36 for (int i = 0; i < BUFFERSIZE; i++) { |
Søren Gjesse
2011/10/24 06:23:04
I forgot that this has to be BUFFERSIZE - 1 for th
jrgfogh
2011/10/24 09:03:21
Done.
| |
35 Expect.equals(buffer[i], readBuffer[i]); | 37 Expect.equals(buffer[i], readBuffer[i]); |
36 } | 38 } |
37 process.close(); | 39 process.close(); |
38 } | 40 } |
39 | 41 |
40 bool read = input.read(readBuffer, 0, BUFFERSIZE, readData); | 42 bool read = input.read(readBuffer, 0, BUFFERSIZE, readData); |
41 if (read) { | 43 if (read) { |
42 readData(); | 44 readData(); |
43 } | 45 } |
44 } | 46 } |
45 bool written = output.write(buffer, 0, BUFFERSIZE, dataWritten); | 47 bool written = output.write(buffer, 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 |