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

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

Issue 8318009: Update the streams interfaces (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from ager@ Created 9 years, 1 month 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 class ProcessStdoutTest { 12 class ProcessStdoutTest {
13 13
14 static void testExit() { 14 static void testStdout() {
15 Process process = new Process("out/Debug_ia32//process_test", 15 Process process = new Process("out/Debug_ia32//process_test",
16 const ["0", "1", "99", "0"]); 16 const ["0", "1", "99", "0"]);
17 final int BUFFERSIZE = 10; 17 final int BUFFERSIZE = 10;
18 final int STARTCHAR = 65; 18 final int STARTCHAR = 65;
19 List<int> buffer = new List<int>(BUFFERSIZE); 19 List<int> data = new List<int>(BUFFERSIZE);
20 for (int i = 0; (i < BUFFERSIZE - 1); i++) { 20 for (int i = 0; (i < BUFFERSIZE - 1); i++) {
21 buffer[i] = STARTCHAR + i; 21 data[i] = STARTCHAR + i;
22 } 22 }
23 buffer[BUFFERSIZE - 1] = 10; 23 data[BUFFERSIZE - 1] = 10;
24 24
25 InputStream input = process.stdout; 25 InputStream input = process.stdout;
26 OutputStream output = process.stdin; 26 OutputStream output = process.stdin;
27 27
28 process.start(); 28 process.start();
29 29
30 List<int> readBuffer = new List<int>(BUFFERSIZE); 30 int received = 0;
31 31
32 void dataWritten() { 32 void dataWritten() {
33 void readData() { 33 void readData() {
34 for (int i = 0; i < BUFFERSIZE; i++) { 34 List<int> buffer = input.read();
35 Expect.equals(buffer[i], readBuffer[i]); 35 for (int i = 0; i < buffer.length; i++) {
36 Expect.equals(data[received + i], buffer[i]);
36 } 37 }
37 process.close(); 38 received += buffer.length;
39 if (received == BUFFERSIZE) {
40 process.close();
41 }
38 } 42 }
39 43
40 bool read = input.read(readBuffer, 0, BUFFERSIZE, readData); 44 void streamClosed() {
41 if (read) { 45 Expect.equals(BUFFERSIZE, received);
42 readData();
43 } 46 }
47
48 input.dataHandler = readData;
49 input.closeHandler = streamClosed;
44 } 50 }
45 bool written = output.write(buffer, 0, BUFFERSIZE, dataWritten); 51
52 bool written = output.write(data, 0, BUFFERSIZE, dataWritten);
46 if (written) { 53 if (written) {
47 dataWritten(); 54 dataWritten();
48 } 55 }
49 } 56 }
50 57
51 static void testMain() { 58 static void testMain() {
52 testExit(); 59 testStdout();
53 } 60 }
54 } 61 }
55 62
56 main() { 63 main() {
57 ProcessStdoutTest.testMain(); 64 ProcessStdoutTest.testMain();
58 } 65 }
OLDNEW
« no previous file with comments | « tests/standalone/src/ProcessStderrTest.dart ('k') | tests/standalone/src/SocketExceptionTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698