| 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 #library("StreamPipeTest"); | 10 #library("StreamPipeTest"); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 }); | 75 }); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void runTest() { | 78 void runTest() { |
| 79 | 79 |
| 80 void connectHandler() { | 80 void connectHandler() { |
| 81 String srcFileName = | 81 String srcFileName = |
| 82 getDataFilename("tests/standalone/src/readline_test1.dat"); | 82 getDataFilename("tests/standalone/src/readline_test1.dat"); |
| 83 | 83 |
| 84 SocketOutputStream socketOutput = _socket.outputStream; | 84 SocketOutputStream socketOutput = _socket.outputStream; |
| 85 InputStream fileInput = new File(srcFileName).openInputStreamSync(); | 85 InputStream fileInput = new File(srcFileName).openInputStream(); |
| 86 | 86 |
| 87 fileInput.closeHandler = () { | 87 fileInput.closeHandler = () { |
| 88 SocketInputStream socketInput = _socket.inputStream; | 88 SocketInputStream socketInput = _socket.inputStream; |
| 89 var tempDir = new Directory(''); | 89 var tempDir = new Directory(''); |
| 90 tempDir.createTempSync(); | 90 tempDir.createTempSync(); |
| 91 var dstFileName = tempDir.path + "/readline_test1.dat"; | 91 var dstFileName = tempDir.path + "/readline_test1.dat"; |
| 92 var dstFile = new File(dstFileName); | 92 var dstFile = new File(dstFileName); |
| 93 dstFile.createSync(); | 93 dstFile.createSync(); |
| 94 var fileOutput = dstFile.openOutputStreamSync(); | 94 var fileOutput = dstFile.openOutputStream(); |
| 95 | 95 |
| 96 socketInput.closeHandler = () { | 96 socketInput.closeHandler = () { |
| 97 // Check that the resulting file is equal to the initial | 97 // Check that the resulting file is equal to the initial |
| 98 // file. | 98 // file. |
| 99 bool result = compareFileContent(srcFileName, dstFileName); | 99 bool result = compareFileContent(srcFileName, dstFileName); |
| 100 fileOutput.closeHandler = () { | 100 fileOutput.closeHandler = () { |
| 101 new File(dstFileName).deleteSync(); | 101 new File(dstFileName).deleteSync(); |
| 102 tempDir.deleteSync(); | 102 tempDir.deleteSync(); |
| 103 Expect.isTrue(result); | 103 Expect.isTrue(result); |
| 104 | 104 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // Test piping from one file to another and closing both streams | 162 // Test piping from one file to another and closing both streams |
| 163 // after wards. | 163 // after wards. |
| 164 testFileToFilePipe1() { | 164 testFileToFilePipe1() { |
| 165 // Force test to timeout if one of the handlers is | 165 // Force test to timeout if one of the handlers is |
| 166 // not called. | 166 // not called. |
| 167 ReceivePort donePort = new ReceivePort.singleShot(); | 167 ReceivePort donePort = new ReceivePort.singleShot(); |
| 168 donePort.receive((message, ignore) {}); | 168 donePort.receive((message, ignore) {}); |
| 169 | 169 |
| 170 String srcFileName = | 170 String srcFileName = |
| 171 getDataFilename("tests/standalone/src/readline_test1.dat"); | 171 getDataFilename("tests/standalone/src/readline_test1.dat"); |
| 172 var srcStream = new File(srcFileName).openInputStreamSync(); | 172 var srcStream = new File(srcFileName).openInputStream(); |
| 173 | 173 |
| 174 var tempDir = new Directory(''); | 174 var tempDir = new Directory(''); |
| 175 tempDir.createTempSync(); | 175 tempDir.createTempSync(); |
| 176 String dstFileName = tempDir.path + "/readline_test1.dat"; | 176 String dstFileName = tempDir.path + "/readline_test1.dat"; |
| 177 new File(dstFileName).createSync(); | 177 new File(dstFileName).createSync(); |
| 178 var dstStream = new File(dstFileName).openOutputStreamSync(); | 178 var dstStream = new File(dstFileName).openOutputStream(); |
| 179 | 179 |
| 180 dstStream.closeHandler = () { | 180 dstStream.closeHandler = () { |
| 181 bool result = compareFileContent(srcFileName, dstFileName); | 181 bool result = compareFileContent(srcFileName, dstFileName); |
| 182 new File(dstFileName).deleteSync(); | 182 new File(dstFileName).deleteSync(); |
| 183 tempDir.deleteSync(); | 183 tempDir.deleteSync(); |
| 184 Expect.isTrue(result); | 184 Expect.isTrue(result); |
| 185 donePort.toSendPort().send(null); | 185 donePort.toSendPort().send(null); |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 srcStream.pipe(dstStream); | 188 srcStream.pipe(dstStream); |
| 189 } | 189 } |
| 190 | 190 |
| 191 | 191 |
| 192 // Test piping from one file to another and write additional data to | 192 // Test piping from one file to another and write additional data to |
| 193 // the output stream after piping finished. | 193 // the output stream after piping finished. |
| 194 testFileToFilePipe2() { | 194 testFileToFilePipe2() { |
| 195 // Force test to timeout if one of the handlers is | 195 // Force test to timeout if one of the handlers is |
| 196 // not called. | 196 // not called. |
| 197 ReceivePort donePort = new ReceivePort.singleShot(); | 197 ReceivePort donePort = new ReceivePort.singleShot(); |
| 198 donePort.receive((message, ignore) {}); | 198 donePort.receive((message, ignore) {}); |
| 199 | 199 |
| 200 String srcFileName = | 200 String srcFileName = |
| 201 getDataFilename("tests/standalone/src/readline_test1.dat"); | 201 getDataFilename("tests/standalone/src/readline_test1.dat"); |
| 202 var srcFile = new File(srcFileName); | 202 var srcFile = new File(srcFileName); |
| 203 var srcStream = srcFile.openInputStreamSync(); | 203 var srcStream = srcFile.openInputStream(); |
| 204 | 204 |
| 205 var tempDir = new Directory(''); | 205 var tempDir = new Directory(''); |
| 206 tempDir.createTempSync(); | 206 tempDir.createTempSync(); |
| 207 var dstFileName = tempDir.path + "/readline_test1.dat"; | 207 var dstFileName = tempDir.path + "/readline_test1.dat"; |
| 208 var dstFile = new File(dstFileName); | 208 var dstFile = new File(dstFileName); |
| 209 dstFile.createSync(); | 209 dstFile.createSync(); |
| 210 var dstStream = dstFile.openOutputStreamSync(); | 210 var dstStream = dstFile.openOutputStream(); |
| 211 | 211 |
| 212 srcStream.closeHandler = () { | 212 srcStream.closeHandler = () { |
| 213 dstStream.write([32]); | 213 dstStream.write([32]); |
| 214 dstStream.close(); | 214 dstStream.close(); |
| 215 dstStream.closeHandler = () { | 215 dstStream.closeHandler = () { |
| 216 var src = srcFile.openSync(); | 216 var src = srcFile.openSync(); |
| 217 var dst = dstFile.openSync(); | 217 var dst = dstFile.openSync(); |
| 218 var srcLength = src.lengthSync(); | 218 var srcLength = src.lengthSync(); |
| 219 var dstLength = dst.lengthSync(); | 219 var dstLength = dst.lengthSync(); |
| 220 Expect.equals(srcLength + 1, dstLength); | 220 Expect.equals(srcLength + 1, dstLength); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 240 // Test piping two copies of one file to another. | 240 // Test piping two copies of one file to another. |
| 241 testFileToFilePipe3() { | 241 testFileToFilePipe3() { |
| 242 // Force test to timeout if one of the handlers is | 242 // Force test to timeout if one of the handlers is |
| 243 // not called. | 243 // not called. |
| 244 ReceivePort donePort = new ReceivePort.singleShot(); | 244 ReceivePort donePort = new ReceivePort.singleShot(); |
| 245 donePort.receive((message, ignore) {}); | 245 donePort.receive((message, ignore) {}); |
| 246 | 246 |
| 247 String srcFileName = | 247 String srcFileName = |
| 248 getDataFilename("tests/standalone/src/readline_test1.dat"); | 248 getDataFilename("tests/standalone/src/readline_test1.dat"); |
| 249 var srcFile = new File(srcFileName); | 249 var srcFile = new File(srcFileName); |
| 250 var srcStream = srcFile.openInputStreamSync(); | 250 var srcStream = srcFile.openInputStream(); |
| 251 | 251 |
| 252 var tempDir = new Directory(''); | 252 var tempDir = new Directory(''); |
| 253 tempDir.createTempSync(); | 253 tempDir.createTempSync(); |
| 254 var dstFileName = tempDir.path + "/readline_test1.dat"; | 254 var dstFileName = tempDir.path + "/readline_test1.dat"; |
| 255 var dstFile = new File(dstFileName); | 255 var dstFile = new File(dstFileName); |
| 256 dstFile.createSync(); | 256 dstFile.createSync(); |
| 257 var dstStream = dstFile.openOutputStreamSync(); | 257 var dstStream = dstFile.openOutputStream(); |
| 258 | 258 |
| 259 srcStream.closeHandler = () { | 259 srcStream.closeHandler = () { |
| 260 var srcStream2 = srcFile.openInputStreamSync(); | 260 var srcStream2 = srcFile.openInputStream(); |
| 261 | 261 |
| 262 dstStream.closeHandler = () { | 262 dstStream.closeHandler = () { |
| 263 var src = srcFile.openSync(); | 263 var src = srcFile.openSync(); |
| 264 var dst = dstFile.openSync(); | 264 var dst = dstFile.openSync(); |
| 265 var srcLength = src.lengthSync(); | 265 var srcLength = src.lengthSync(); |
| 266 var dstLength = dst.lengthSync(); | 266 var dstLength = dst.lengthSync(); |
| 267 Expect.equals(srcLength * 2, dstLength); | 267 Expect.equals(srcLength * 2, dstLength); |
| 268 Expect.isTrue(compareFileContent(srcFileName, | 268 Expect.isTrue(compareFileContent(srcFileName, |
| 269 dstFileName, | 269 dstFileName, |
| 270 count: srcLength)); | 270 count: srcLength)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 286 srcStream.pipe(dstStream, close: false); | 286 srcStream.pipe(dstStream, close: false); |
| 287 } | 287 } |
| 288 | 288 |
| 289 | 289 |
| 290 main() { | 290 main() { |
| 291 testFileToFilePipe1(); | 291 testFileToFilePipe1(); |
| 292 testFileToFilePipe2(); | 292 testFileToFilePipe2(); |
| 293 testFileToFilePipe3(); | 293 testFileToFilePipe3(); |
| 294 PipeServerGame echoServerGame = new PipeServerGame.start(); | 294 PipeServerGame echoServerGame = new PipeServerGame.start(); |
| 295 } | 295 } |
| OLD | NEW |