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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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).openInputStream(); | 85 InputStream fileInput = new File(srcFileName).openInputStream(); |
86 | 86 |
87 fileInput.closeHandler = () { | 87 fileInput.onClosed = () { |
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.openOutputStream(); | 94 var fileOutput = dstFile.openOutputStream(); |
95 | 95 |
96 socketInput.closeHandler = () { | 96 socketInput.onClosed = () { |
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 fileOutput.closeHandler = () { | 99 fileOutput.onClosed = () { |
100 bool result = compareFileContent(srcFileName, dstFileName); | 100 bool result = compareFileContent(srcFileName, dstFileName); |
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 |
105 _socket.close(); | 105 _socket.close(); |
106 | 106 |
107 // Run this twice. | 107 // Run this twice. |
108 if (count++ < 2) { | 108 if (count++ < 2) { |
109 runTest(); | 109 runTest(); |
110 } else { | 110 } else { |
111 shutdown(); | 111 shutdown(); |
112 } | 112 } |
113 }; | 113 }; |
114 }; | 114 }; |
115 | 115 |
116 socketInput.pipe(fileOutput); | 116 socketInput.pipe(fileOutput); |
117 }; | 117 }; |
118 | 118 |
119 fileInput.pipe(socketOutput); | 119 fileInput.pipe(socketOutput); |
120 } | 120 } |
121 | 121 |
122 // Connect to the server. | 122 // Connect to the server. |
123 _socket = new Socket(TestingServer.HOST, _port); | 123 _socket = new Socket(TestingServer.HOST, _port); |
124 if (_socket !== null) { | 124 if (_socket !== null) { |
125 _socket.connectHandler = connectHandler; | 125 _socket.onConnect = connectHandler; |
126 } else { | 126 } else { |
127 Expect.fail("socket creation failed"); | 127 Expect.fail("socket creation failed"); |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 void start() { | 131 void start() { |
132 _receivePort.receive((var message, SendPort replyTo) { | 132 _receivePort.receive((var message, SendPort replyTo) { |
133 _port = message; | 133 _port = message; |
134 runTest(); | 134 runTest(); |
135 }); | 135 }); |
(...skipping 10 matching lines...) Expand all Loading... |
146 SendPort _sendPort; | 146 SendPort _sendPort; |
147 Socket _socket; | 147 Socket _socket; |
148 int _messages; | 148 int _messages; |
149 } | 149 } |
150 | 150 |
151 | 151 |
152 // The testing server will simply pipe each connecting sockets input | 152 // The testing server will simply pipe each connecting sockets input |
153 // stream to its output stream. | 153 // stream to its output stream. |
154 class PipeServer extends TestingServer { | 154 class PipeServer extends TestingServer { |
155 void connectionHandler(Socket connection) { | 155 void connectionHandler(Socket connection) { |
156 connection.errorHandler = () { Expect.fail("Socket error"); }; | 156 connection.onError = () { Expect.fail("Socket error"); }; |
157 connection.inputStream.pipe(connection.outputStream); | 157 connection.inputStream.pipe(connection.outputStream); |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
161 | 161 |
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).openInputStream(); | 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).openOutputStream(); | 178 var dstStream = new File(dstFileName).openOutputStream(); |
179 | 179 |
180 dstStream.closeHandler = () { | 180 dstStream.onClosed = () { |
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 |
(...skipping 11 matching lines...) Expand all Loading... |
202 var srcFile = new File(srcFileName); | 202 var srcFile = new File(srcFileName); |
203 var srcStream = srcFile.openInputStream(); | 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.openOutputStream(); | 210 var dstStream = dstFile.openOutputStream(); |
211 | 211 |
212 srcStream.closeHandler = () { | 212 srcStream.onClosed = () { |
213 dstStream.write([32]); | 213 dstStream.write([32]); |
214 dstStream.close(); | 214 dstStream.close(); |
215 dstStream.closeHandler = () { | 215 dstStream.onClosed = () { |
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); |
221 Expect.isTrue(compareFileContent(srcFileName, | 221 Expect.isTrue(compareFileContent(srcFileName, |
222 dstFileName, | 222 dstFileName, |
223 count: srcLength)); | 223 count: srcLength)); |
224 dst.setPositionSync(srcLength); | 224 dst.setPositionSync(srcLength); |
225 var data = new List<int>(1); | 225 var data = new List<int>(1); |
(...skipping 23 matching lines...) Expand all Loading... |
249 var srcFile = new File(srcFileName); | 249 var srcFile = new File(srcFileName); |
250 var srcStream = srcFile.openInputStream(); | 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.openOutputStream(); | 257 var dstStream = dstFile.openOutputStream(); |
258 | 258 |
259 srcStream.closeHandler = () { | 259 srcStream.onClosed = () { |
260 var srcStream2 = srcFile.openInputStream(); | 260 var srcStream2 = srcFile.openInputStream(); |
261 | 261 |
262 dstStream.closeHandler = () { | 262 dstStream.onClosed = () { |
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)); |
271 Expect.isTrue(compareFileContent(srcFileName, | 271 Expect.isTrue(compareFileContent(srcFileName, |
272 dstFileName, | 272 dstFileName, |
(...skipping 13 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 |