| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 void connectionHandler(Socket connection) { | 152 void connectionHandler(Socket connection) { |
| 153 connection.errorHandler = () { Expect.fail("Socket error"); }; | 153 connection.errorHandler = () { Expect.fail("Socket error"); }; |
| 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 // Force test to timeout if one of the handlers is |
| 163 // not called. |
| 164 ReceivePort donePort = new ReceivePort.singleShot(); |
| 165 donePort.receive((message, ignore) {}); |
| 166 |
| 162 String srcFileName = | 167 String srcFileName = |
| 163 getDataFilename("tests/standalone/src/readline_test1.dat"); | 168 getDataFilename("tests/standalone/src/readline_test1.dat"); |
| 164 var srcStream = new File(srcFileName).openInputStreamSync(); | 169 var srcStream = new File(srcFileName).openInputStreamSync(); |
| 165 | 170 |
| 166 var tempDir = new Directory(''); | 171 var tempDir = new Directory(''); |
| 167 tempDir.createTempSync(); | 172 tempDir.createTempSync(); |
| 168 String dstFileName = tempDir.path + "/readline_test1.dat"; | 173 String dstFileName = tempDir.path + "/readline_test1.dat"; |
| 169 new File(dstFileName).createSync(); | 174 new File(dstFileName).createSync(); |
| 170 var dstStream = new File(dstFileName).openOutputStreamSync(); | 175 var dstStream = new File(dstFileName).openOutputStreamSync(); |
| 171 | 176 |
| 172 srcStream.closeHandler = () { | 177 dstStream.closeHandler = () { |
| 173 bool result = compareFileContent(srcFileName, dstFileName); | 178 bool result = compareFileContent(srcFileName, dstFileName); |
| 174 new File(dstFileName).deleteSync(); | 179 new File(dstFileName).deleteSync(); |
| 175 tempDir.deleteSync(); | 180 tempDir.deleteSync(); |
| 176 Expect.isTrue(result); | 181 Expect.isTrue(result); |
| 182 donePort.toSendPort().send(null); |
| 177 }; | 183 }; |
| 178 | 184 |
| 179 srcStream.pipe(dstStream); | 185 srcStream.pipe(dstStream); |
| 180 } | 186 } |
| 181 | 187 |
| 182 | 188 |
| 183 // 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 |
| 184 // the output stream after piping finished. | 190 // the output stream after piping finished. |
| 185 testFileToFilePipe2() { | 191 testFileToFilePipe2() { |
| 192 // Force test to timeout if one of the handlers is |
| 193 // not called. |
| 194 ReceivePort donePort = new ReceivePort.singleShot(); |
| 195 donePort.receive((message, ignore) {}); |
| 196 |
| 186 String srcFileName = | 197 String srcFileName = |
| 187 getDataFilename("tests/standalone/src/readline_test1.dat"); | 198 getDataFilename("tests/standalone/src/readline_test1.dat"); |
| 188 var srcFile = new File(srcFileName); | 199 var srcFile = new File(srcFileName); |
| 189 var srcStream = srcFile.openInputStreamSync(); | 200 var srcStream = srcFile.openInputStreamSync(); |
| 190 | 201 |
| 191 var tempDir = new Directory(''); | 202 var tempDir = new Directory(''); |
| 192 tempDir.createTempSync(); | 203 tempDir.createTempSync(); |
| 193 var dstFileName = tempDir.path + "/readline_test1.dat"; | 204 var dstFileName = tempDir.path + "/readline_test1.dat"; |
| 194 var dstFile = new File(dstFileName); | 205 var dstFile = new File(dstFileName); |
| 195 dstFile.createSync(); | 206 dstFile.createSync(); |
| 196 var dstStream = dstFile.openOutputStreamSync(); | 207 var dstStream = dstFile.openOutputStreamSync(); |
| 197 | 208 |
| 198 srcStream.closeHandler = () { | 209 srcStream.closeHandler = () { |
| 199 dstStream.write([32]); | 210 dstStream.write([32]); |
| 200 dstStream.close(); | 211 dstStream.close(); |
| 201 var src = srcFile.openSync(); | 212 dstStream.closeHandler = () { |
| 202 var dst = dstFile.openSync(); | 213 var src = srcFile.openSync(); |
| 203 var srcLength = src.lengthSync(); | 214 var dst = dstFile.openSync(); |
| 204 var dstLength = dst.lengthSync(); | 215 var srcLength = src.lengthSync(); |
| 205 Expect.equals(srcLength + 1, dstLength); | 216 var dstLength = dst.lengthSync(); |
| 206 Expect.isTrue(compareFileContent(srcFileName, | 217 Expect.equals(srcLength + 1, dstLength); |
| 207 dstFileName, | 218 Expect.isTrue(compareFileContent(srcFileName, |
| 208 count: srcLength)); | 219 dstFileName, |
| 209 dst.setPositionSync(srcLength); | 220 count: srcLength)); |
| 210 var data = new List<int>(1); | 221 dst.setPositionSync(srcLength); |
| 211 var read2 = dst.readListSync(data, 0, 1); | 222 var data = new List<int>(1); |
| 212 Expect.equals(32, data[0]); | 223 var read2 = dst.readListSync(data, 0, 1); |
| 213 src.closeSync(); | 224 Expect.equals(32, data[0]); |
| 214 dst.closeSync(); | 225 src.closeSync(); |
| 215 dstFile.deleteSync(); | 226 dst.closeSync(); |
| 216 tempDir.deleteSync(); | 227 dstFile.deleteSync(); |
| 228 tempDir.deleteSync(); |
| 229 donePort.toSendPort().send(null); |
| 230 }; |
| 217 }; | 231 }; |
| 218 | 232 |
| 219 srcStream.pipe(dstStream, close: false); | 233 srcStream.pipe(dstStream, close: false); |
| 220 } | 234 } |
| 221 | 235 |
| 222 | 236 |
| 223 // Test piping two copies of one file to another. | 237 // Test piping two copies of one file to another. |
| 224 testFileToFilePipe3() { | 238 testFileToFilePipe3() { |
| 239 // Force test to timeout if one of the handlers is |
| 240 // not called. |
| 241 ReceivePort donePort = new ReceivePort.singleShot(); |
| 242 donePort.receive((message, ignore) {}); |
| 243 |
| 225 String srcFileName = | 244 String srcFileName = |
| 226 getDataFilename("tests/standalone/src/readline_test1.dat"); | 245 getDataFilename("tests/standalone/src/readline_test1.dat"); |
| 227 var srcFile = new File(srcFileName); | 246 var srcFile = new File(srcFileName); |
| 228 var srcStream = srcFile.openInputStreamSync(); | 247 var srcStream = srcFile.openInputStreamSync(); |
| 229 | 248 |
| 230 var tempDir = new Directory(''); | 249 var tempDir = new Directory(''); |
| 231 tempDir.createTempSync(); | 250 tempDir.createTempSync(); |
| 232 var dstFileName = tempDir.path + "/readline_test1.dat"; | 251 var dstFileName = tempDir.path + "/readline_test1.dat"; |
| 233 var dstFile = new File(dstFileName); | 252 var dstFile = new File(dstFileName); |
| 234 dstFile.createSync(); | 253 dstFile.createSync(); |
| 235 var dstStream = dstFile.openOutputStreamSync(); | 254 var dstStream = dstFile.openOutputStreamSync(); |
| 236 | 255 |
| 237 srcStream.closeHandler = () { | 256 srcStream.closeHandler = () { |
| 238 var srcStream2 = srcFile.openInputStreamSync(); | 257 var srcStream2 = srcFile.openInputStreamSync(); |
| 239 | 258 |
| 240 srcStream2.closeHandler = () { | 259 dstStream.closeHandler = () { |
| 241 var src = srcFile.openSync(); | 260 var src = srcFile.openSync(); |
| 242 var dst = dstFile.openSync(); | 261 var dst = dstFile.openSync(); |
| 243 var srcLength = src.lengthSync(); | 262 var srcLength = src.lengthSync(); |
| 244 var dstLength = dst.lengthSync(); | 263 var dstLength = dst.lengthSync(); |
| 245 Expect.equals(srcLength * 2, dstLength); | 264 Expect.equals(srcLength * 2, dstLength); |
| 246 Expect.isTrue(compareFileContent(srcFileName, | 265 Expect.isTrue(compareFileContent(srcFileName, |
| 247 dstFileName, | 266 dstFileName, |
| 248 count: srcLength)); | 267 count: srcLength)); |
| 249 Expect.isTrue(compareFileContent(srcFileName, | 268 Expect.isTrue(compareFileContent(srcFileName, |
| 250 dstFileName, | 269 dstFileName, |
| 251 file2Offset: srcLength, | 270 file2Offset: srcLength, |
| 252 count: srcLength)); | 271 count: srcLength)); |
| 253 src.closeSync(); | 272 src.closeSync(); |
| 254 dst.closeSync(); | 273 dst.closeSync(); |
| 255 dstFile.deleteSync(); | 274 dstFile.deleteSync(); |
| 256 tempDir.deleteSync(); | 275 tempDir.deleteSync(); |
| 276 donePort.toSendPort().send(null); |
| 257 }; | 277 }; |
| 258 | 278 |
| 259 // Pipe another copy of the source file. | 279 // Pipe another copy of the source file. |
| 260 srcStream2.pipe(dstStream); | 280 srcStream2.pipe(dstStream); |
| 261 }; | 281 }; |
| 262 | 282 |
| 263 srcStream.pipe(dstStream, close: false); | 283 srcStream.pipe(dstStream, close: false); |
| 264 } | 284 } |
| 265 | 285 |
| 266 | 286 |
| 267 main() { | 287 main() { |
| 268 testFileToFilePipe1(); | 288 testFileToFilePipe1(); |
| 269 testFileToFilePipe2(); | 289 testFileToFilePipe2(); |
| 270 testFileToFilePipe3(); | 290 testFileToFilePipe3(); |
| 271 PipeServerGame echoServerGame = new PipeServerGame.start(); | 291 PipeServerGame echoServerGame = new PipeServerGame.start(); |
| 272 } | 292 } |
| OLD | NEW |