OLD | NEW |
1 // Copyright (c) 2012, 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 #import("dart:io"); | 10 #import("dart:io"); |
11 #import("dart:isolate"); | 11 #import("dart:isolate"); |
12 #source("testing_server.dart"); | 12 #source("testing_server.dart"); |
13 | 13 |
14 // Helper method to be able to run the test from the runtime | 14 // Helper method to be able to run the test from the runtime |
15 // directory, or the top directory. | 15 // directory, or the top directory. |
16 String getDataFilename(String path) => | 16 String getDataFilename(String path) => |
17 new File(path).existsSync() ? path : '../' + path; | 17 new File(path).existsSync() ? path : '../$path'; |
18 | 18 |
19 | 19 |
20 bool compareFileContent(String fileName1, | 20 bool compareFileContent(String fileName1, |
21 String fileName2, | 21 String fileName2, |
22 [int file1Offset = 0, | 22 [int file1Offset = 0, |
23 int file2Offset = 0, | 23 int file2Offset = 0, |
24 int count]) { | 24 int count]) { |
25 var file1 = new File(fileName1).openSync(); | 25 var file1 = new File(fileName1).openSync(); |
26 var file2 = new File(fileName2).openSync(); | 26 var file2 = new File(fileName2).openSync(); |
27 var length1 = file1.lengthSync(); | 27 var length1 = file1.lengthSync(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 void connectHandler() { | 79 void connectHandler() { |
80 String srcFileName = | 80 String srcFileName = |
81 getDataFilename("tests/standalone/io/readline_test1.dat"); | 81 getDataFilename("tests/standalone/io/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).openInputStream(); |
85 | 85 |
86 fileInput.onClosed = () { | 86 fileInput.onClosed = () { |
87 SocketInputStream socketInput = _socket.inputStream; | 87 SocketInputStream socketInput = _socket.inputStream; |
88 var tempDir = new Directory('').createTempSync(); | 88 var tempDir = new Directory('').createTempSync(); |
89 var dstFileName = tempDir.path + "/readline_test1.dat"; | 89 var dstFileName = tempDir.path.concat("/readline_test1.dat"); |
90 var dstFile = new File(dstFileName); | 90 var dstFile = new File(dstFileName); |
91 dstFile.createSync(); | 91 dstFile.createSync(); |
92 var fileOutput = dstFile.openOutputStream(); | 92 var fileOutput = dstFile.openOutputStream(); |
93 | 93 |
94 socketInput.onClosed = () { | 94 socketInput.onClosed = () { |
95 // Check that the resulting file is equal to the initial | 95 // Check that the resulting file is equal to the initial |
96 // file. | 96 // file. |
97 fileOutput.onClosed = () { | 97 fileOutput.onClosed = () { |
98 bool result = compareFileContent(srcFileName, dstFileName); | 98 bool result = compareFileContent(srcFileName, dstFileName); |
99 new File(dstFileName).deleteSync(); | 99 new File(dstFileName).deleteSync(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // Force test to timeout if one of the handlers is | 163 // Force test to timeout if one of the handlers is |
164 // not called. | 164 // not called. |
165 ReceivePort donePort = new ReceivePort(); | 165 ReceivePort donePort = new ReceivePort(); |
166 donePort.receive((message, ignore) { donePort.close(); }); | 166 donePort.receive((message, ignore) { donePort.close(); }); |
167 | 167 |
168 String srcFileName = | 168 String srcFileName = |
169 getDataFilename("tests/standalone/io/readline_test1.dat"); | 169 getDataFilename("tests/standalone/io/readline_test1.dat"); |
170 var srcStream = new File(srcFileName).openInputStream(); | 170 var srcStream = new File(srcFileName).openInputStream(); |
171 | 171 |
172 var tempDir = new Directory('').createTempSync(); | 172 var tempDir = new Directory('').createTempSync(); |
173 String dstFileName = tempDir.path + "/readline_test1.dat"; | 173 String dstFileName = tempDir.path.concat("/readline_test1.dat"); |
174 new File(dstFileName).createSync(); | 174 new File(dstFileName).createSync(); |
175 var dstStream = new File(dstFileName).openOutputStream(); | 175 var dstStream = new File(dstFileName).openOutputStream(); |
176 | 176 |
177 dstStream.onClosed = () { | 177 dstStream.onClosed = () { |
178 bool result = compareFileContent(srcFileName, dstFileName); | 178 bool result = compareFileContent(srcFileName, dstFileName); |
179 new File(dstFileName).deleteSync(); | 179 new File(dstFileName).deleteSync(); |
180 tempDir.deleteSync(); | 180 tempDir.deleteSync(); |
181 Expect.isTrue(result); | 181 Expect.isTrue(result); |
182 donePort.toSendPort().send(null); | 182 donePort.toSendPort().send(null); |
183 }; | 183 }; |
184 | 184 |
185 srcStream.pipe(dstStream); | 185 srcStream.pipe(dstStream); |
186 } | 186 } |
187 | 187 |
188 | 188 |
189 // Test piping from one file to another and write additional data to | 189 // Test piping from one file to another and write additional data to |
190 // the output stream after piping finished. | 190 // the output stream after piping finished. |
191 testFileToFilePipe2() { | 191 testFileToFilePipe2() { |
192 // Force test to timeout if one of the handlers is | 192 // Force test to timeout if one of the handlers is |
193 // not called. | 193 // not called. |
194 ReceivePort donePort = new ReceivePort(); | 194 ReceivePort donePort = new ReceivePort(); |
195 donePort.receive((message, ignore) { donePort.close(); }); | 195 donePort.receive((message, ignore) { donePort.close(); }); |
196 | 196 |
197 String srcFileName = | 197 String srcFileName = |
198 getDataFilename("tests/standalone/io/readline_test1.dat"); | 198 getDataFilename("tests/standalone/io/readline_test1.dat"); |
199 var srcFile = new File(srcFileName); | 199 var srcFile = new File(srcFileName); |
200 var srcStream = srcFile.openInputStream(); | 200 var srcStream = srcFile.openInputStream(); |
201 | 201 |
202 var tempDir = new Directory('').createTempSync(); | 202 var tempDir = new Directory('').createTempSync(); |
203 var dstFileName = tempDir.path + "/readline_test1.dat"; | 203 var dstFileName = tempDir.path.concat("/readline_test1.dat"); |
204 var dstFile = new File(dstFileName); | 204 var dstFile = new File(dstFileName); |
205 dstFile.createSync(); | 205 dstFile.createSync(); |
206 var dstStream = dstFile.openOutputStream(); | 206 var dstStream = dstFile.openOutputStream(); |
207 | 207 |
208 srcStream.onClosed = () { | 208 srcStream.onClosed = () { |
209 dstStream.write([32]); | 209 dstStream.write([32]); |
210 dstStream.close(); | 210 dstStream.close(); |
211 dstStream.onClosed = () { | 211 dstStream.onClosed = () { |
212 var src = srcFile.openSync(); | 212 var src = srcFile.openSync(); |
213 var dst = dstFile.openSync(); | 213 var dst = dstFile.openSync(); |
(...skipping 25 matching lines...) Expand all Loading... |
239 // not called. | 239 // not called. |
240 ReceivePort donePort = new ReceivePort(); | 240 ReceivePort donePort = new ReceivePort(); |
241 donePort.receive((message, ignore) { donePort.close(); }); | 241 donePort.receive((message, ignore) { donePort.close(); }); |
242 | 242 |
243 String srcFileName = | 243 String srcFileName = |
244 getDataFilename("tests/standalone/io/readline_test1.dat"); | 244 getDataFilename("tests/standalone/io/readline_test1.dat"); |
245 var srcFile = new File(srcFileName); | 245 var srcFile = new File(srcFileName); |
246 var srcStream = srcFile.openInputStream(); | 246 var srcStream = srcFile.openInputStream(); |
247 | 247 |
248 var tempDir = new Directory('').createTempSync(); | 248 var tempDir = new Directory('').createTempSync(); |
249 var dstFileName = tempDir.path + "/readline_test1.dat"; | 249 var dstFileName = tempDir.path.concat("/readline_test1.dat"); |
250 var dstFile = new File(dstFileName); | 250 var dstFile = new File(dstFileName); |
251 dstFile.createSync(); | 251 dstFile.createSync(); |
252 var dstStream = dstFile.openOutputStream(); | 252 var dstStream = dstFile.openOutputStream(); |
253 | 253 |
254 srcStream.onClosed = () { | 254 srcStream.onClosed = () { |
255 var srcStream2 = srcFile.openInputStream(); | 255 var srcStream2 = srcFile.openInputStream(); |
256 | 256 |
257 dstStream.onClosed = () { | 257 dstStream.onClosed = () { |
258 var src = srcFile.openSync(); | 258 var src = srcFile.openSync(); |
259 var dst = dstFile.openSync(); | 259 var dst = dstFile.openSync(); |
(...skipping 21 matching lines...) Expand all Loading... |
281 srcStream.pipe(dstStream, close: false); | 281 srcStream.pipe(dstStream, close: false); |
282 } | 282 } |
283 | 283 |
284 | 284 |
285 main() { | 285 main() { |
286 testFileToFilePipe1(); | 286 testFileToFilePipe1(); |
287 testFileToFilePipe2(); | 287 testFileToFilePipe2(); |
288 testFileToFilePipe3(); | 288 testFileToFilePipe3(); |
289 PipeServerGame echoServerGame = new PipeServerGame.start(); | 289 PipeServerGame echoServerGame = new PipeServerGame.start(); |
290 } | 290 } |
OLD | NEW |