OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 | 7 |
8 class FileTest { | 8 class FileTest { |
9 static Directory tempDirectory; | 9 static Directory tempDirectory; |
10 static int numLiveAsyncTests = 0; | 10 static int numLiveAsyncTests = 0; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 Expect.equals(buffer1.length, buffer2.length); | 258 Expect.equals(buffer1.length, buffer2.length); |
259 for (int i = 0; i < buffer1.length; i++) { | 259 for (int i = 0; i < buffer1.length; i++) { |
260 Expect.equals(buffer1[i], buffer2[i]); | 260 Expect.equals(buffer1[i], buffer2[i]); |
261 } | 261 } |
262 // Delete the output file. | 262 // Delete the output file. |
263 outFile.deleteSync(); | 263 outFile.deleteSync(); |
264 Expect.isFalse(outFile.existsSync()); | 264 Expect.isFalse(outFile.existsSync()); |
265 return 1; | 265 return 1; |
266 } | 266 } |
267 | 267 |
| 268 static int testReadEmptyFileSync() { |
| 269 String fileName = tempDirectory.path + "/empty_file_sync"; |
| 270 File file = new File(fileName); |
| 271 file.createSync(); |
| 272 RandomAccessFile openedFile = file.openSync(); |
| 273 Expect.throws(() => openedFile.readByteSync(), (e) => e is FileIOException); |
| 274 return 1; |
| 275 } |
| 276 |
| 277 static int testReadEmptyFile() { |
| 278 String fileName = tempDirectory.path + "/empty_file"; |
| 279 File file = new File(fileName); |
| 280 file.createHandler = () { |
| 281 file.openHandler = (RandomAccessFile openedFile) { |
| 282 openedFile.readByteHandler = (int byte) { |
| 283 Expect.fail("Read byte from empty file"); |
| 284 }; |
| 285 openedFile.errorHandler = (String err) { |
| 286 Expect.isTrue(err.indexOf("failed") != -1); |
| 287 }; |
| 288 openedFile.readByte(); |
| 289 }; |
| 290 file.open(); |
| 291 }; |
| 292 asyncTestStarted(); |
| 293 file.create(); |
| 294 return 1; |
| 295 } |
| 296 |
268 // Test for file length functionality. | 297 // Test for file length functionality. |
269 static int testLength() { | 298 static int testLength() { |
270 String filename = getFilename("tests/vm/data/fixed_length_file"); | 299 String filename = getFilename("tests/vm/data/fixed_length_file"); |
271 RandomAccessFile input = (new File(filename)).openSync(); | 300 RandomAccessFile input = (new File(filename)).openSync(); |
272 input.errorHandler = (s) { | 301 input.errorHandler = (s) { |
273 Expect.fail("No errors expected"); | 302 Expect.fail("No errors expected"); |
274 }; | 303 }; |
275 input.lengthHandler = (length) { | 304 input.lengthHandler = (length) { |
276 Expect.equals(42, length); | 305 Expect.equals(42, length); |
277 input.close(); | 306 input.close(); |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 Expect.equals(1, testLength()); | 658 Expect.equals(1, testLength()); |
630 Expect.equals(1, testLengthSync()); | 659 Expect.equals(1, testLengthSync()); |
631 Expect.equals(1, testPosition()); | 660 Expect.equals(1, testPosition()); |
632 Expect.equals(1, testPositionSync()); | 661 Expect.equals(1, testPositionSync()); |
633 Expect.equals(1, testMixedSyncAndAsync()); | 662 Expect.equals(1, testMixedSyncAndAsync()); |
634 asyncTestStarted(); | 663 asyncTestStarted(); |
635 createTempDirectory(() { | 664 createTempDirectory(() { |
636 Expect.equals(1, testReadWrite()); | 665 Expect.equals(1, testReadWrite()); |
637 Expect.equals(1, testReadWriteSync()); | 666 Expect.equals(1, testReadWriteSync()); |
638 Expect.equals(1, testReadWriteStream()); | 667 Expect.equals(1, testReadWriteStream()); |
| 668 Expect.equals(1, testReadEmptyFileSync()); |
| 669 Expect.equals(1, testReadEmptyFile()); |
639 Expect.equals(1, testTruncate()); | 670 Expect.equals(1, testTruncate()); |
640 Expect.equals(1, testTruncateSync()); | 671 Expect.equals(1, testTruncateSync()); |
641 Expect.equals(1, testCloseException()); | 672 Expect.equals(1, testCloseException()); |
642 Expect.equals(1, testCloseExceptionStream()); | 673 Expect.equals(1, testCloseExceptionStream()); |
643 Expect.equals(1, testBufferOutOfBoundsException()); | 674 Expect.equals(1, testBufferOutOfBoundsException()); |
644 asyncTestDone(); | 675 asyncTestDone(); |
645 }); | 676 }); |
646 } | 677 } |
647 } | 678 } |
648 | 679 |
649 main() { | 680 main() { |
650 FileTest.testMain(); | 681 FileTest.testMain(); |
651 } | 682 } |
OLD | NEW |