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

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

Issue 9652001: SendPort + ReceivePort changes: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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
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 #import("dart:isolate"); 8 #import("dart:isolate");
9 9
10 class MyListOfOneElement implements List { 10 class MyListOfOneElement implements List {
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 }); 450 });
451 }; 451 };
452 }); 452 });
453 }); 453 });
454 } 454 }
455 455
456 static void testDirectory() { 456 static void testDirectory() {
457 asyncTestStarted(); 457 asyncTestStarted();
458 458
459 // Port to verify that the test completes. 459 // Port to verify that the test completes.
460 var port = new ReceivePort.singleShot(); 460 var port = new ReceivePort();
461 port.receive((message, replyTo) { 461 port.receive((message, replyTo) {
462 port.close();
462 Expect.equals(1, message); 463 Expect.equals(1, message);
463 asyncTestDone("testDirectory"); 464 asyncTestDone("testDirectory");
464 }); 465 });
465 466
466 var tempDir = tempDirectory.path; 467 var tempDir = tempDirectory.path;
467 var file = new File("${tempDir}/testDirectory"); 468 var file = new File("${tempDir}/testDirectory");
468 var errors = 0; 469 var errors = 0;
469 file.directory((d) => Expect.fail("non-existing file")); 470 file.directory((d) => Expect.fail("non-existing file"));
470 file.onError = (s) { 471 file.onError = (s) {
471 file.onError = (s) => Expect.fail("no error expected"); 472 file.onError = (s) => Expect.fail("no error expected");
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 var f = new File('.'); 850 var f = new File('.');
850 try { 851 try {
851 f.openSync(); 852 f.openSync();
852 Expect.fail("Expected exception opening directory as file"); 853 Expect.fail("Expected exception opening directory as file");
853 } catch (var e) { 854 } catch (var e) {
854 Expect.isTrue(e is FileIOException); 855 Expect.isTrue(e is FileIOException);
855 } 856 }
856 } 857 }
857 858
858 static void testReadAsBytes() { 859 static void testReadAsBytes() {
859 var port = new ReceivePort.singleShot(); 860 var port = new ReceivePort();
860 port.receive((result, replyTo) { 861 port.receive((result, replyTo) {
862 port.close();
861 Expect.equals(42, result); 863 Expect.equals(42, result);
862 }); 864 });
863 var name = getFilename("tests/vm/data/fixed_length_file"); 865 var name = getFilename("tests/vm/data/fixed_length_file");
864 var f = new File(name); 866 var f = new File(name);
865 f.readAsBytes((bytes) { 867 f.readAsBytes((bytes) {
866 Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes.")); 868 Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes."));
867 port.toSendPort().send(bytes.length); 869 port.toSendPort().send(bytes.length);
868 }); 870 });
869 f.onError = (e) { 871 f.onError = (e) {
870 Expect.fail("No errors expected: $e"); 872 Expect.fail("No errors expected: $e");
871 }; 873 };
872 } 874 }
873 875
874 static void testReadAsBytesSync() { 876 static void testReadAsBytesSync() {
875 var name = getFilename("tests/vm/data/fixed_length_file"); 877 var name = getFilename("tests/vm/data/fixed_length_file");
876 var bytes = new File(name).readAsBytesSync(); 878 var bytes = new File(name).readAsBytesSync();
877 Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes.")); 879 Expect.isTrue(new String.fromCharCodes(bytes).endsWith("42 bytes."));
878 Expect.equals(bytes.length, 42); 880 Expect.equals(bytes.length, 42);
879 } 881 }
880 882
881 static void testReadAsText() { 883 static void testReadAsText() {
882 var port = new ReceivePort.singleShot(); 884 var port = new ReceivePort();
883 port.receive((result, replyTo) { 885 port.receive((result, replyTo) {
886 port.close();
884 Expect.equals(1, result); 887 Expect.equals(1, result);
885 }); 888 });
886 var name = getFilename("tests/vm/data/fixed_length_file"); 889 var name = getFilename("tests/vm/data/fixed_length_file");
887 var f = new File(name); 890 var f = new File(name);
888 f.readAsText('UTF-8', (text) { 891 f.readAsText('UTF-8', (text) {
889 Expect.isTrue(text.endsWith("42 bytes.")); 892 Expect.isTrue(text.endsWith("42 bytes."));
890 Expect.equals(42, text.length); 893 Expect.equals(42, text.length);
891 var name = getDataFilename("tests/standalone/src/io/read_as_text.dat"); 894 var name = getDataFilename("tests/standalone/src/io/read_as_text.dat");
892 var f = new File(name); 895 var f = new File(name);
893 f.onError = (e) => Expect.fail("No errors expected"); 896 f.onError = (e) => Expect.fail("No errors expected");
(...skipping 30 matching lines...) Expand all
924 var expected = [955, 120, 46, 32, 120, 10]; 927 var expected = [955, 120, 46, 32, 120, 10];
925 Expect.listEquals(expected, text.charCodes()); 928 Expect.listEquals(expected, text.charCodes());
926 Expect.throws(() { new File(name).readAsTextSync("ASCII"); }); 929 Expect.throws(() { new File(name).readAsTextSync("ASCII"); });
927 text = new File(name).readAsTextSync("ISO-8859-1"); 930 text = new File(name).readAsTextSync("ISO-8859-1");
928 expected = [206, 187, 120, 46, 32, 120, 10]; 931 expected = [206, 187, 120, 46, 32, 120, 10];
929 Expect.equals(7, text.length); 932 Expect.equals(7, text.length);
930 Expect.listEquals(expected, text.charCodes()); 933 Expect.listEquals(expected, text.charCodes());
931 } 934 }
932 935
933 static void testReadAsLines() { 936 static void testReadAsLines() {
934 var port = new ReceivePort.singleShot(); 937 var port = new ReceivePort();
935 port.receive((result, replyTo) { 938 port.receive((result, replyTo) {
939 port.close();
936 Expect.equals(42, result); 940 Expect.equals(42, result);
937 }); 941 });
938 var name = getFilename("tests/vm/data/fixed_length_file"); 942 var name = getFilename("tests/vm/data/fixed_length_file");
939 var f = new File(name); 943 var f = new File(name);
940 f.readAsLines('UTF-8', (lines) { 944 f.readAsLines('UTF-8', (lines) {
941 Expect.equals(1, lines.length); 945 Expect.equals(1, lines.length);
942 var line = lines[0]; 946 var line = lines[0];
943 Expect.isTrue(line.endsWith("42 bytes.")); 947 Expect.isTrue(line.endsWith("42 bytes."));
944 port.toSendPort().send(line.length); 948 port.toSendPort().send(line.length);
945 }); 949 });
946 f.onError = (e) { 950 f.onError = (e) {
947 Expect.fail("No errors expected: $e"); 951 Expect.fail("No errors expected: $e");
948 }; 952 };
949 } 953 }
950 954
951 static void testReadAsLinesSync() { 955 static void testReadAsLinesSync() {
952 var name = getFilename("tests/vm/data/fixed_length_file"); 956 var name = getFilename("tests/vm/data/fixed_length_file");
953 var lines = new File(name).readAsLinesSync(); 957 var lines = new File(name).readAsLinesSync();
954 Expect.equals(1, lines.length); 958 Expect.equals(1, lines.length);
955 var line = lines[0]; 959 var line = lines[0];
956 Expect.isTrue(line.endsWith("42 bytes.")); 960 Expect.isTrue(line.endsWith("42 bytes."));
957 Expect.equals(42, line.length); 961 Expect.equals(42, line.length);
958 name = getDataFilename("tests/standalone/src/io/readline_test1.dat"); 962 name = getDataFilename("tests/standalone/src/io/readline_test1.dat");
959 lines = new File(name).readAsLinesSync(); 963 lines = new File(name).readAsLinesSync();
960 Expect.equals(10, lines.length); 964 Expect.equals(10, lines.length);
961 } 965 }
962 966
963 967
964 static void testReadAsErrors() { 968 static void testReadAsErrors() {
965 var port = new ReceivePort.singleShot(); 969 var port = new ReceivePort();
966 port.receive((message, _) { 970 port.receive((message, _) {
971 port.close();
967 Expect.equals(1, message); 972 Expect.equals(1, message);
968 }); 973 });
969 var f = new File('.'); 974 var f = new File('.');
970 Expect.throws(f.readAsBytesSync, (e) => e is FileIOException); 975 Expect.throws(f.readAsBytesSync, (e) => e is FileIOException);
971 Expect.throws(f.readAsTextSync, (e) => e is FileIOException); 976 Expect.throws(f.readAsTextSync, (e) => e is FileIOException);
972 Expect.throws(f.readAsLinesSync, (e) => e is FileIOException); 977 Expect.throws(f.readAsLinesSync, (e) => e is FileIOException);
973 f.readAsBytes((bytes) => Expect.fail("no bytes expected")); 978 f.readAsBytes((bytes) => Expect.fail("no bytes expected"));
974 f.onError = (e) { 979 f.onError = (e) {
975 f.readAsText('UTF-8', (text) => Expect.fail("no text expected")); 980 f.readAsText('UTF-8', (text) => Expect.fail("no text expected"));
976 f.onError = (e) { 981 f.onError = (e) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 testWriteVariousLists(); 1081 testWriteVariousLists();
1077 testDirectory(); 1082 testDirectory();
1078 testDirectorySync(); 1083 testDirectorySync();
1079 }); 1084 });
1080 } 1085 }
1081 } 1086 }
1082 1087
1083 main() { 1088 main() {
1084 FileTest.testMain(); 1089 FileTest.testMain();
1085 } 1090 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698