| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // OtherResources=empty_file | 7 // OtherResources=empty_file |
| 8 // OtherResources=file_test.txt | 8 // OtherResources=file_test.txt |
| 9 // OtherResources=fixed_length_file | 9 // OtherResources=fixed_length_file |
| 10 // OtherResources=read_as_text.dat | 10 // OtherResources=read_as_text.dat |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 | 635 |
| 636 static void testLengthSync() { | 636 static void testLengthSync() { |
| 637 String filename = getFilename("fixed_length_file"); | 637 String filename = getFilename("fixed_length_file"); |
| 638 File file = new File(filename); | 638 File file = new File(filename); |
| 639 RandomAccessFile openedFile = file.openSync(); | 639 RandomAccessFile openedFile = file.openSync(); |
| 640 Expect.equals(42, file.lengthSync()); | 640 Expect.equals(42, file.lengthSync()); |
| 641 Expect.equals(42, openedFile.lengthSync()); | 641 Expect.equals(42, openedFile.lengthSync()); |
| 642 openedFile.closeSync(); | 642 openedFile.closeSync(); |
| 643 } | 643 } |
| 644 | 644 |
| 645 static void testLengthSyncDirectory() { |
| 646 Directory tmp = tempDirectory.createTempSync('file_length_test_'); |
| 647 String dirPath = '${tmp.path}/dir'; |
| 648 new Directory(dirPath).createSync(); |
| 649 try { |
| 650 new File(dirPath).lengthSync(); |
| 651 Expect.fail('Expected operation to throw'); |
| 652 } catch (e) { |
| 653 if (e is! FileSystemException) { |
| 654 print(e); |
| 655 } |
| 656 Expect.isTrue(e is FileSystemException); |
| 657 } finally { |
| 658 tmp.deleteSync(recursive: true); |
| 659 } |
| 660 } |
| 661 |
| 645 // Test for file position functionality. | 662 // Test for file position functionality. |
| 646 static void testPosition() { | 663 static void testPosition() { |
| 647 asyncTestStarted(); | 664 asyncTestStarted(); |
| 648 String filename = getFilename("fixed_length_file"); | 665 String filename = getFilename("fixed_length_file"); |
| 649 RandomAccessFile input = (new File(filename)).openSync(); | 666 RandomAccessFile input = (new File(filename)).openSync(); |
| 650 input.position().then((position) { | 667 input.position().then((position) { |
| 651 Expect.equals(0, position); | 668 Expect.equals(0, position); |
| 652 List<int> buffer = new List<int>(100); | 669 List<int> buffer = new List<int>(100); |
| 653 input.readInto(buffer, 0, 12).then((bytes_read) { | 670 input.readInto(buffer, 0, 12).then((bytes_read) { |
| 654 input.position().then((position) { | 671 input.position().then((position) { |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1421 testOpenDirectoryAsFileSync(); | 1438 testOpenDirectoryAsFileSync(); |
| 1422 testReadAsBytesSync(); | 1439 testReadAsBytesSync(); |
| 1423 testReadAsBytesSyncEmptyFile(); | 1440 testReadAsBytesSyncEmptyFile(); |
| 1424 testReadAsTextSync(); | 1441 testReadAsTextSync(); |
| 1425 testReadAsTextSyncEmptyFile(); | 1442 testReadAsTextSyncEmptyFile(); |
| 1426 testReadAsLinesSync(); | 1443 testReadAsLinesSync(); |
| 1427 testLastModifiedSync(); | 1444 testLastModifiedSync(); |
| 1428 | 1445 |
| 1429 createTempDirectory(() { | 1446 createTempDirectory(() { |
| 1430 testLength(); | 1447 testLength(); |
| 1448 testLengthSyncDirectory(); |
| 1431 testReadWrite(); | 1449 testReadWrite(); |
| 1432 testReadWriteSync(); | 1450 testReadWriteSync(); |
| 1433 testReadWriteNoArgsSync(); | 1451 testReadWriteNoArgsSync(); |
| 1434 testReadWriteStream(); | 1452 testReadWriteStream(); |
| 1435 testReadEmptyFileSync(); | 1453 testReadEmptyFileSync(); |
| 1436 testReadEmptyFile(); | 1454 testReadEmptyFile(); |
| 1437 testReadWriteStreamLargeFile(); | 1455 testReadWriteStreamLargeFile(); |
| 1438 testReadAsBytes(); | 1456 testReadAsBytes(); |
| 1439 testReadAsBytesEmptyFile(); | 1457 testReadAsBytesEmptyFile(); |
| 1440 testReadAsText(); | 1458 testReadAsText(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1468 testLastModified(); | 1486 testLastModified(); |
| 1469 testDoubleAsyncOperation(); | 1487 testDoubleAsyncOperation(); |
| 1470 asyncEnd(); | 1488 asyncEnd(); |
| 1471 }); | 1489 }); |
| 1472 } | 1490 } |
| 1473 } | 1491 } |
| 1474 | 1492 |
| 1475 main() { | 1493 main() { |
| 1476 FileTest.testMain(); | 1494 FileTest.testMain(); |
| 1477 } | 1495 } |
| OLD | NEW |