| Index: tests/standalone/io/stream_pipe_test.dart
|
| diff --git a/tests/standalone/io/stream_pipe_test.dart b/tests/standalone/io/stream_pipe_test.dart
|
| index 8a1b91052bc6b2baea3133e1c622f192ab953ca4..f663e81d9035aeafe1525c9711e4ae5846a57324 100644
|
| --- a/tests/standalone/io/stream_pipe_test.dart
|
| +++ b/tests/standalone/io/stream_pipe_test.dart
|
| @@ -10,7 +10,6 @@ library ServerTest;
|
|
|
| import "dart:io";
|
| import "dart:isolate";
|
| -part "testing_server.dart";
|
|
|
| // Helper method to be able to run the test from the runtime
|
| // directory, or the top directory.
|
| @@ -56,112 +55,6 @@ bool compareFileContent(String fileName1,
|
| }
|
|
|
|
|
| -// This test does:
|
| -// 1. Opens a socket to the testing server.
|
| -// 2. Pipes the content of a file to that sockets input stream.
|
| -// 3. Creates a temp file.
|
| -// 4. Pipes the socket output stream to the temp file.
|
| -// 5. Expects the original file and the temp file to be equal.
|
| -class PipeServerGame {
|
| - int count = 0;
|
| -
|
| - PipeServerGame.start()
|
| - : _receivePort = new ReceivePort(),
|
| - _sendPort = null,
|
| - _messages = 0 {
|
| - _sendPort = spawnFunction(startPipeServer);
|
| - initialize();
|
| - }
|
| -
|
| - void runTest() {
|
| -
|
| - void connectHandler() {
|
| - String srcFileName =
|
| - getDataFilename("tests/standalone/io/readline_test1.dat");
|
| -
|
| - OutputStream socketOutput = _socket.outputStream;
|
| - InputStream fileInput = new File(srcFileName).openInputStream();
|
| -
|
| - fileInput.onClosed = () {
|
| - InputStream socketInput = _socket.inputStream;
|
| - var tempDir = new Directory('').createTempSync();
|
| - var dstFileName = tempDir.path.concat("/readline_test1.dat");
|
| - var dstFile = new File(dstFileName);
|
| - dstFile.createSync();
|
| - var fileOutput = dstFile.openOutputStream();
|
| -
|
| - socketInput.onClosed = () {
|
| - // Check that the resulting file is equal to the initial
|
| - // file.
|
| - fileOutput.onClosed = () {
|
| - bool result = compareFileContent(srcFileName, dstFileName);
|
| - new File(dstFileName).deleteSync();
|
| - tempDir.deleteSync();
|
| - Expect.isTrue(result);
|
| -
|
| - _socket.close();
|
| -
|
| - // Run this twice.
|
| - if (count++ < 2) {
|
| - runTest();
|
| - } else {
|
| - shutdown();
|
| - }
|
| - };
|
| - };
|
| -
|
| - socketInput.pipe(fileOutput);
|
| - };
|
| -
|
| - fileInput.pipe(socketOutput);
|
| - }
|
| -
|
| - // Connect to the server.
|
| - _socket = new Socket(TestingServer.HOST, _port);
|
| - if (_socket != null) {
|
| - _socket.onConnect = connectHandler;
|
| - } else {
|
| - Expect.fail("socket creation failed");
|
| - }
|
| - }
|
| -
|
| - void initialize() {
|
| - _receivePort.receive((var message, SendPort replyTo) {
|
| - _port = message;
|
| - runTest();
|
| - });
|
| - _sendPort.send(TestingServer.INIT, _receivePort.toSendPort());
|
| - }
|
| -
|
| - void shutdown() {
|
| - _sendPort.send(TestingServer.SHUTDOWN, _receivePort.toSendPort());
|
| - _receivePort.close();
|
| - }
|
| -
|
| - int _port;
|
| - ReceivePort _receivePort;
|
| - SendPort _sendPort;
|
| - Socket _socket;
|
| - int _messages;
|
| -}
|
| -
|
| -
|
| -void startPipeServer() {
|
| - var server = new PipeServer();
|
| - port.receive(server.dispatch);
|
| -}
|
| -
|
| -
|
| -// The testing server will simply pipe each connecting sockets input
|
| -// stream to its output stream.
|
| -class PipeServer extends TestingServer {
|
| - void onConnection(Socket connection) {
|
| - connection.onError = (Exception e) { Expect.fail("Socket error $e"); };
|
| - connection.inputStream.pipe(connection.outputStream);
|
| - }
|
| -}
|
| -
|
| -
|
| // Test piping from one file to another and closing both streams
|
| // after wards.
|
| testFileToFilePipe1() {
|
| @@ -172,22 +65,19 @@ testFileToFilePipe1() {
|
|
|
| String srcFileName =
|
| getDataFilename("tests/standalone/io/readline_test1.dat");
|
| - var srcStream = new File(srcFileName).openInputStream();
|
| + var srcStream = new File(srcFileName).openRead();
|
|
|
| var tempDir = new Directory('').createTempSync();
|
| String dstFileName = tempDir.path.concat("/readline_test1.dat");
|
| new File(dstFileName).createSync();
|
| - var dstStream = new File(dstFileName).openOutputStream();
|
| -
|
| - dstStream.onClosed = () {
|
| + var output = new File(dstFileName).openWrite();
|
| + srcStream.pipe(output).then((_) {
|
| bool result = compareFileContent(srcFileName, dstFileName);
|
| new File(dstFileName).deleteSync();
|
| tempDir.deleteSync();
|
| Expect.isTrue(result);
|
| donePort.toSendPort().send(null);
|
| - };
|
| -
|
| - srcStream.pipe(dstStream);
|
| + });
|
| }
|
|
|
|
|
| @@ -202,18 +92,17 @@ testFileToFilePipe2() {
|
| String srcFileName =
|
| getDataFilename("tests/standalone/io/readline_test1.dat");
|
| var srcFile = new File(srcFileName);
|
| - var srcStream = srcFile.openInputStream();
|
| + var srcStream = srcFile.openRead();
|
|
|
| var tempDir = new Directory('').createTempSync();
|
| var dstFileName = tempDir.path.concat("/readline_test1.dat");
|
| var dstFile = new File(dstFileName);
|
| dstFile.createSync();
|
| - var dstStream = dstFile.openOutputStream();
|
| -
|
| - srcStream.onClosed = () {
|
| - dstStream.write([32]);
|
| - dstStream.close();
|
| - dstStream.onClosed = () {
|
| + var output = dstFile.openWrite();
|
| + output.addStream(srcStream).then((_) {
|
| + output.add([32]);
|
| + output.close();
|
| + output.done.then((_) {
|
| var src = srcFile.openSync();
|
| var dst = dstFile.openSync();
|
| var srcLength = src.lengthSync();
|
| @@ -231,10 +120,8 @@ testFileToFilePipe2() {
|
| dstFile.deleteSync();
|
| tempDir.deleteSync();
|
| donePort.toSendPort().send(null);
|
| - };
|
| - };
|
| -
|
| - srcStream.pipe(dstStream, close: false);
|
| + });
|
| + });
|
| }
|
|
|
|
|
| @@ -248,42 +135,38 @@ testFileToFilePipe3() {
|
| String srcFileName =
|
| getDataFilename("tests/standalone/io/readline_test1.dat");
|
| var srcFile = new File(srcFileName);
|
| - var srcStream = srcFile.openInputStream();
|
| + var srcStream = srcFile.openRead();
|
|
|
| var tempDir = new Directory('').createTempSync();
|
| var dstFileName = tempDir.path.concat("/readline_test1.dat");
|
| var dstFile = new File(dstFileName);
|
| dstFile.createSync();
|
| - var dstStream = dstFile.openOutputStream();
|
| -
|
| - srcStream.onClosed = () {
|
| - var srcStream2 = srcFile.openInputStream();
|
| -
|
| - dstStream.onClosed = () {
|
| - var src = srcFile.openSync();
|
| - var dst = dstFile.openSync();
|
| - var srcLength = src.lengthSync();
|
| - var dstLength = dst.lengthSync();
|
| - Expect.equals(srcLength * 2, dstLength);
|
| - Expect.isTrue(compareFileContent(srcFileName,
|
| - dstFileName,
|
| - count: srcLength));
|
| - Expect.isTrue(compareFileContent(srcFileName,
|
| - dstFileName,
|
| - file2Offset: srcLength,
|
| - count: srcLength));
|
| - src.closeSync();
|
| - dst.closeSync();
|
| - dstFile.deleteSync();
|
| - tempDir.deleteSync();
|
| - donePort.toSendPort().send(null);
|
| - };
|
| -
|
| - // Pipe another copy of the source file.
|
| - srcStream2.pipe(dstStream);
|
| - };
|
| -
|
| - srcStream.pipe(dstStream, close: false);
|
| + var output = dstFile.openWrite();
|
| + output.addStream(srcStream).then((_) {
|
| + var srcStream2 = srcFile.openRead();
|
| + output.addStream(srcStream2).then((_) {
|
| + output.close();
|
| + output.done.then((_) {
|
| + var src = srcFile.openSync();
|
| + var dst = dstFile.openSync();
|
| + var srcLength = src.lengthSync();
|
| + var dstLength = dst.lengthSync();
|
| + Expect.equals(srcLength * 2, dstLength);
|
| + Expect.isTrue(compareFileContent(srcFileName,
|
| + dstFileName,
|
| + count: srcLength));
|
| + Expect.isTrue(compareFileContent(srcFileName,
|
| + dstFileName,
|
| + file2Offset: srcLength,
|
| + count: srcLength));
|
| + src.closeSync();
|
| + dst.closeSync();
|
| + dstFile.deleteSync();
|
| + tempDir.deleteSync();
|
| + donePort.toSendPort().send(null);
|
| + });
|
| + });
|
| + });
|
| }
|
|
|
|
|
| @@ -291,5 +174,4 @@ main() {
|
| testFileToFilePipe1();
|
| testFileToFilePipe2();
|
| testFileToFilePipe3();
|
| - PipeServerGame echoServerGame = new PipeServerGame.start();
|
| }
|
|
|