Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Side by Side Diff: tests/standalone/src/FileTest.dart

Issue 9416096: Implement File.directory() and File.directorySync() to get (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Implement async version using isolate Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« runtime/bin/file_linux.cc ('K') | « runtime/bin/file_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:io");
8 8
9 class MyListOfOneElement implements List { 9 class MyListOfOneElement implements List {
10 int _value; 10 int _value;
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 openedFile2.closeSync(); 444 openedFile2.closeSync();
445 file2.deleteSync(); 445 file2.deleteSync();
446 }; 446 };
447 }; 447 };
448 file.errorHandler = (s) { 448 file.errorHandler = (s) {
449 Expect.fail("No errors expected : $s"); 449 Expect.fail("No errors expected : $s");
450 }; 450 };
451 }; 451 };
452 } 452 }
453 453
454 static void testDirectory() {
455 // Port to verify that the test completes.
456 var port = new ReceivePort.singleShot();
457 port.receive((message, replyTo) => Expect.equals(1, message));
458
459 var tempDir = tempDirectory.path;
460 var file = new File("${tempDir}/file");
461 var errors = 0;
462 file.directory();
463 file.directoryHandler = (d) => Expect.fail("non-existing file");
464 file.errorHandler = (s) {
465 file.errorHandler = (s) => Expect.fail("no error expected");
466 file.create();
467 file.createHandler = () {
468 file.directory();
469 file.directoryHandler = (Directory d) {
470 d.exists();
471 d.errorHandler = (s) => Expect.fail("no error expected");
472 d.existsHandler = (exists) {
473 Expect.isTrue(exists);
474 Expect.equals(tempDir, d.path);
475 file.delete();
476 file.deleteHandler = () {
477 var file_dir = new File(".");
478 file_dir.directory();
479 file_dir.directoryHandler = (d) {
480 Expect.fail("non-existing file");
481 };
482 file_dir.errorHandler = (s) {
483 var file_dir = new File(tempDir);
484 file_dir.directory();
485 file_dir.directoryHandler = (d) {
486 Expect.fail("non-existing file");
487 };
488 file_dir.errorHandler = (s) {
489 port.toSendPort().send(1);
490 };
491 };
492 };
493 };
494 };
495 };
496 };
497 }
498
499 static void testDirectorySync() {
500 var tempDir = tempDirectory.path;
501 var file = new File("${tempDir}/file");
502 // Non-existing file should throw exception.
503 Expect.throws(file.directorySync, (e) { return e is FileIOException; });
504 file.createSync();
505 // Check that the path of the returned directory is the temp directory.
506 Directory d = file.directorySync();
507 Expect.isTrue(d.existsSync());
508 Expect.equals(tempDir, d.path);
509 file.deleteSync();
510 // Directories should throw exception.
511 var file_dir = new File(".");
512 Expect.throws(file_dir.directorySync, (e) { return e is FileIOException; });
513 file_dir = new File(tempDir);
514 Expect.throws(file_dir.directorySync, (e) { return e is FileIOException; });
515 }
516
454 // Test for file length functionality. 517 // Test for file length functionality.
455 static void testLength() { 518 static void testLength() {
456 String filename = getFilename("tests/vm/data/fixed_length_file"); 519 String filename = getFilename("tests/vm/data/fixed_length_file");
457 RandomAccessFile input = (new File(filename)).openSync(); 520 RandomAccessFile input = (new File(filename)).openSync();
458 input.errorHandler = (s) { 521 input.errorHandler = (s) {
459 Expect.fail("No errors expected"); 522 Expect.fail("No errors expected");
460 }; 523 };
461 input.lengthHandler = (length) { 524 input.lengthHandler = (length) {
462 Expect.equals(42, length); 525 Expect.equals(42, length);
463 input.close(); 526 input.close();
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 static void testOpenDirectoryAsFileSync() { 863 static void testOpenDirectoryAsFileSync() {
801 var f = new File('.'); 864 var f = new File('.');
802 try { 865 try {
803 f.openSync(); 866 f.openSync();
804 Expect.fail("Expected exception opening directory as file"); 867 Expect.fail("Expected exception opening directory as file");
805 } catch (var e) { 868 } catch (var e) {
806 Expect.isTrue(e is FileIOException); 869 Expect.isTrue(e is FileIOException);
807 } 870 }
808 } 871 }
809 872
873
810 // Test that opens the same file for writing then for appending to test 874 // Test that opens the same file for writing then for appending to test
811 // that the file is not truncated when opened for appending. 875 // that the file is not truncated when opened for appending.
812 static void testAppend() { 876 static void testAppend() {
813 var file = new File('${tempDirectory.path}/out_append'); 877 var file = new File('${tempDirectory.path}/out_append');
814 file.openHandler = (openedFile) { 878 file.openHandler = (openedFile) {
815 openedFile.noPendingWriteHandler = () { 879 openedFile.noPendingWriteHandler = () {
816 openedFile.closeHandler = () { 880 openedFile.closeHandler = () {
817 file.openHandler = (openedFile) { 881 file.openHandler = (openedFile) {
818 openedFile.lengthHandler = (length) { 882 openedFile.lengthHandler = (length) {
819 Expect.equals(4, length); 883 Expect.equals(4, length);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 testReadStream(); 942 testReadStream();
879 testLength(); 943 testLength();
880 testLengthSync(); 944 testLengthSync();
881 testPosition(); 945 testPosition();
882 testPositionSync(); 946 testPositionSync();
883 testMixedSyncAndAsync(); 947 testMixedSyncAndAsync();
884 testOpenDirectoryAsFile(); 948 testOpenDirectoryAsFile();
885 testOpenDirectoryAsFileSync(); 949 testOpenDirectoryAsFileSync();
886 950
887 createTempDirectory(() { 951 createTempDirectory(() {
888 testReadWrite(); 952 testReadWrite();
889 testReadWriteSync(); 953 testReadWriteSync();
890 testReadWriteStream(); 954 testReadWriteStream();
891 testReadEmptyFileSync(); 955 testReadEmptyFileSync();
892 testReadEmptyFile(); 956 testReadEmptyFile();
893 testTruncate(); 957 testTruncate();
894 testTruncateSync(); 958 testTruncateSync();
895 testCloseException(); 959 testCloseException();
896 testCloseExceptionStream(); 960 testCloseExceptionStream();
897 testBufferOutOfBoundsException(); 961 testBufferOutOfBoundsException();
898 testAppend(); 962 testAppend();
899 testAppendSync(); 963 testAppendSync();
900 testWriteAppend(); 964 testWriteAppend();
901 testOutputStreamWriteAppend(); 965 testOutputStreamWriteAppend();
902 testWriteVariousLists(); 966 testWriteVariousLists();
903 }); 967 testDirectory();
968 testDirectorySync();
969 });
904 } 970 }
905 } 971 }
906 972
907 main() { 973 main() {
908 FileTest.testMain(); 974 FileTest.testMain();
909 } 975 }
OLDNEW
« runtime/bin/file_linux.cc ('K') | « runtime/bin/file_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698