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

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

Issue 9432023: Add both sync and async methods for getting streams for a File (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from ager@ Created 8 years, 10 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
« no previous file with comments | « tests/standalone/src/ReadIntoConstList.dart ('k') | tools/testing/dart/status_file_parser.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 9
10 #library("StreamPipeTest"); 10 #library("StreamPipeTest");
11 #import("dart:io"); 11 #import("dart:io");
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 }); 74 });
75 } 75 }
76 76
77 void runTest() { 77 void runTest() {
78 78
79 void connectHandler() { 79 void connectHandler() {
80 String srcFileName = 80 String srcFileName =
81 getDataFilename("tests/standalone/src/readline_test1.dat"); 81 getDataFilename("tests/standalone/src/readline_test1.dat");
82 82
83 SocketOutputStream socketOutput = _socket.outputStream; 83 SocketOutputStream socketOutput = _socket.outputStream;
84 InputStream fileInput = new File(srcFileName).openInputStream(); 84 InputStream fileInput = new File(srcFileName).openInputStreamSync();
85 85
86 fileInput.closeHandler = () { 86 fileInput.closeHandler = () {
87 SocketInputStream socketInput = _socket.inputStream; 87 SocketInputStream socketInput = _socket.inputStream;
88 var tempDir = new Directory(''); 88 var tempDir = new Directory('');
89 tempDir.createTempSync(); 89 tempDir.createTempSync();
90 var dstFileName = tempDir.path + "/readline_test1.dat"; 90 var dstFileName = tempDir.path + "/readline_test1.dat";
91 var dstFile = new File(dstFileName); 91 var dstFile = new File(dstFileName);
92 dstFile.createSync(); 92 dstFile.createSync();
93 var fileOutput = dstFile.openOutputStream(); 93 var fileOutput = dstFile.openOutputStreamSync();
94 94
95 socketInput.closeHandler = () { 95 socketInput.closeHandler = () {
96 // Check that the resulting file is equal to the initial 96 // Check that the resulting file is equal to the initial
97 // file. 97 // file.
98 bool result = compareFileContent(srcFileName, dstFileName); 98 bool result = compareFileContent(srcFileName, dstFileName);
99 new File(dstFileName).deleteSync(); 99 new File(dstFileName).deleteSync();
100 tempDir.deleteSync(); 100 tempDir.deleteSync();
101 Expect.isTrue(result); 101 Expect.isTrue(result);
102 102
103 _socket.close(); 103 _socket.close();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 connection.inputStream.pipe(connection.outputStream); 154 connection.inputStream.pipe(connection.outputStream);
155 } 155 }
156 } 156 }
157 157
158 158
159 // Test piping from one file to another and closing both streams 159 // Test piping from one file to another and closing both streams
160 // after wards. 160 // after wards.
161 testFileToFilePipe1() { 161 testFileToFilePipe1() {
162 String srcFileName = 162 String srcFileName =
163 getDataFilename("tests/standalone/src/readline_test1.dat"); 163 getDataFilename("tests/standalone/src/readline_test1.dat");
164 var srcStream = new File(srcFileName).openInputStream(); 164 var srcStream = new File(srcFileName).openInputStreamSync();
165 165
166 var tempDir = new Directory(''); 166 var tempDir = new Directory('');
167 tempDir.createTempSync(); 167 tempDir.createTempSync();
168 String dstFileName = tempDir.path + "/readline_test1.dat"; 168 String dstFileName = tempDir.path + "/readline_test1.dat";
169 new File(dstFileName).createSync(); 169 new File(dstFileName).createSync();
170 var dstStream = new File(dstFileName).openOutputStream(); 170 var dstStream = new File(dstFileName).openOutputStreamSync();
171 171
172 srcStream.closeHandler = () { 172 srcStream.closeHandler = () {
173 bool result = compareFileContent(srcFileName, dstFileName); 173 bool result = compareFileContent(srcFileName, dstFileName);
174 new File(dstFileName).deleteSync(); 174 new File(dstFileName).deleteSync();
175 tempDir.deleteSync(); 175 tempDir.deleteSync();
176 Expect.isTrue(result); 176 Expect.isTrue(result);
177 }; 177 };
178 178
179 srcStream.pipe(dstStream); 179 srcStream.pipe(dstStream);
180 } 180 }
181 181
182 182
183 // Test piping from one file to another and write additional data to 183 // Test piping from one file to another and write additional data to
184 // the output stream after piping finished. 184 // the output stream after piping finished.
185 testFileToFilePipe2() { 185 testFileToFilePipe2() {
186 String srcFileName = 186 String srcFileName =
187 getDataFilename("tests/standalone/src/readline_test1.dat"); 187 getDataFilename("tests/standalone/src/readline_test1.dat");
188 var srcFile = new File(srcFileName); 188 var srcFile = new File(srcFileName);
189 var srcStream = srcFile.openInputStream(); 189 var srcStream = srcFile.openInputStreamSync();
190 190
191 var tempDir = new Directory(''); 191 var tempDir = new Directory('');
192 tempDir.createTempSync(); 192 tempDir.createTempSync();
193 var dstFileName = tempDir.path + "/readline_test1.dat"; 193 var dstFileName = tempDir.path + "/readline_test1.dat";
194 var dstFile = new File(dstFileName); 194 var dstFile = new File(dstFileName);
195 dstFile.createSync(); 195 dstFile.createSync();
196 var dstStream = dstFile.openOutputStream(); 196 var dstStream = dstFile.openOutputStreamSync();
197 197
198 srcStream.closeHandler = () { 198 srcStream.closeHandler = () {
199 dstStream.write([32]); 199 dstStream.write([32]);
200 dstStream.close(); 200 dstStream.close();
201 var src = srcFile.openSync(); 201 var src = srcFile.openSync();
202 var dst = dstFile.openSync(); 202 var dst = dstFile.openSync();
203 var srcLength = src.lengthSync(); 203 var srcLength = src.lengthSync();
204 var dstLength = dst.lengthSync(); 204 var dstLength = dst.lengthSync();
205 Expect.equals(srcLength + 1, dstLength); 205 Expect.equals(srcLength + 1, dstLength);
206 Expect.isTrue(compareFileContent(srcFileName, 206 Expect.isTrue(compareFileContent(srcFileName,
(...skipping 11 matching lines...) Expand all
218 218
219 srcStream.pipe(dstStream, close: false); 219 srcStream.pipe(dstStream, close: false);
220 } 220 }
221 221
222 222
223 // Test piping two copies of one file to another. 223 // Test piping two copies of one file to another.
224 testFileToFilePipe3() { 224 testFileToFilePipe3() {
225 String srcFileName = 225 String srcFileName =
226 getDataFilename("tests/standalone/src/readline_test1.dat"); 226 getDataFilename("tests/standalone/src/readline_test1.dat");
227 var srcFile = new File(srcFileName); 227 var srcFile = new File(srcFileName);
228 var srcStream = srcFile.openInputStream(); 228 var srcStream = srcFile.openInputStreamSync();
229 229
230 var tempDir = new Directory(''); 230 var tempDir = new Directory('');
231 tempDir.createTempSync(); 231 tempDir.createTempSync();
232 var dstFileName = tempDir.path + "/readline_test1.dat"; 232 var dstFileName = tempDir.path + "/readline_test1.dat";
233 var dstFile = new File(dstFileName); 233 var dstFile = new File(dstFileName);
234 dstFile.createSync(); 234 dstFile.createSync();
235 var dstStream = dstFile.openOutputStream(); 235 var dstStream = dstFile.openOutputStreamSync();
236 236
237 srcStream.closeHandler = () { 237 srcStream.closeHandler = () {
238 var srcStream2 = srcFile.openInputStream(); 238 var srcStream2 = srcFile.openInputStreamSync();
239 239
240 srcStream2.closeHandler = () { 240 srcStream2.closeHandler = () {
241 var src = srcFile.openSync(); 241 var src = srcFile.openSync();
242 var dst = dstFile.openSync(); 242 var dst = dstFile.openSync();
243 var srcLength = src.lengthSync(); 243 var srcLength = src.lengthSync();
244 var dstLength = dst.lengthSync(); 244 var dstLength = dst.lengthSync();
245 Expect.equals(srcLength * 2, dstLength); 245 Expect.equals(srcLength * 2, dstLength);
246 Expect.isTrue(compareFileContent(srcFileName, 246 Expect.isTrue(compareFileContent(srcFileName,
247 dstFileName, 247 dstFileName,
248 count: srcLength)); 248 count: srcLength));
(...skipping 14 matching lines...) Expand all
263 srcStream.pipe(dstStream, close: false); 263 srcStream.pipe(dstStream, close: false);
264 } 264 }
265 265
266 266
267 main() { 267 main() {
268 testFileToFilePipe1(); 268 testFileToFilePipe1();
269 testFileToFilePipe2(); 269 testFileToFilePipe2();
270 testFileToFilePipe3(); 270 testFileToFilePipe3();
271 PipeServerGame echoServerGame = new PipeServerGame.start(); 271 PipeServerGame echoServerGame = new PipeServerGame.start();
272 } 272 }
OLDNEW
« no previous file with comments | « tests/standalone/src/ReadIntoConstList.dart ('k') | tools/testing/dart/status_file_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698