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

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

Issue 9428003: Add more file tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « no previous file | 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 {
10 int _value;
11 MyListOfOneElement(this._value);
12 int get length() => 1;
13 operator [](int index) => _value;
14 }
15
9 class FileTest { 16 class FileTest {
10 static Directory tempDirectory; 17 static Directory tempDirectory;
11 static int numLiveAsyncTests = 0; 18 static int numLiveAsyncTests = 0;
12 19
13 static void asyncTestStarted() { ++numLiveAsyncTests; } 20 static void asyncTestStarted() { ++numLiveAsyncTests; }
14 static void asyncTestDone(String name) { 21 static void asyncTestDone(String name) {
15 --numLiveAsyncTests; 22 --numLiveAsyncTests;
16 if (numLiveAsyncTests == 0) { 23 if (numLiveAsyncTests == 0) {
17 deleteTempDirectory(); 24 deleteTempDirectory();
18 } 25 }
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 openedFile.close(); 395 openedFile.close();
389 }; 396 };
390 openedFile.readByte(); 397 openedFile.readByte();
391 }; 398 };
392 file.open(); 399 file.open();
393 }; 400 };
394 asyncTestStarted(); 401 asyncTestStarted();
395 file.create(); 402 file.create();
396 } 403 }
397 404
405 // Test for file write of different types of lists.
406 static void testWriteVariousLists() {
407 final String fileName = "${tempDirectory.path}/testWriteVariousLists";
408 final File file = new File(fileName);
409 file.create();
410 file.createHandler = () {
411 file.open(FileMode.WRITE);
412 file.openHandler = (RandomAccessFile openedFile) {
413 // Write bytes from 0 to 7.
414 openedFile.writeList([0], 0, 1);
415 openedFile.writeList(const [1], 0, 1);
416 openedFile.writeList(new MyListOfOneElement(2), 0, 1);
417 var x = 12345678901234567890123456789012345678901234567890;
418 var y = 12345678901234567890123456789012345678901234567893;
419 openedFile.writeList([y - x], 0, 1);
420 openedFile.writeList([260], 0, 1); // 260 = 256 + 4 = 0x104.
421 openedFile.writeList(const [261], 0, 1);
422 openedFile.writeList(new MyListOfOneElement(262), 0, 1);
423 x = 12345678901234567890123456789012345678901234567890;
424 y = 12345678901234567890123456789012345678901234568153;
425 openedFile.writeList([y - x], 0, 1);
426
427 openedFile.errorHandler = (s) {
428 Expect.fail("No errors expected : $s");
429 };
430 openedFile.noPendingWriteHandler = () {
431 openedFile.close();
432 };
433 openedFile.closeHandler = () {
434 // Check the written bytes.
435 final File file2 = new File(fileName);
436 var openedFile2 = file2.openSync();
437 vat length = openedFile2.lengthSync();
438 Expect.equals(8, length);
439 List data = new List(length);
440 openedFile2.readListSync(data, 0, length);
Mads Ager (google) 2012/02/21 15:46:22 Maybe add an Expect.equals on the return value of
Søren Gjesse 2012/02/21 16:03:17 Done.
441 for (var i = 0; i < data.length; i++) {
442 Expect.equals(i, data[i]);
443 }
444 openedFile2.closeSync();
445 file2.deleteSync();
446 };
447 };
448 file.errorHandler = (s) {
449 Expect.fail("No errors expected : $s");
450 };
451 };
452 }
453
398 // Test for file length functionality. 454 // Test for file length functionality.
399 static void testLength() { 455 static void testLength() {
400 String filename = getFilename("tests/vm/data/fixed_length_file"); 456 String filename = getFilename("tests/vm/data/fixed_length_file");
401 RandomAccessFile input = (new File(filename)).openSync(); 457 RandomAccessFile input = (new File(filename)).openSync();
402 input.errorHandler = (s) { 458 input.errorHandler = (s) {
403 Expect.fail("No errors expected"); 459 Expect.fail("No errors expected");
404 }; 460 };
405 input.lengthHandler = (length) { 461 input.lengthHandler = (length) {
406 Expect.equals(42, length); 462 Expect.equals(42, length);
407 input.close(); 463 input.close();
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 testReadEmptyFile(); 892 testReadEmptyFile();
837 testTruncate(); 893 testTruncate();
838 testTruncateSync(); 894 testTruncateSync();
839 testCloseException(); 895 testCloseException();
840 testCloseExceptionStream(); 896 testCloseExceptionStream();
841 testBufferOutOfBoundsException(); 897 testBufferOutOfBoundsException();
842 testAppend(); 898 testAppend();
843 testAppendSync(); 899 testAppendSync();
844 testWriteAppend(); 900 testWriteAppend();
845 testOutputStreamWriteAppend(); 901 testOutputStreamWriteAppend();
902 testWriteVariousLists();
846 }); 903 });
847 } 904 }
848 } 905 }
849 906
850 main() { 907 main() {
851 FileTest.testMain(); 908 FileTest.testMain();
852 } 909 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698