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

Side by Side Diff: tests/standalone/io/stream_pipe_test.dart

Issue 23886004: Update dart:io tests to use asyncStart/asyncEnd (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 3 months 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // VMOptions= 5 // VMOptions=
6 // VMOptions=--short_socket_read 6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write 7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // VMOptions=--short_socket_read --short_socket_write
9 library ServerTest;
10 9
10 import "dart:io";
11
12 import "package:async_helper/async_helper.dart";
11 import "package:expect/expect.dart"; 13 import "package:expect/expect.dart";
12 import "dart:io";
13 import "dart:isolate";
14 14
15 // Helper method to be able to run the test from the runtime 15 // Helper method to be able to run the test from the runtime
16 // directory, or the top directory. 16 // directory, or the top directory.
17 String getDataFilename(String path) => 17 String getDataFilename(String path) =>
18 new File(path).existsSync() ? path : '../$path'; 18 new File(path).existsSync() ? path : '../$path';
19 19
20 20
21 bool compareFileContent(String fileName1, 21 bool compareFileContent(String fileName1,
22 String fileName2, 22 String fileName2,
23 {int file1Offset: 0, 23 {int file1Offset: 0,
(...skipping 30 matching lines...) Expand all
54 file2.closeSync(); 54 file2.closeSync();
55 return true; 55 return true;
56 } 56 }
57 57
58 58
59 // Test piping from one file to another and closing both streams 59 // Test piping from one file to another and closing both streams
60 // after wards. 60 // after wards.
61 testFileToFilePipe1() { 61 testFileToFilePipe1() {
62 // Force test to timeout if one of the handlers is 62 // Force test to timeout if one of the handlers is
63 // not called. 63 // not called.
64 ReceivePort donePort = new ReceivePort(); 64 asyncStart();
65 donePort.receive((message, ignore) { donePort.close(); });
66 65
67 String srcFileName = 66 String srcFileName =
68 getDataFilename("tests/standalone/io/readline_test1.dat"); 67 getDataFilename("tests/standalone/io/readline_test1.dat");
69 var srcStream = new File(srcFileName).openRead(); 68 var srcStream = new File(srcFileName).openRead();
70 69
71 var tempDir = new Directory('').createTempSync(); 70 var tempDir = new Directory('').createTempSync();
72 String dstFileName = tempDir.path + "/readline_test1.dat"; 71 String dstFileName = tempDir.path + "/readline_test1.dat";
73 new File(dstFileName).createSync(); 72 new File(dstFileName).createSync();
74 var output = new File(dstFileName).openWrite(); 73 var output = new File(dstFileName).openWrite();
75 srcStream.pipe(output).then((_) { 74 srcStream.pipe(output).then((_) {
76 bool result = compareFileContent(srcFileName, dstFileName); 75 bool result = compareFileContent(srcFileName, dstFileName);
77 new File(dstFileName).deleteSync(); 76 new File(dstFileName).deleteSync();
78 tempDir.deleteSync(); 77 tempDir.deleteSync();
79 Expect.isTrue(result); 78 Expect.isTrue(result);
80 donePort.toSendPort().send(null); 79 asyncEnd();
81 }); 80 });
82 } 81 }
83 82
84 83
85 // Test piping from one file to another and write additional data to 84 // Test piping from one file to another and write additional data to
86 // the output stream after piping finished. 85 // the output stream after piping finished.
87 testFileToFilePipe2() { 86 testFileToFilePipe2() {
88 // Force test to timeout if one of the handlers is 87 // Force test to timeout if one of the handlers is
89 // not called. 88 // not called.
90 ReceivePort donePort = new ReceivePort(); 89 asyncStart();
91 donePort.receive((message, ignore) { donePort.close(); });
92 90
93 String srcFileName = 91 String srcFileName =
94 getDataFilename("tests/standalone/io/readline_test1.dat"); 92 getDataFilename("tests/standalone/io/readline_test1.dat");
95 var srcFile = new File(srcFileName); 93 var srcFile = new File(srcFileName);
96 var srcStream = srcFile.openRead(); 94 var srcStream = srcFile.openRead();
97 95
98 var tempDir = new Directory('').createTempSync(); 96 var tempDir = new Directory('').createTempSync();
99 var dstFileName = tempDir.path + "/readline_test1.dat"; 97 var dstFileName = tempDir.path + "/readline_test1.dat";
100 var dstFile = new File(dstFileName); 98 var dstFile = new File(dstFileName);
101 dstFile.createSync(); 99 dstFile.createSync();
(...skipping 11 matching lines...) Expand all
113 dstFileName, 111 dstFileName,
114 count: srcLength)); 112 count: srcLength));
115 dst.setPositionSync(srcLength); 113 dst.setPositionSync(srcLength);
116 var data = new List<int>(1); 114 var data = new List<int>(1);
117 var read2 = dst.readIntoSync(data, 0, 1); 115 var read2 = dst.readIntoSync(data, 0, 1);
118 Expect.equals(32, data[0]); 116 Expect.equals(32, data[0]);
119 src.closeSync(); 117 src.closeSync();
120 dst.closeSync(); 118 dst.closeSync();
121 dstFile.deleteSync(); 119 dstFile.deleteSync();
122 tempDir.deleteSync(); 120 tempDir.deleteSync();
123 donePort.toSendPort().send(null); 121 asyncEnd();
124 }); 122 });
125 }); 123 });
126 } 124 }
127 125
128 126
129 // Test piping two copies of one file to another. 127 // Test piping two copies of one file to another.
130 testFileToFilePipe3() { 128 testFileToFilePipe3() {
131 // Force test to timeout if one of the handlers is 129 // Force test to timeout if one of the handlers is
132 // not called. 130 // not called.
133 ReceivePort donePort = new ReceivePort(); 131 asyncStart();
134 donePort.receive((message, ignore) { donePort.close(); });
135 132
136 String srcFileName = 133 String srcFileName =
137 getDataFilename("tests/standalone/io/readline_test1.dat"); 134 getDataFilename("tests/standalone/io/readline_test1.dat");
138 var srcFile = new File(srcFileName); 135 var srcFile = new File(srcFileName);
139 var srcStream = srcFile.openRead(); 136 var srcStream = srcFile.openRead();
140 137
141 var tempDir = new Directory('').createTempSync(); 138 var tempDir = new Directory('').createTempSync();
142 var dstFileName = tempDir.path + "/readline_test1.dat"; 139 var dstFileName = tempDir.path + "/readline_test1.dat";
143 var dstFile = new File(dstFileName); 140 var dstFile = new File(dstFileName);
144 dstFile.createSync(); 141 dstFile.createSync();
(...skipping 12 matching lines...) Expand all
157 dstFileName, 154 dstFileName,
158 count: srcLength)); 155 count: srcLength));
159 Expect.isTrue(compareFileContent(srcFileName, 156 Expect.isTrue(compareFileContent(srcFileName,
160 dstFileName, 157 dstFileName,
161 file2Offset: srcLength, 158 file2Offset: srcLength,
162 count: srcLength)); 159 count: srcLength));
163 src.closeSync(); 160 src.closeSync();
164 dst.closeSync(); 161 dst.closeSync();
165 dstFile.deleteSync(); 162 dstFile.deleteSync();
166 tempDir.deleteSync(); 163 tempDir.deleteSync();
167 donePort.toSendPort().send(null); 164 asyncEnd();
168 }); 165 });
169 }); 166 });
170 }); 167 });
171 } 168 }
172 169
173 170
174 main() { 171 main() {
175 testFileToFilePipe1(); 172 testFileToFilePipe1();
176 testFileToFilePipe2(); 173 testFileToFilePipe2();
177 testFileToFilePipe3(); 174 testFileToFilePipe3();
178 } 175 }
OLDNEW
« no previous file with comments | « tests/standalone/io/socket_upgrade_to_secure_test.dart ('k') | tests/standalone/io/web_socket_protocol_processor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698