Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: tests/standalone/src/ProcessStdoutTest.dart

Issue 9024008: Change the process API to be completely asynchronous. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Presubmit fixes Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #library("ProcessStdoutTest"); 12 #library("ProcessStdoutTest");
13 #source("ProcessTestUtil.dart"); 13 #source("ProcessTestUtil.dart");
14 14
15 void test(Process process) { 15 void test(Process process) {
16 List<int> data = "ABCDEFGHI\n".charCodes(); 16 // Wait for the process to start and then interact with it.
17 final int dataSize = data.length; 17 process.startHandler = () {
18 List<int> data = "ABCDEFGHI\n".charCodes();
19 final int dataSize = data.length;
18 20
19 InputStream input = process.stdout; 21 InputStream input = process.stdout;
20 OutputStream output = process.stdin; 22 OutputStream output = process.stdin;
21 process.start();
22 23
23 int received = 0; 24 int received = 0;
24 List<int> buffer = []; 25 List<int> buffer = [];
25 26
26 void readData() { 27 void readData() {
27 buffer.addAll(input.read()); 28 buffer.addAll(input.read());
28 for (int i = received; i < Math.min(data.length, buffer.length) - 1; i++) { 29 for (int i = received;
29 Expect.equals(data[i], buffer[i]); 30 i < Math.min(data.length, buffer.length) - 1;
30 } 31 i++) {
31 received = buffer.length; 32 Expect.equals(data[i], buffer[i]);
32 if (received >= dataSize) { 33 }
33 // We expect an extra character on windows due to carriage return. 34 received = buffer.length;
34 if (13 === buffer[dataSize - 1] && dataSize + 1 === received) { 35 if (received >= dataSize) {
35 Expect.equals(13, buffer[dataSize - 1]); 36 // We expect an extra character on windows due to carriage return.
36 Expect.equals(10, buffer[dataSize]); 37 if (13 === buffer[dataSize - 1] && dataSize + 1 === received) {
37 buffer.removeLast(); 38 Expect.equals(13, buffer[dataSize - 1]);
38 process.close(); 39 Expect.equals(10, buffer[dataSize]);
39 } else if (received === dataSize) { 40 buffer.removeLast();
40 process.close(); 41 process.close();
42 } else if (received === dataSize) {
43 process.close();
44 }
41 } 45 }
42 } 46 }
43 }
44 47
45 output.write(data); 48 output.write(data);
46 output.close(); 49 output.close();
47 input.dataHandler = readData; 50 input.dataHandler = readData;
51 };
48 } 52 }
49 53
50 main() { 54 main() {
51 // Run the test using the process_test binary. 55 // Run the test using the process_test binary.
52 test(new Process(getProcessTestFileName(), 56 test(new Process.start(getProcessTestFileName(),
53 const ["0", "1", "99", "0"])); 57 const ["0", "1", "99", "0"]));
54 58
55 // Run the test using the dart binary with an echo script. 59 // Run the test using the dart binary with an echo script.
56 // The test runner can be run from either the root or from runtime. 60 // The test runner can be run from either the root or from runtime.
57 var scriptFile = new File("tests/standalone/src/ProcessStdIOScript.dart"); 61 var scriptFile = new File("tests/standalone/src/ProcessStdIOScript.dart");
58 if (!scriptFile.existsSync()) { 62 if (!scriptFile.existsSync()) {
59 scriptFile = new File("../tests/standalone/src/ProcessStdIOScript.dart"); 63 scriptFile = new File("../tests/standalone/src/ProcessStdIOScript.dart");
60 } 64 }
61 Expect.isTrue(scriptFile.existsSync()); 65 Expect.isTrue(scriptFile.existsSync());
62 test(new Process(getDartFileName(), [scriptFile.name, "0"])); 66 test(new Process.start(getDartFileName(), [scriptFile.name, "0"]));
63 } 67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698