Chromium Code Reviews| 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> 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.stderr; | 27 InputStream input = process.stderr; |
| 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 = []; | |
| 34 | |
| 31 void readData() { | 35 void readData() { |
| 32 List<int> buffer = input.read(); | 36 buffer.addAll(input.read()); |
| 33 for (int i = 0; i < buffer.length; i++) { | 37 for (int i = received; i < Math.min(data.length, buffer.length); i++) { |
|
Søren Gjesse
2011/11/08 08:43:38
Math.min(data.length, buffer.length) should be Mat
jrgfogh
2011/11/08 09:15:15
Done.
| |
| 34 Expect.equals(data[received + i], buffer[i]); | 38 Expect.equals(data[i], buffer[i]); |
| 35 } | 39 } |
| 36 received += buffer.length; | 40 received = buffer.length; |
| 37 if (received == BUFFERSIZE) { | 41 if (received >= BUFFERSIZE) { |
| 38 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) { | |
|
Søren Gjesse
2011/11/08 08:43:38
Expect 10 === buffer[BUFFERSIZE - 1] here.
jrgfogh
2011/11/08 09:15:15
Done.
| |
| 48 process.close(); | |
| 49 } | |
| 39 } | 50 } |
| 40 } | 51 } |
| 41 | 52 |
| 53 void streamClosed() { | |
| 54 Expect.equals(BUFFERSIZE, received); | |
| 55 } | |
| 56 | |
| 42 output.write(data); | 57 output.write(data); |
| 43 output.end(); | 58 output.end(); |
| 44 input.dataHandler = readData; | 59 input.dataHandler = readData; |
| 60 input.closeHandler = streamClosed; | |
| 45 } | 61 } |
| 46 | 62 |
| 47 static void testMain() { | 63 static void testMain() { |
| 48 testExit(); | 64 testExit(); |
| 49 } | 65 } |
| 50 } | 66 } |
| 51 | 67 |
| 52 main() { | 68 main() { |
| 53 ProcessStderrTest.testMain(); | 69 ProcessStderrTest.testMain(); |
| 54 } | 70 } |
| OLD | NEW |