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 // Dart test program for testing file I/O. | 5 // Dart test program for testing file I/O. |
6 | 6 |
7 import "dart:io"; | 7 import 'dart:async'; |
8 import "dart:isolate"; | 8 import 'dart:io'; |
| 9 import 'dart:isolate'; |
9 | 10 |
10 class MyListOfOneElement implements List { | 11 class MyListOfOneElement implements List { |
11 int _value; | 12 int _value; |
12 MyListOfOneElement(this._value); | 13 MyListOfOneElement(this._value); |
13 int get length => 1; | 14 int get length => 1; |
14 operator [](int index) => _value; | 15 operator [](int index) => _value; |
15 } | 16 } |
16 | 17 |
17 class FileTest { | 18 class FileTest { |
18 static Directory tempDirectory; | 19 static Directory tempDirectory; |
(...skipping 21 matching lines...) Expand all Loading... |
40 } | 41 } |
41 | 42 |
42 // Test for file read functionality. | 43 // Test for file read functionality. |
43 static void testReadStream() { | 44 static void testReadStream() { |
44 // Read a file and check part of it's contents. | 45 // Read a file and check part of it's contents. |
45 String filename = getFilename("bin/file_test.cc"); | 46 String filename = getFilename("bin/file_test.cc"); |
46 File file = new File(filename); | 47 File file = new File(filename); |
47 Expect.isTrue('$file'.contains(file.name)); | 48 Expect.isTrue('$file'.contains(file.name)); |
48 InputStream input = file.openInputStream(); | 49 InputStream input = file.openInputStream(); |
49 input.onData = () { | 50 input.onData = () { |
50 List<int> buffer = new List<int>(42); | 51 List<int> buffer = new List<int>.fixedLength(42); |
51 int bytesRead = input.readInto(buffer, 0, 12); | 52 int bytesRead = input.readInto(buffer, 0, 12); |
52 Expect.equals(12, bytesRead); | 53 Expect.equals(12, bytesRead); |
53 bytesRead = input.readInto(buffer, 12, 30); | 54 bytesRead = input.readInto(buffer, 12, 30); |
54 input.close(); | 55 input.close(); |
55 Expect.equals(30, bytesRead); | 56 Expect.equals(30, bytesRead); |
56 Expect.equals(47, buffer[0]); // represents '/' in the file. | 57 Expect.equals(47, buffer[0]); // represents '/' in the file. |
57 Expect.equals(47, buffer[1]); // represents '/' in the file. | 58 Expect.equals(47, buffer[1]); // represents '/' in the file. |
58 Expect.equals(32, buffer[2]); // represents ' ' in the file. | 59 Expect.equals(32, buffer[2]); // represents ' ' in the file. |
59 Expect.equals(67, buffer[3]); // represents 'C' in the file. | 60 Expect.equals(67, buffer[3]); // represents 'C' in the file. |
60 Expect.equals(111, buffer[4]); // represents 'o' in the file. | 61 Expect.equals(111, buffer[4]); // represents 'o' in the file. |
(...skipping 15 matching lines...) Expand all Loading... |
76 String inFilename = getFilename("tests/vm/data/fixed_length_file"); | 77 String inFilename = getFilename("tests/vm/data/fixed_length_file"); |
77 File file; | 78 File file; |
78 InputStream input; | 79 InputStream input; |
79 int bytesRead; | 80 int bytesRead; |
80 | 81 |
81 // Test reading all using readInto. | 82 // Test reading all using readInto. |
82 var file1 = new File(inFilename); | 83 var file1 = new File(inFilename); |
83 var input1 = file1.openInputStream(); | 84 var input1 = file1.openInputStream(); |
84 List<int> buffer1; | 85 List<int> buffer1; |
85 input1.onData = () { | 86 input1.onData = () { |
86 buffer1 = new List<int>(42); | 87 buffer1 = new List<int>.fixedLength(42); |
87 bytesRead = input1.readInto(buffer1, 0, 42); | 88 bytesRead = input1.readInto(buffer1, 0, 42); |
88 Expect.equals(42, bytesRead); | 89 Expect.equals(42, bytesRead); |
89 }; | 90 }; |
90 input1.onError = (e) { throw e; }; | 91 input1.onError = (e) { throw e; }; |
91 input1.onClosed = () { | 92 input1.onClosed = () { |
92 Expect.isTrue(input1.closed); | 93 Expect.isTrue(input1.closed); |
93 | 94 |
94 // Test reading all using readInto and read. | 95 // Test reading all using readInto and read. |
95 var file2 = new File(inFilename); | 96 var file2 = new File(inFilename); |
96 var input2 = file2.openInputStream(); | 97 var input2 = file2.openInputStream(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 String outFilename = | 133 String outFilename = |
133 tempDirectory.path.concat("/out_read_write_stream"); | 134 tempDirectory.path.concat("/out_read_write_stream"); |
134 file = new File(outFilename); | 135 file = new File(outFilename); |
135 OutputStream output = file.openOutputStream(); | 136 OutputStream output = file.openOutputStream(); |
136 bool writeDone = output.writeFrom(buffer1, 0, 42); | 137 bool writeDone = output.writeFrom(buffer1, 0, 42); |
137 Expect.equals(false, writeDone); | 138 Expect.equals(false, writeDone); |
138 output.onNoPendingWrites = () { | 139 output.onNoPendingWrites = () { |
139 output.close(); | 140 output.close(); |
140 output.onClosed = () { | 141 output.onClosed = () { |
141 // Now read the contents of the file just written. | 142 // Now read the contents of the file just written. |
142 List<int> buffer2 = new List<int>(42); | 143 List<int> buffer2 = new List<int>.fixedLength(42); |
143 var file6 = new File(outFilename); | 144 var file6 = new File(outFilename); |
144 var input6 = file6.openInputStream(); | 145 var input6 = file6.openInputStream(); |
145 input6.onData = () { | 146 input6.onData = () { |
146 bytesRead = input6.readInto(buffer2, 0, 42); | 147 bytesRead = input6.readInto(buffer2, 0, 42); |
147 Expect.equals(42, bytesRead); | 148 Expect.equals(42, bytesRead); |
148 // Now compare the two buffers to check if they are identical. | 149 // Now compare the two buffers to check if they are identical. |
149 for (int i = 0; i < buffer1.length; i++) { | 150 for (int i = 0; i < buffer1.length; i++) { |
150 Expect.equals(buffer1[i], buffer2[i]); | 151 Expect.equals(buffer1[i], buffer2[i]); |
151 } | 152 } |
152 }; | 153 }; |
(...skipping 10 matching lines...) Expand all Loading... |
163 }; | 164 }; |
164 }; | 165 }; |
165 }; | 166 }; |
166 } | 167 } |
167 | 168 |
168 // Test for file stream buffered handling of large files. | 169 // Test for file stream buffered handling of large files. |
169 static void testReadWriteStreamLargeFile() { | 170 static void testReadWriteStreamLargeFile() { |
170 asyncTestStarted(); | 171 asyncTestStarted(); |
171 | 172 |
172 // Create the test data - arbitrary binary data. | 173 // Create the test data - arbitrary binary data. |
173 List<int> buffer = new List<int>(100000); | 174 List<int> buffer = new List<int>.fixedLength(100000); |
174 for (var i = 0; i < buffer.length; ++i) { | 175 for (var i = 0; i < buffer.length; ++i) { |
175 buffer[i] = i % 256; | 176 buffer[i] = i % 256; |
176 } | 177 } |
177 String filename = | 178 String filename = |
178 tempDirectory.path.concat("/out_read_write_stream_large_file"); | 179 tempDirectory.path.concat("/out_read_write_stream_large_file"); |
179 File file = new File(filename); | 180 File file = new File(filename); |
180 OutputStream output = file.openOutputStream(); | 181 OutputStream output = file.openOutputStream(); |
181 // Test a write immediately after the output stream is created. | 182 // Test a write immediately after the output stream is created. |
182 output.writeFrom(buffer, 0, 20000); | 183 output.writeFrom(buffer, 0, 20000); |
183 | 184 |
(...skipping 11 matching lines...) Expand all Loading... |
195 InputStream input = file.openInputStream(); | 196 InputStream input = file.openInputStream(); |
196 int position = 0; | 197 int position = 0; |
197 final int expectedLength = 200000; | 198 final int expectedLength = 200000; |
198 // Start an independent asynchronous check on the length. | 199 // Start an independent asynchronous check on the length. |
199 asyncTestStarted(); | 200 asyncTestStarted(); |
200 file.length().then((len) { | 201 file.length().then((len) { |
201 Expect.equals(expectedLength, len); | 202 Expect.equals(expectedLength, len); |
202 asyncTestDone('testReadWriteStreamLargeFile: length check'); | 203 asyncTestDone('testReadWriteStreamLargeFile: length check'); |
203 }); | 204 }); |
204 | 205 |
205 List<int> inputBuffer = new List<int>(expectedLength + 100000); | 206 List<int> inputBuffer = |
| 207 new List<int>.fixedLength(expectedLength + 100000); |
206 // Immediate read should read 0 bytes. | 208 // Immediate read should read 0 bytes. |
207 Expect.equals(0, input.available()); | 209 Expect.equals(0, input.available()); |
208 Expect.equals(false, input.closed); | 210 Expect.equals(false, input.closed); |
209 int bytesRead = input.readInto(inputBuffer); | 211 int bytesRead = input.readInto(inputBuffer); |
210 Expect.equals(0, bytesRead); | 212 Expect.equals(0, bytesRead); |
211 Expect.equals(0, input.available()); | 213 Expect.equals(0, input.available()); |
212 Expect.isFalse(input.closed); | 214 Expect.isFalse(input.closed); |
213 input.onError = (e) { | 215 input.onError = (e) { |
214 print('Error handler called on input in testReadWriteStreamLargeFile'); | 216 print('Error handler called on input in testReadWriteStreamLargeFile'); |
215 print('with error $e'); | 217 print('with error $e'); |
(...skipping 18 matching lines...) Expand all Loading... |
234 Expect.isTrue(input.closed); | 236 Expect.isTrue(input.closed); |
235 input.close(); // This should be safe to call. | 237 input.close(); // This should be safe to call. |
236 | 238 |
237 Expect.equals(expectedLength, position); | 239 Expect.equals(expectedLength, position); |
238 for (int i = 0; i < position; ++i) { | 240 for (int i = 0; i < position; ++i) { |
239 Expect.equals(buffer[i % buffer.length], inputBuffer[i]); | 241 Expect.equals(buffer[i % buffer.length], inputBuffer[i]); |
240 } | 242 } |
241 | 243 |
242 Future testPipeDone = testPipe(file, buffer); | 244 Future testPipeDone = testPipe(file, buffer); |
243 | 245 |
244 Future futureDeleted = testPipeDone.chain((ignored) => file.delete()); | 246 Future futureDeleted = testPipeDone.then((ignored) => file.delete()); |
245 futureDeleted.handleException((e) { | 247 futureDeleted.then((ignored) { |
| 248 asyncTestDone('testReadWriteStreamLargeFile: main test'); |
| 249 }).catchError((e) { |
246 print('Exception while deleting ReadWriteStreamLargeFile file'); | 250 print('Exception while deleting ReadWriteStreamLargeFile file'); |
247 print('Exception $e'); | 251 print('Exception $e'); |
248 return false; // Throw exception further. | |
249 }); | |
250 futureDeleted.then((ignored) { | |
251 asyncTestDone('testReadWriteStreamLargeFile: main test'); | |
252 }); | 252 }); |
253 }; | 253 }; |
254 // Try a read again after handlers are set. | 254 // Try a read again after handlers are set. |
255 bytesRead = input.readInto(inputBuffer); | 255 bytesRead = input.readInto(inputBuffer); |
256 Expect.equals(0, bytesRead); | 256 Expect.equals(0, bytesRead); |
257 Expect.equals(0, input.available()); | 257 Expect.equals(0, input.available()); |
258 Expect.isFalse(input.closed); | 258 Expect.isFalse(input.closed); |
259 }; | 259 }; |
260 } | 260 } |
261 | 261 |
(...skipping 23 matching lines...) Expand all Loading... |
285 }; | 285 }; |
286 return done.future; | 286 return done.future; |
287 } | 287 } |
288 | 288 |
289 static void testRead() { | 289 static void testRead() { |
290 ReceivePort port = new ReceivePort(); | 290 ReceivePort port = new ReceivePort(); |
291 // Read a file and check part of it's contents. | 291 // Read a file and check part of it's contents. |
292 String filename = getFilename("bin/file_test.cc"); | 292 String filename = getFilename("bin/file_test.cc"); |
293 File file = new File(filename); | 293 File file = new File(filename); |
294 file.open(FileMode.READ).then((RandomAccessFile file) { | 294 file.open(FileMode.READ).then((RandomAccessFile file) { |
295 List<int> buffer = new List<int>(10); | 295 List<int> buffer = new List<int>.fixedLength(10); |
296 file.readList(buffer, 0, 5).then((bytes_read) { | 296 file.readList(buffer, 0, 5).then((bytes_read) { |
297 Expect.equals(5, bytes_read); | 297 Expect.equals(5, bytes_read); |
298 file.readList(buffer, 5, 5).then((bytes_read) { | 298 file.readList(buffer, 5, 5).then((bytes_read) { |
299 Expect.equals(5, bytes_read); | 299 Expect.equals(5, bytes_read); |
300 Expect.equals(47, buffer[0]); // represents '/' in the file. | 300 Expect.equals(47, buffer[0]); // represents '/' in the file. |
301 Expect.equals(47, buffer[1]); // represents '/' in the file. | 301 Expect.equals(47, buffer[1]); // represents '/' in the file. |
302 Expect.equals(32, buffer[2]); // represents ' ' in the file. | 302 Expect.equals(32, buffer[2]); // represents ' ' in the file. |
303 Expect.equals(67, buffer[3]); // represents 'C' in the file. | 303 Expect.equals(67, buffer[3]); // represents 'C' in the file. |
304 Expect.equals(111, buffer[4]); // represents 'o' in the file. | 304 Expect.equals(111, buffer[4]); // represents 'o' in the file. |
305 Expect.equals(112, buffer[5]); // represents 'p' in the file. | 305 Expect.equals(112, buffer[5]); // represents 'p' in the file. |
306 Expect.equals(121, buffer[6]); // represents 'y' in the file. | 306 Expect.equals(121, buffer[6]); // represents 'y' in the file. |
307 Expect.equals(114, buffer[7]); // represents 'r' in the file. | 307 Expect.equals(114, buffer[7]); // represents 'r' in the file. |
308 Expect.equals(105, buffer[8]); // represents 'i' in the file. | 308 Expect.equals(105, buffer[8]); // represents 'i' in the file. |
309 Expect.equals(103, buffer[9]); // represents 'g' in the file. | 309 Expect.equals(103, buffer[9]); // represents 'g' in the file. |
310 file.close().then((ignore) => port.close()); | 310 file.close().then((ignore) => port.close()); |
311 }); | 311 }); |
312 }); | 312 }); |
313 }); | 313 }); |
314 } | 314 } |
315 | 315 |
316 static void testReadSync() { | 316 static void testReadSync() { |
317 // Read a file and check part of it's contents. | 317 // Read a file and check part of it's contents. |
318 String filename = getFilename("bin/file_test.cc"); | 318 String filename = getFilename("bin/file_test.cc"); |
319 RandomAccessFile file = (new File(filename)).openSync(); | 319 RandomAccessFile file = (new File(filename)).openSync(); |
320 List<int> buffer = new List<int>(42); | 320 List<int> buffer = new List<int>.fixedLength(42); |
321 int bytes_read = 0; | 321 int bytes_read = 0; |
322 bytes_read = file.readListSync(buffer, 0, 12); | 322 bytes_read = file.readListSync(buffer, 0, 12); |
323 Expect.equals(12, bytes_read); | 323 Expect.equals(12, bytes_read); |
324 bytes_read = file.readListSync(buffer, 12, 30); | 324 bytes_read = file.readListSync(buffer, 12, 30); |
325 Expect.equals(30, bytes_read); | 325 Expect.equals(30, bytes_read); |
326 Expect.equals(47, buffer[0]); // represents '/' in the file. | 326 Expect.equals(47, buffer[0]); // represents '/' in the file. |
327 Expect.equals(47, buffer[1]); // represents '/' in the file. | 327 Expect.equals(47, buffer[1]); // represents '/' in the file. |
328 Expect.equals(32, buffer[2]); // represents ' ' in the file. | 328 Expect.equals(32, buffer[2]); // represents ' ' in the file. |
329 Expect.equals(67, buffer[3]); // represents 'C' in the file. | 329 Expect.equals(67, buffer[3]); // represents 'C' in the file. |
330 Expect.equals(111, buffer[4]); // represents 'o' in the file. | 330 Expect.equals(111, buffer[4]); // represents 'o' in the file. |
331 Expect.equals(112, buffer[5]); // represents 'p' in the file. | 331 Expect.equals(112, buffer[5]); // represents 'p' in the file. |
332 Expect.equals(121, buffer[6]); // represents 'y' in the file. | 332 Expect.equals(121, buffer[6]); // represents 'y' in the file. |
333 Expect.equals(114, buffer[7]); // represents 'r' in the file. | 333 Expect.equals(114, buffer[7]); // represents 'r' in the file. |
334 Expect.equals(105, buffer[8]); // represents 'i' in the file. | 334 Expect.equals(105, buffer[8]); // represents 'i' in the file. |
335 Expect.equals(103, buffer[9]); // represents 'g' in the file. | 335 Expect.equals(103, buffer[9]); // represents 'g' in the file. |
336 Expect.equals(104, buffer[10]); // represents 'h' in the file. | 336 Expect.equals(104, buffer[10]); // represents 'h' in the file. |
337 Expect.equals(116, buffer[11]); // represents 't' in the file. | 337 Expect.equals(116, buffer[11]); // represents 't' in the file. |
338 } | 338 } |
339 | 339 |
340 // Test for file read and write functionality. | 340 // Test for file read and write functionality. |
341 static void testReadWrite() { | 341 static void testReadWrite() { |
342 // Read a file. | 342 // Read a file. |
343 String inFilename = getFilename("tests/vm/data/fixed_length_file"); | 343 String inFilename = getFilename("tests/vm/data/fixed_length_file"); |
344 final File file = new File(inFilename); | 344 final File file = new File(inFilename); |
345 file.open(FileMode.READ).then((openedFile) { | 345 file.open(FileMode.READ).then((openedFile) { |
346 List<int> buffer1 = new List<int>(42); | 346 List<int> buffer1 = new List<int>.fixedLength(42); |
347 openedFile.readList(buffer1, 0, 42).then((bytes_read) { | 347 openedFile.readList(buffer1, 0, 42).then((bytes_read) { |
348 Expect.equals(42, bytes_read); | 348 Expect.equals(42, bytes_read); |
349 openedFile.close().then((ignore) { | 349 openedFile.close().then((ignore) { |
350 // Write the contents of the file just read into another file. | 350 // Write the contents of the file just read into another file. |
351 String outFilename = tempDirectory.path.concat("/out_read_write"); | 351 String outFilename = tempDirectory.path.concat("/out_read_write"); |
352 final File file2 = new File(outFilename); | 352 final File file2 = new File(outFilename); |
353 file2.create().then((ignore) { | 353 file2.create().then((ignore) { |
354 file2.fullPath().then((s) { | 354 file2.fullPath().then((s) { |
355 Expect.isTrue(new File(s).existsSync()); | 355 Expect.isTrue(new File(s).existsSync()); |
356 if (s[0] != '/' && s[0] != '\\' && s[1] != ':') { | 356 if (s[0] != '/' && s[0] != '\\' && s[1] != ':') { |
357 Expect.fail("Not a full path"); | 357 Expect.fail("Not a full path"); |
358 } | 358 } |
359 file2.open(FileMode.WRITE).then((openedFile2) { | 359 file2.open(FileMode.WRITE).then((openedFile2) { |
360 openedFile2.writeList(buffer1, 0, bytes_read).then((ignore) { | 360 openedFile2.writeList(buffer1, 0, bytes_read).then((ignore) { |
361 openedFile2.close().then((ignore) { | 361 openedFile2.close().then((ignore) { |
362 List<int> buffer2 = new List<int>(bytes_read); | 362 List<int> buffer2 = new List<int>.fixedLength(bytes_read); |
363 final File file3 = new File(outFilename); | 363 final File file3 = new File(outFilename); |
364 file3.open(FileMode.READ).then((openedFile3) { | 364 file3.open(FileMode.READ).then((openedFile3) { |
365 openedFile3.readList(buffer2, 0, 42).then((bytes_read) { | 365 openedFile3.readList(buffer2, 0, 42).then((bytes_read) { |
366 Expect.equals(42, bytes_read); | 366 Expect.equals(42, bytes_read); |
367 openedFile3.close().then((ignore) { | 367 openedFile3.close().then((ignore) { |
368 // Now compare the two buffers to check if they | 368 // Now compare the two buffers to check if they |
369 // are identical. | 369 // are identical. |
370 Expect.equals(buffer1.length, buffer2.length); | 370 Expect.equals(buffer1.length, buffer2.length); |
371 for (int i = 0; i < buffer1.length; i++) { | 371 for (int i = 0; i < buffer1.length; i++) { |
372 Expect.equals(buffer1[i], buffer2[i]); | 372 Expect.equals(buffer1[i], buffer2[i]); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 }; | 477 }; |
478 }; | 478 }; |
479 asyncTestStarted(); | 479 asyncTestStarted(); |
480 } | 480 } |
481 | 481 |
482 | 482 |
483 static void testReadWriteSync() { | 483 static void testReadWriteSync() { |
484 // Read a file. | 484 // Read a file. |
485 String inFilename = getFilename("tests/vm/data/fixed_length_file"); | 485 String inFilename = getFilename("tests/vm/data/fixed_length_file"); |
486 RandomAccessFile file = (new File(inFilename)).openSync(); | 486 RandomAccessFile file = (new File(inFilename)).openSync(); |
487 List<int> buffer1 = new List<int>(42); | 487 List<int> buffer1 = new List<int>.fixedLength(42); |
488 int bytes_read = 0; | 488 int bytes_read = 0; |
489 int bytes_written = 0; | 489 int bytes_written = 0; |
490 bytes_read = file.readListSync(buffer1, 0, 42); | 490 bytes_read = file.readListSync(buffer1, 0, 42); |
491 Expect.equals(42, bytes_read); | 491 Expect.equals(42, bytes_read); |
492 file.closeSync(); | 492 file.closeSync(); |
493 // Write the contents of the file just read into another file. | 493 // Write the contents of the file just read into another file. |
494 String outFilename = tempDirectory.path.concat("/out_read_write_sync"); | 494 String outFilename = tempDirectory.path.concat("/out_read_write_sync"); |
495 File outFile = new File(outFilename); | 495 File outFile = new File(outFilename); |
496 outFile.createSync(); | 496 outFile.createSync(); |
497 String path = outFile.fullPathSync(); | 497 String path = outFile.fullPathSync(); |
498 if (path[0] != '/' && path[0] != '\\' && path[1] != ':') { | 498 if (path[0] != '/' && path[0] != '\\' && path[1] != ':') { |
499 Expect.fail("Not a full path"); | 499 Expect.fail("Not a full path"); |
500 } | 500 } |
501 Expect.isTrue(new File(path).existsSync()); | 501 Expect.isTrue(new File(path).existsSync()); |
502 RandomAccessFile openedFile = outFile.openSync(FileMode.WRITE); | 502 RandomAccessFile openedFile = outFile.openSync(FileMode.WRITE); |
503 openedFile.writeListSync(buffer1, 0, bytes_read); | 503 openedFile.writeListSync(buffer1, 0, bytes_read); |
504 openedFile.closeSync(); | 504 openedFile.closeSync(); |
505 // Now read the contents of the file just written. | 505 // Now read the contents of the file just written. |
506 List<int> buffer2 = new List<int>(bytes_read); | 506 List<int> buffer2 = new List<int>.fixedLength(bytes_read); |
507 openedFile = (new File(outFilename)).openSync(); | 507 openedFile = (new File(outFilename)).openSync(); |
508 bytes_read = openedFile.readListSync(buffer2, 0, 42); | 508 bytes_read = openedFile.readListSync(buffer2, 0, 42); |
509 Expect.equals(42, bytes_read); | 509 Expect.equals(42, bytes_read); |
510 openedFile.closeSync(); | 510 openedFile.closeSync(); |
511 // Now compare the two buffers to check if they are identical. | 511 // Now compare the two buffers to check if they are identical. |
512 Expect.equals(buffer1.length, buffer2.length); | 512 Expect.equals(buffer1.length, buffer2.length); |
513 for (int i = 0; i < buffer1.length; i++) { | 513 for (int i = 0; i < buffer1.length; i++) { |
514 Expect.equals(buffer1[i], buffer2[i]); | 514 Expect.equals(buffer1[i], buffer2[i]); |
515 } | 515 } |
516 // Delete the output file. | 516 // Delete the output file. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 openedFile.writeList(new MyListOfOneElement(262), 0, 1); | 564 openedFile.writeList(new MyListOfOneElement(262), 0, 1); |
565 x = 12345678901234567890123456789012345678901234567890; | 565 x = 12345678901234567890123456789012345678901234567890; |
566 y = 12345678901234567890123456789012345678901234568153; | 566 y = 12345678901234567890123456789012345678901234568153; |
567 openedFile.writeList([y - x], 0, 1).then((ignore) { | 567 openedFile.writeList([y - x], 0, 1).then((ignore) { |
568 openedFile.close().then((ignore) { | 568 openedFile.close().then((ignore) { |
569 // Check the written bytes. | 569 // Check the written bytes. |
570 final File file2 = new File(fileName); | 570 final File file2 = new File(fileName); |
571 var openedFile2 = file2.openSync(); | 571 var openedFile2 = file2.openSync(); |
572 var length = openedFile2.lengthSync(); | 572 var length = openedFile2.lengthSync(); |
573 Expect.equals(8, length); | 573 Expect.equals(8, length); |
574 List data = new List(length); | 574 List data = new List.fixedLength(length); |
575 openedFile2.readListSync(data, 0, length); | 575 openedFile2.readListSync(data, 0, length); |
576 for (var i = 0; i < data.length; i++) { | 576 for (var i = 0; i < data.length; i++) { |
577 Expect.equals(i, data[i]); | 577 Expect.equals(i, data[i]); |
578 } | 578 } |
579 openedFile2.closeSync(); | 579 openedFile2.closeSync(); |
580 file2.deleteSync(); | 580 file2.deleteSync(); |
581 asyncTestDone("testWriteVariousLists"); | 581 asyncTestDone("testWriteVariousLists"); |
582 }); | 582 }); |
583 }); | 583 }); |
584 }); | 584 }); |
585 }); | 585 }); |
586 } | 586 } |
587 | 587 |
588 static void testDirectory() { | 588 static void testDirectory() { |
589 asyncTestStarted(); | 589 asyncTestStarted(); |
590 | 590 |
591 // Port to verify that the test completes. | 591 // Port to verify that the test completes. |
592 var port = new ReceivePort(); | 592 var port = new ReceivePort(); |
593 port.receive((message, replyTo) { | 593 port.receive((message, replyTo) { |
594 port.close(); | 594 port.close(); |
595 Expect.equals(1, message); | 595 Expect.equals(1, message); |
596 asyncTestDone("testDirectory"); | 596 asyncTestDone("testDirectory"); |
597 }); | 597 }); |
598 | 598 |
599 var tempDir = tempDirectory.path; | 599 var tempDir = tempDirectory.path; |
600 var file = new File("${tempDir}/testDirectory"); | 600 var file = new File("${tempDir}/testDirectory"); |
601 var errors = 0; | 601 var errors = 0; |
602 var dirFuture = file.directory(); | 602 var dirFuture = file.directory(); |
603 dirFuture.then((d) => Expect.fail("non-existing file")); | 603 dirFuture.then((d) => Expect.fail("non-existing file")) |
604 dirFuture.handleException((e) { | 604 .catchError((e) { |
605 file.create().then((ignore) { | 605 file.create().then((ignore) { |
606 file.directory().then((Directory d) { | 606 file.directory().then((Directory d) { |
607 d.exists().then((exists) { | 607 d.exists().then((exists) { |
608 Expect.isTrue(exists); | 608 Expect.isTrue(exists); |
609 Expect.isTrue(d.path.endsWith(tempDir)); | 609 Expect.isTrue(d.path.endsWith(tempDir)); |
610 file.delete().then((ignore) { | 610 file.delete().then((ignore) { |
611 var fileDir = new File("."); | 611 var fileDir = new File("."); |
612 var dirFuture2 = fileDir.directory(); | 612 var dirFuture2 = fileDir.directory(); |
613 dirFuture2.then((d) => Expect.fail("non-existing file")); | 613 dirFuture2.then((d) => Expect.fail("non-existing file")) |
614 dirFuture2.handleException((e) { | 614 .catchError((e) { |
615 var fileDir = new File(tempDir); | 615 var fileDir = new File(tempDir); |
616 var dirFuture3 = fileDir.directory(); | 616 var dirFuture3 = fileDir.directory(); |
617 dirFuture3.then((d) => Expect.fail("non-existing file")); | 617 dirFuture3.then((d) => Expect.fail("non-existing file")) |
618 dirFuture3.handleException((e) { | 618 .catchError((e) { |
619 port.toSendPort().send(1); | 619 port.toSendPort().send(1); |
620 return true; | |
621 }); | 620 }); |
622 return true; | |
623 }); | 621 }); |
624 }); | 622 }); |
625 }); | 623 }); |
626 }); | 624 }); |
627 }); | 625 }); |
628 return true; | |
629 }); | 626 }); |
630 } | 627 } |
631 | 628 |
632 static void testDirectorySync() { | 629 static void testDirectorySync() { |
633 var tempDir = tempDirectory.path; | 630 var tempDir = tempDirectory.path; |
634 var file = new File("${tempDir}/testDirectorySync"); | 631 var file = new File("${tempDir}/testDirectorySync"); |
635 // Non-existing file should throw exception. | 632 // Non-existing file should throw exception. |
636 Expect.throws(file.directorySync, (e) { return e is FileIOException; }); | 633 Expect.throws(file.directorySync, (e) { return e is FileIOException; }); |
637 file.createSync(); | 634 file.createSync(); |
638 // Check that the path of the returned directory is the temp directory. | 635 // Check that the path of the returned directory is the temp directory. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 openedFile.closeSync(); | 668 openedFile.closeSync(); |
672 } | 669 } |
673 | 670 |
674 // Test for file position functionality. | 671 // Test for file position functionality. |
675 static void testPosition() { | 672 static void testPosition() { |
676 var port = new ReceivePort(); | 673 var port = new ReceivePort(); |
677 String filename = getFilename("tests/vm/data/fixed_length_file"); | 674 String filename = getFilename("tests/vm/data/fixed_length_file"); |
678 RandomAccessFile input = (new File(filename)).openSync(); | 675 RandomAccessFile input = (new File(filename)).openSync(); |
679 input.position().then((position) { | 676 input.position().then((position) { |
680 Expect.equals(0, position); | 677 Expect.equals(0, position); |
681 List<int> buffer = new List<int>(100); | 678 List<int> buffer = new List<int>.fixedLength(100); |
682 input.readList(buffer, 0, 12).then((bytes_read) { | 679 input.readList(buffer, 0, 12).then((bytes_read) { |
683 input.position().then((position) { | 680 input.position().then((position) { |
684 Expect.equals(12, position); | 681 Expect.equals(12, position); |
685 input.readList(buffer, 12, 6).then((bytes_read) { | 682 input.readList(buffer, 12, 6).then((bytes_read) { |
686 input.position().then((position) { | 683 input.position().then((position) { |
687 Expect.equals(18, position); | 684 Expect.equals(18, position); |
688 input.setPosition(8).then((ignore) { | 685 input.setPosition(8).then((ignore) { |
689 input.position().then((position) { | 686 input.position().then((position) { |
690 Expect.equals(8, position); | 687 Expect.equals(8, position); |
691 input.close().then((ignore) => port.close()); | 688 input.close().then((ignore) => port.close()); |
692 }); | 689 }); |
693 }); | 690 }); |
694 }); | 691 }); |
695 }); | 692 }); |
696 }); | 693 }); |
697 }); | 694 }); |
698 }); | 695 }); |
699 } | 696 } |
700 | 697 |
701 static void testPositionSync() { | 698 static void testPositionSync() { |
702 String filename = getFilename("tests/vm/data/fixed_length_file"); | 699 String filename = getFilename("tests/vm/data/fixed_length_file"); |
703 RandomAccessFile input = (new File(filename)).openSync(); | 700 RandomAccessFile input = (new File(filename)).openSync(); |
704 Expect.equals(0, input.positionSync()); | 701 Expect.equals(0, input.positionSync()); |
705 List<int> buffer = new List<int>(100); | 702 List<int> buffer = new List<int>.fixedLength(100); |
706 input.readListSync(buffer, 0, 12); | 703 input.readListSync(buffer, 0, 12); |
707 Expect.equals(12, input.positionSync()); | 704 Expect.equals(12, input.positionSync()); |
708 input.readListSync(buffer, 12, 6); | 705 input.readListSync(buffer, 12, 6); |
709 Expect.equals(18, input.positionSync()); | 706 Expect.equals(18, input.positionSync()); |
710 input.setPositionSync(8); | 707 input.setPositionSync(8); |
711 Expect.equals(8, input.positionSync()); | 708 Expect.equals(8, input.positionSync()); |
712 input.closeSync(); | 709 input.closeSync(); |
713 } | 710 } |
714 | 711 |
715 static void testTruncate() { | 712 static void testTruncate() { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 openedFile.writeStringSync("Test"); | 779 openedFile.writeStringSync("Test"); |
783 } on FileIOException catch (ex) { | 780 } on FileIOException catch (ex) { |
784 exceptionCaught = true; | 781 exceptionCaught = true; |
785 } on Exception catch (ex) { | 782 } on Exception catch (ex) { |
786 wrongExceptionCaught = true; | 783 wrongExceptionCaught = true; |
787 } | 784 } |
788 Expect.equals(true, exceptionCaught); | 785 Expect.equals(true, exceptionCaught); |
789 Expect.equals(true, !wrongExceptionCaught); | 786 Expect.equals(true, !wrongExceptionCaught); |
790 exceptionCaught = false; | 787 exceptionCaught = false; |
791 try { | 788 try { |
792 List<int> buffer = new List<int>(100); | 789 List<int> buffer = new List<int>.fixedLength(100); |
793 openedFile.readListSync(buffer, 0, 10); | 790 openedFile.readListSync(buffer, 0, 10); |
794 } on FileIOException catch (ex) { | 791 } on FileIOException catch (ex) { |
795 exceptionCaught = true; | 792 exceptionCaught = true; |
796 } on Exception catch (ex) { | 793 } on Exception catch (ex) { |
797 wrongExceptionCaught = true; | 794 wrongExceptionCaught = true; |
798 } | 795 } |
799 Expect.equals(true, exceptionCaught); | 796 Expect.equals(true, exceptionCaught); |
800 Expect.equals(true, !wrongExceptionCaught); | 797 Expect.equals(true, !wrongExceptionCaught); |
801 exceptionCaught = false; | 798 exceptionCaught = false; |
802 try { | 799 try { |
803 List<int> buffer = new List<int>(100); | 800 List<int> buffer = new List<int>.fixedLength(100); |
804 openedFile.writeListSync(buffer, 0, 10); | 801 openedFile.writeListSync(buffer, 0, 10); |
805 } on FileIOException catch (ex) { | 802 } on FileIOException catch (ex) { |
806 exceptionCaught = true; | 803 exceptionCaught = true; |
807 } on Exception catch (ex) { | 804 } on Exception catch (ex) { |
808 wrongExceptionCaught = true; | 805 wrongExceptionCaught = true; |
809 } | 806 } |
810 Expect.equals(true, exceptionCaught); | 807 Expect.equals(true, exceptionCaught); |
811 Expect.equals(true, !wrongExceptionCaught); | 808 Expect.equals(true, !wrongExceptionCaught); |
812 exceptionCaught = false; | 809 exceptionCaught = false; |
813 try { | 810 try { |
(...skipping 24 matching lines...) Expand all Loading... |
838 wrongExceptionCaught = true; | 835 wrongExceptionCaught = true; |
839 } | 836 } |
840 Expect.equals(true, exceptionCaught); | 837 Expect.equals(true, exceptionCaught); |
841 Expect.equals(true, !wrongExceptionCaught); | 838 Expect.equals(true, !wrongExceptionCaught); |
842 input.deleteSync(); | 839 input.deleteSync(); |
843 } | 840 } |
844 | 841 |
845 // Tests stream exception handling after file was closed. | 842 // Tests stream exception handling after file was closed. |
846 static void testCloseExceptionStream() { | 843 static void testCloseExceptionStream() { |
847 asyncTestStarted(); | 844 asyncTestStarted(); |
848 List<int> buffer = new List<int>(42); | 845 List<int> buffer = new List<int>.fixedLength(42); |
849 File file = | 846 File file = |
850 new File(tempDirectory.path.concat("/out_close_exception_stream")); | 847 new File(tempDirectory.path.concat("/out_close_exception_stream")); |
851 file.createSync(); | 848 file.createSync(); |
852 InputStream input = file.openInputStream(); | 849 InputStream input = file.openInputStream(); |
853 input.onClosed = () { | 850 input.onClosed = () { |
854 Expect.isTrue(input.closed); | 851 Expect.isTrue(input.closed); |
855 Expect.equals(0, input.readInto(buffer, 0, 12)); | 852 Expect.equals(0, input.readInto(buffer, 0, 12)); |
856 OutputStream output = file.openOutputStream(); | 853 OutputStream output = file.openOutputStream(); |
857 output.close(); | 854 output.close(); |
858 Expect.throws(() => output.writeFrom(buffer, 0, 12)); | 855 Expect.throws(() => output.writeFrom(buffer, 0, 12)); |
859 output.onClosed = () { | 856 output.onClosed = () { |
860 file.deleteSync(); | 857 file.deleteSync(); |
861 asyncTestDone("testCloseExceptionStream"); | 858 asyncTestDone("testCloseExceptionStream"); |
862 }; | 859 }; |
863 }; | 860 }; |
864 } | 861 } |
865 | 862 |
866 // Tests buffer out of bounds exception. | 863 // Tests buffer out of bounds exception. |
867 static void testBufferOutOfBoundsException() { | 864 static void testBufferOutOfBoundsException() { |
868 bool exceptionCaught = false; | 865 bool exceptionCaught = false; |
869 bool wrongExceptionCaught = false; | 866 bool wrongExceptionCaught = false; |
870 File file = | 867 File file = |
871 new File(tempDirectory.path.concat("/out_buffer_out_of_bounds")); | 868 new File(tempDirectory.path.concat("/out_buffer_out_of_bounds")); |
872 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); | 869 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); |
873 try { | 870 try { |
874 List<int> buffer = new List<int>(10); | 871 List<int> buffer = new List<int>.fixedLength(10); |
875 openedFile.readListSync(buffer, 0, 12); | 872 openedFile.readListSync(buffer, 0, 12); |
876 } on RangeError catch (ex) { | 873 } on RangeError catch (ex) { |
877 exceptionCaught = true; | 874 exceptionCaught = true; |
878 } on Exception catch (ex) { | 875 } on Exception catch (ex) { |
879 wrongExceptionCaught = true; | 876 wrongExceptionCaught = true; |
880 } | 877 } |
881 Expect.equals(true, exceptionCaught); | 878 Expect.equals(true, exceptionCaught); |
882 Expect.equals(true, !wrongExceptionCaught); | 879 Expect.equals(true, !wrongExceptionCaught); |
883 exceptionCaught = false; | 880 exceptionCaught = false; |
884 try { | 881 try { |
885 List<int> buffer = new List<int>(10); | 882 List<int> buffer = new List<int>.fixedLength(10); |
886 openedFile.readListSync(buffer, 6, 6); | 883 openedFile.readListSync(buffer, 6, 6); |
887 } on RangeError catch (ex) { | 884 } on RangeError catch (ex) { |
888 exceptionCaught = true; | 885 exceptionCaught = true; |
889 } on Exception catch (ex) { | 886 } on Exception catch (ex) { |
890 wrongExceptionCaught = true; | 887 wrongExceptionCaught = true; |
891 } | 888 } |
892 Expect.equals(true, exceptionCaught); | 889 Expect.equals(true, exceptionCaught); |
893 Expect.equals(true, !wrongExceptionCaught); | 890 Expect.equals(true, !wrongExceptionCaught); |
894 exceptionCaught = false; | 891 exceptionCaught = false; |
895 try { | 892 try { |
896 List<int> buffer = new List<int>(10); | 893 List<int> buffer = new List<int>.fixedLength(10); |
897 openedFile.readListSync(buffer, -1, 1); | 894 openedFile.readListSync(buffer, -1, 1); |
898 } on RangeError catch (ex) { | 895 } on RangeError catch (ex) { |
899 exceptionCaught = true; | 896 exceptionCaught = true; |
900 } on Exception catch (ex) { | 897 } on Exception catch (ex) { |
901 wrongExceptionCaught = true; | 898 wrongExceptionCaught = true; |
902 } | 899 } |
903 Expect.equals(true, exceptionCaught); | 900 Expect.equals(true, exceptionCaught); |
904 Expect.equals(true, !wrongExceptionCaught); | 901 Expect.equals(true, !wrongExceptionCaught); |
905 exceptionCaught = false; | 902 exceptionCaught = false; |
906 try { | 903 try { |
907 List<int> buffer = new List<int>(10); | 904 List<int> buffer = new List<int>.fixedLength(10); |
908 openedFile.readListSync(buffer, 0, -1); | 905 openedFile.readListSync(buffer, 0, -1); |
909 } on RangeError catch (ex) { | 906 } on RangeError catch (ex) { |
910 exceptionCaught = true; | 907 exceptionCaught = true; |
911 } on Exception catch (ex) { | 908 } on Exception catch (ex) { |
912 wrongExceptionCaught = true; | 909 wrongExceptionCaught = true; |
913 } | 910 } |
914 Expect.equals(true, exceptionCaught); | 911 Expect.equals(true, exceptionCaught); |
915 Expect.equals(true, !wrongExceptionCaught); | 912 Expect.equals(true, !wrongExceptionCaught); |
916 exceptionCaught = false; | 913 exceptionCaught = false; |
917 try { | 914 try { |
918 List<int> buffer = new List<int>(10); | 915 List<int> buffer = new List<int>.fixedLength(10); |
919 openedFile.writeListSync(buffer, 0, 12); | 916 openedFile.writeListSync(buffer, 0, 12); |
920 } on RangeError catch (ex) { | 917 } on RangeError catch (ex) { |
921 exceptionCaught = true; | 918 exceptionCaught = true; |
922 } on Exception catch (ex) { | 919 } on Exception catch (ex) { |
923 wrongExceptionCaught = true; | 920 wrongExceptionCaught = true; |
924 } | 921 } |
925 Expect.equals(true, exceptionCaught); | 922 Expect.equals(true, exceptionCaught); |
926 Expect.equals(true, !wrongExceptionCaught); | 923 Expect.equals(true, !wrongExceptionCaught); |
927 exceptionCaught = false; | 924 exceptionCaught = false; |
928 try { | 925 try { |
929 List<int> buffer = new List<int>(10); | 926 List<int> buffer = new List<int>.fixedLength(10); |
930 openedFile.writeListSync(buffer, 6, 6); | 927 openedFile.writeListSync(buffer, 6, 6); |
931 } on RangeError catch (ex) { | 928 } on RangeError catch (ex) { |
932 exceptionCaught = true; | 929 exceptionCaught = true; |
933 } on Exception catch (ex) { | 930 } on Exception catch (ex) { |
934 wrongExceptionCaught = true; | 931 wrongExceptionCaught = true; |
935 } | 932 } |
936 Expect.equals(true, exceptionCaught); | 933 Expect.equals(true, exceptionCaught); |
937 Expect.equals(true, !wrongExceptionCaught); | 934 Expect.equals(true, !wrongExceptionCaught); |
938 exceptionCaught = false; | 935 exceptionCaught = false; |
939 try { | 936 try { |
940 List<int> buffer = new List<int>(10); | 937 List<int> buffer = new List<int>.fixedLength(10); |
941 openedFile.writeListSync(buffer, -1, 1); | 938 openedFile.writeListSync(buffer, -1, 1); |
942 } on RangeError catch (ex) { | 939 } on RangeError catch (ex) { |
943 exceptionCaught = true; | 940 exceptionCaught = true; |
944 } on Exception catch (ex) { | 941 } on Exception catch (ex) { |
945 wrongExceptionCaught = true; | 942 wrongExceptionCaught = true; |
946 } | 943 } |
947 Expect.equals(true, exceptionCaught); | 944 Expect.equals(true, exceptionCaught); |
948 Expect.equals(true, !wrongExceptionCaught); | 945 Expect.equals(true, !wrongExceptionCaught); |
949 exceptionCaught = false; | 946 exceptionCaught = false; |
950 try { | 947 try { |
951 List<int> buffer = new List<int>(10); | 948 List<int> buffer = new List<int>.fixedLength(10); |
952 openedFile.writeListSync(buffer, 0, -1); | 949 openedFile.writeListSync(buffer, 0, -1); |
953 } on RangeError catch (ex) { | 950 } on RangeError catch (ex) { |
954 exceptionCaught = true; | 951 exceptionCaught = true; |
955 } on Exception catch (ex) { | 952 } on Exception catch (ex) { |
956 wrongExceptionCaught = true; | 953 wrongExceptionCaught = true; |
957 } | 954 } |
958 Expect.equals(true, exceptionCaught); | 955 Expect.equals(true, exceptionCaught); |
959 Expect.equals(true, !wrongExceptionCaught); | 956 Expect.equals(true, !wrongExceptionCaught); |
960 openedFile.closeSync(); | 957 openedFile.closeSync(); |
961 file.deleteSync(); | 958 file.deleteSync(); |
962 } | 959 } |
963 | 960 |
964 static void testOpenDirectoryAsFile() { | 961 static void testOpenDirectoryAsFile() { |
965 var f = new File('.'); | 962 var f = new File('.'); |
966 var future = f.open(FileMode.READ); | 963 var future = f.open(FileMode.READ); |
967 future.then((r) => Expect.fail('Directory opened as file')); | 964 future.then((r) => Expect.fail('Directory opened as file')) |
968 future.handleException((e) => true); | 965 .catchError((e) {}); |
969 } | 966 } |
970 | 967 |
971 static void testOpenDirectoryAsFileSync() { | 968 static void testOpenDirectoryAsFileSync() { |
972 var f = new File('.'); | 969 var f = new File('.'); |
973 try { | 970 try { |
974 f.openSync(); | 971 f.openSync(); |
975 Expect.fail("Expected exception opening directory as file"); | 972 Expect.fail("Expected exception opening directory as file"); |
976 } catch (e) { | 973 } catch (e) { |
977 Expect.isTrue(e is FileIOException); | 974 Expect.isTrue(e is FileIOException); |
978 } | 975 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 Expect.equals(6, text.length); | 1044 Expect.equals(6, text.length); |
1048 var expected = [955, 120, 46, 32, 120, 10]; | 1045 var expected = [955, 120, 46, 32, 120, 10]; |
1049 Expect.listEquals(expected, text.charCodes); | 1046 Expect.listEquals(expected, text.charCodes); |
1050 f.readAsString(Encoding.ISO_8859_1).then((text) { | 1047 f.readAsString(Encoding.ISO_8859_1).then((text) { |
1051 Expect.equals(7, text.length); | 1048 Expect.equals(7, text.length); |
1052 var expected = [206, 187, 120, 46, 32, 120, 10]; | 1049 var expected = [206, 187, 120, 46, 32, 120, 10]; |
1053 Expect.listEquals(expected, text.charCodes); | 1050 Expect.listEquals(expected, text.charCodes); |
1054 var readAsStringFuture = f.readAsString(Encoding.ASCII); | 1051 var readAsStringFuture = f.readAsString(Encoding.ASCII); |
1055 readAsStringFuture.then((text) { | 1052 readAsStringFuture.then((text) { |
1056 Expect.fail("Non-ascii char should cause error"); | 1053 Expect.fail("Non-ascii char should cause error"); |
1057 }); | 1054 }).catchError((e) { |
1058 readAsStringFuture.handleException((e) { | |
1059 port.toSendPort().send(1); | 1055 port.toSendPort().send(1); |
1060 return true; | |
1061 }); | 1056 }); |
1062 }); | 1057 }); |
1063 }); | 1058 }); |
1064 }); | 1059 }); |
1065 } | 1060 } |
1066 | 1061 |
1067 static void testReadAsTextEmptyFile() { | 1062 static void testReadAsTextEmptyFile() { |
1068 var port = new ReceivePort(); | 1063 var port = new ReceivePort(); |
1069 port.receive((result, replyTo) { | 1064 port.receive((result, replyTo) { |
1070 port.close(); | 1065 port.close(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 var port = new ReceivePort(); | 1129 var port = new ReceivePort(); |
1135 port.receive((message, _) { | 1130 port.receive((message, _) { |
1136 port.close(); | 1131 port.close(); |
1137 Expect.equals(1, message); | 1132 Expect.equals(1, message); |
1138 }); | 1133 }); |
1139 var f = new File('.'); | 1134 var f = new File('.'); |
1140 Expect.throws(f.readAsBytesSync, (e) => e is FileIOException); | 1135 Expect.throws(f.readAsBytesSync, (e) => e is FileIOException); |
1141 Expect.throws(f.readAsStringSync, (e) => e is FileIOException); | 1136 Expect.throws(f.readAsStringSync, (e) => e is FileIOException); |
1142 Expect.throws(f.readAsLinesSync, (e) => e is FileIOException); | 1137 Expect.throws(f.readAsLinesSync, (e) => e is FileIOException); |
1143 var readAsBytesFuture = f.readAsBytes(); | 1138 var readAsBytesFuture = f.readAsBytes(); |
1144 readAsBytesFuture.then((bytes) => Expect.fail("no bytes expected")); | 1139 readAsBytesFuture.then((bytes) => Expect.fail("no bytes expected")) |
1145 readAsBytesFuture.handleException((e) { | 1140 .catchError((e) { |
1146 var readAsStringFuture = f.readAsString(Encoding.UTF_8); | 1141 var readAsStringFuture = f.readAsString(Encoding.UTF_8); |
1147 readAsStringFuture.then((text) => Expect.fail("no text expected")); | 1142 readAsStringFuture.then((text) => Expect.fail("no text expected")) |
1148 readAsStringFuture.handleException((e) { | 1143 .catchError((e) { |
1149 var readAsLinesFuture = f.readAsLines(Encoding.UTF_8); | 1144 var readAsLinesFuture = f.readAsLines(Encoding.UTF_8); |
1150 readAsLinesFuture.then((lines) => Expect.fail("no lines expected")); | 1145 readAsLinesFuture.then((lines) => Expect.fail("no lines expected")) |
1151 readAsLinesFuture.handleException((e) { | 1146 .catchError((e) { |
1152 port.toSendPort().send(1); | 1147 port.toSendPort().send(1); |
1153 return true; | |
1154 }); | 1148 }); |
1155 return true; | |
1156 }); | 1149 }); |
1157 return true; | |
1158 }); | 1150 }); |
1159 } | 1151 } |
1160 | 1152 |
1161 static void testLastModified() { | 1153 static void testLastModified() { |
1162 var port = new ReceivePort(); | 1154 var port = new ReceivePort(); |
1163 new File(new Options().executable).lastModified().then((modified) { | 1155 new File(new Options().executable).lastModified().then((modified) { |
1164 Expect.isTrue(modified is Date); | 1156 Expect.isTrue(modified is Date); |
1165 Expect.isTrue(modified < new Date.now()); | 1157 Expect.isTrue(modified < new Date.now()); |
1166 port.close(); | 1158 port.close(); |
1167 }); | 1159 }); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 testDirectorySync(); | 1321 testDirectorySync(); |
1330 testWriteStringUtf8(); | 1322 testWriteStringUtf8(); |
1331 testWriteStringUtf8Sync(); | 1323 testWriteStringUtf8Sync(); |
1332 }); | 1324 }); |
1333 } | 1325 } |
1334 } | 1326 } |
1335 | 1327 |
1336 main() { | 1328 main() { |
1337 FileTest.testMain(); | 1329 FileTest.testMain(); |
1338 } | 1330 } |
OLD | NEW |