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 ProcessStdoutTest { | 14 class ProcessStdoutTest { |
13 | 15 |
14 static void testStdout() { | 16 static void testExit() { |
15 Process process = new Process("out/Debug_ia32//process_test", | 17 Process process = new Process(getProcessTestFileName(), |
16 const ["0", "1", "99", "0"]); | 18 const ["0", "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> data = new List<int>(BUFFERSIZE); | 21 List<int> data = new List<int>(BUFFERSIZE); |
20 for (int i = 0; (i < BUFFERSIZE - 1); i++) { | 22 for (int i = 0; (i < BUFFERSIZE - 1); i++) { |
21 data[i] = STARTCHAR + i; | 23 data[i] = STARTCHAR + i; |
22 } | 24 } |
23 data[BUFFERSIZE - 1] = 10; | 25 data[BUFFERSIZE - 1] = 10; |
24 | 26 |
25 InputStream input = process.stdout; | 27 InputStream input = process.stdout; |
26 OutputStream output = process.stdin; | 28 OutputStream output = process.stdin; |
27 | 29 |
28 process.start(); | 30 process.start(); |
29 | 31 |
30 int received = 0; | 32 int received = 0; |
| 33 List<int> buffer = []; |
31 | 34 |
32 void readData() { | 35 void readData() { |
33 List<int> buffer = input.read(); | 36 buffer.addAll(input.read()); |
34 for (int i = 0; i < buffer.length; i++) { | 37 for (int i = received; i < Math.min(data.length, buffer.length); i++) { |
35 Expect.equals(data[received + i], buffer[i]); | 38 Expect.equals(data[i], buffer[i]); |
36 } | 39 } |
37 received += buffer.length; | 40 received = buffer.length; |
38 if (received == BUFFERSIZE) { | 41 if (received >= BUFFERSIZE) { |
39 process.close(); | 42 // We expect an extra character on windows due to carriage return. |
| 43 if (13 === buffer[BUFFERSIZE - 1] && BUFFERSIZE + 1 === received) { |
| 44 Expect.equals(10, buffer[BUFFERSIZE]); |
| 45 buffer.removeLast(); |
| 46 process.close(); |
| 47 } else if (received === BUFFERSIZE) { |
| 48 process.close(); |
| 49 } |
40 } | 50 } |
41 } | 51 } |
42 | 52 |
43 void streamClosed() { | 53 void streamClosed() { |
44 Expect.equals(BUFFERSIZE, received); | 54 Expect.equals(BUFFERSIZE, received); |
45 } | 55 } |
46 | 56 |
47 output.write(data); | 57 output.write(data); |
48 output.end(); | 58 output.end(); |
49 input.dataHandler = readData; | 59 input.dataHandler = readData; |
50 input.closeHandler = streamClosed; | 60 input.closeHandler = streamClosed; |
51 } | 61 } |
52 | 62 |
53 static void testMain() { | 63 static void testMain() { |
54 testStdout(); | 64 testExit(); |
55 } | 65 } |
56 } | 66 } |
57 | 67 |
58 main() { | 68 main() { |
59 ProcessStdoutTest.testMain(); | 69 ProcessStdoutTest.testMain(); |
60 } | 70 } |
OLD | NEW |