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

Side by Side Diff: tests/standalone/io/file_test.dart

Issue 12282038: Remove deprecated string features. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge to head Created 7 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:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 10
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 }); 301 });
302 asyncTestStarted(); 302 asyncTestStarted();
303 } 303 }
304 304
305 static void testWriteAppend() { 305 static void testWriteAppend() {
306 String content = "foobar"; 306 String content = "foobar";
307 String filename = tempDirectory.path.concat("/write_append"); 307 String filename = tempDirectory.path.concat("/write_append");
308 File file = new File(filename); 308 File file = new File(filename);
309 file.createSync(); 309 file.createSync();
310 Expect.isTrue(new File(filename).existsSync()); 310 Expect.isTrue(new File(filename).existsSync());
311 List<int> buffer = content.charCodes; 311 List<int> buffer = content.codeUnits;
312 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); 312 RandomAccessFile openedFile = file.openSync(FileMode.WRITE);
313 openedFile.writeListSync(buffer, 0, buffer.length); 313 openedFile.writeListSync(buffer, 0, buffer.length);
314 openedFile.closeSync(); 314 openedFile.closeSync();
315 // Reopen the file in write mode to ensure that we overwrite the content. 315 // Reopen the file in write mode to ensure that we overwrite the content.
316 openedFile = (new File(filename)).openSync(FileMode.WRITE); 316 openedFile = (new File(filename)).openSync(FileMode.WRITE);
317 openedFile.writeListSync(buffer, 0, buffer.length); 317 openedFile.writeListSync(buffer, 0, buffer.length);
318 Expect.equals(content.length, openedFile.lengthSync()); 318 Expect.equals(content.length, openedFile.lengthSync());
319 openedFile.closeSync(); 319 openedFile.closeSync();
320 // Open the file in append mode and ensure that we do not overwrite 320 // Open the file in append mode and ensure that we do not overwrite
321 // the existing content. 321 // the existing content.
322 openedFile = (new File(filename)).openSync(FileMode.APPEND); 322 openedFile = (new File(filename)).openSync(FileMode.APPEND);
323 openedFile.writeListSync(buffer, 0, buffer.length); 323 openedFile.writeListSync(buffer, 0, buffer.length);
324 Expect.equals(content.length * 2, openedFile.lengthSync()); 324 Expect.equals(content.length * 2, openedFile.lengthSync());
325 openedFile.closeSync(); 325 openedFile.closeSync();
326 file.deleteSync(); 326 file.deleteSync();
327 } 327 }
328 328
329 static void testOutputStreamWriteAppend() { 329 static void testOutputStreamWriteAppend() {
330 String content = "foobar"; 330 String content = "foobar";
331 String filename = tempDirectory.path.concat("/outstream_write_append"); 331 String filename = tempDirectory.path.concat("/outstream_write_append");
332 File file = new File(filename); 332 File file = new File(filename);
333 file.createSync(); 333 file.createSync();
334 List<int> buffer = content.charCodes; 334 List<int> buffer = content.codeUnits;
335 var output = file.openWrite(); 335 var output = file.openWrite();
336 output.add(buffer); 336 output.add(buffer);
337 output.close(); 337 output.close();
338 output.done.then((_) { 338 output.done.then((_) {
339 File file2 = new File(filename); 339 File file2 = new File(filename);
340 var appendingOutput = file2.openWrite(FileMode.APPEND); 340 var appendingOutput = file2.openWrite(FileMode.APPEND);
341 appendingOutput.add(buffer); 341 appendingOutput.add(buffer);
342 appendingOutput.close(); 342 appendingOutput.close();
343 appendingOutput.done.then((_) { 343 appendingOutput.done.then((_) {
344 File file3 = new File(filename); 344 File file3 = new File(filename);
(...skipping 11 matching lines...) Expand all
356 }); 356 });
357 asyncTestStarted(); 357 asyncTestStarted();
358 } 358 }
359 359
360 // Test for file read and write functionality. 360 // Test for file read and write functionality.
361 static void testOutputStreamWriteString() { 361 static void testOutputStreamWriteString() {
362 String content = "foobar"; 362 String content = "foobar";
363 String filename = tempDirectory.path.concat("/outstream_write_string"); 363 String filename = tempDirectory.path.concat("/outstream_write_string");
364 File file = new File(filename); 364 File file = new File(filename);
365 file.createSync(); 365 file.createSync();
366 List<int> buffer = content.charCodes; 366 List<int> buffer = content.codeUnits;
367 var output = file.openWrite(); 367 var output = file.openWrite();
368 output.addString("abcdABCD"); 368 output.addString("abcdABCD");
369 output.addString("abcdABCD", Encoding.UTF_8); 369 output.addString("abcdABCD", Encoding.UTF_8);
370 output.addString("abcdABCD", Encoding.ISO_8859_1); 370 output.addString("abcdABCD", Encoding.ISO_8859_1);
371 output.addString("abcdABCD", Encoding.ASCII); 371 output.addString("abcdABCD", Encoding.ASCII);
372 output.addString("æøå", Encoding.UTF_8); 372 output.addString("æøå", Encoding.UTF_8);
373 output.close(); 373 output.close();
374 output.done.then((_) { 374 output.done.then((_) {
375 RandomAccessFile raf = file.openSync(); 375 RandomAccessFile raf = file.openSync();
376 Expect.equals(38, raf.lengthSync()); 376 Expect.equals(38, raf.lengthSync());
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 var name = getFilename("tests/vm/data/fixed_length_file"); 933 var name = getFilename("tests/vm/data/fixed_length_file");
934 var f = new File(name); 934 var f = new File(name);
935 f.readAsString(Encoding.UTF_8).then((text) { 935 f.readAsString(Encoding.UTF_8).then((text) {
936 Expect.isTrue(text.endsWith("42 bytes.")); 936 Expect.isTrue(text.endsWith("42 bytes."));
937 Expect.equals(42, text.length); 937 Expect.equals(42, text.length);
938 var name = getDataFilename("tests/standalone/io/read_as_text.dat"); 938 var name = getDataFilename("tests/standalone/io/read_as_text.dat");
939 var f = new File(name); 939 var f = new File(name);
940 f.readAsString(Encoding.UTF_8).then((text) { 940 f.readAsString(Encoding.UTF_8).then((text) {
941 Expect.equals(6, text.length); 941 Expect.equals(6, text.length);
942 var expected = [955, 120, 46, 32, 120, 10]; 942 var expected = [955, 120, 46, 32, 120, 10];
943 Expect.listEquals(expected, text.charCodes); 943 Expect.listEquals(expected, text.codeUnits);
944 f.readAsString(Encoding.ISO_8859_1).then((text) { 944 f.readAsString(Encoding.ISO_8859_1).then((text) {
945 Expect.equals(7, text.length); 945 Expect.equals(7, text.length);
946 var expected = [206, 187, 120, 46, 32, 120, 10]; 946 var expected = [206, 187, 120, 46, 32, 120, 10];
947 Expect.listEquals(expected, text.charCodes); 947 Expect.listEquals(expected, text.codeUnits);
948 var readAsStringFuture = f.readAsString(Encoding.ASCII); 948 var readAsStringFuture = f.readAsString(Encoding.ASCII);
949 readAsStringFuture.then((text) { 949 readAsStringFuture.then((text) {
950 Expect.fail("Non-ascii char should cause error"); 950 Expect.fail("Non-ascii char should cause error");
951 }).catchError((e) { 951 }).catchError((e) {
952 port.toSendPort().send(1); 952 port.toSendPort().send(1);
953 }); 953 });
954 }); 954 });
955 }); 955 });
956 }); 956 });
957 } 957 }
(...skipping 14 matching lines...) Expand all
972 972
973 static void testReadAsTextSync() { 973 static void testReadAsTextSync() {
974 var name = getFilename("tests/vm/data/fixed_length_file"); 974 var name = getFilename("tests/vm/data/fixed_length_file");
975 var text = new File(name).readAsStringSync(); 975 var text = new File(name).readAsStringSync();
976 Expect.isTrue(text.endsWith("42 bytes.")); 976 Expect.isTrue(text.endsWith("42 bytes."));
977 Expect.equals(42, text.length); 977 Expect.equals(42, text.length);
978 name = getDataFilename("tests/standalone/io/read_as_text.dat"); 978 name = getDataFilename("tests/standalone/io/read_as_text.dat");
979 text = new File(name).readAsStringSync(); 979 text = new File(name).readAsStringSync();
980 Expect.equals(6, text.length); 980 Expect.equals(6, text.length);
981 var expected = [955, 120, 46, 32, 120, 10]; 981 var expected = [955, 120, 46, 32, 120, 10];
982 Expect.listEquals(expected, text.charCodes); 982 Expect.listEquals(expected, text.codeUnits);
983 text = new File(name).readAsStringSync(Encoding.ASCII); 983 text = new File(name).readAsStringSync(Encoding.ASCII);
984 // Default replacement character is '?', char code 63. 984 // Default replacement character is '?', char code 63.
985 expected = [63, 63, 120, 46, 32, 120, 10]; 985 expected = [63, 63, 120, 46, 32, 120, 10];
986 Expect.listEquals(expected, text.charCodes); 986 Expect.listEquals(expected, text.codeUnits);
987 text = new File(name).readAsStringSync(Encoding.ISO_8859_1); 987 text = new File(name).readAsStringSync(Encoding.ISO_8859_1);
988 expected = [206, 187, 120, 46, 32, 120, 10]; 988 expected = [206, 187, 120, 46, 32, 120, 10];
989 Expect.equals(7, text.length); 989 Expect.equals(7, text.length);
990 Expect.listEquals(expected, text.charCodes); 990 Expect.listEquals(expected, text.codeUnits);
991 } 991 }
992 992
993 static void testReadAsTextSyncEmptyFile() { 993 static void testReadAsTextSyncEmptyFile() {
994 var name = getFilename("tests/vm/data/empty_file"); 994 var name = getFilename("tests/vm/data/empty_file");
995 var text = new File(name).readAsStringSync(); 995 var text = new File(name).readAsStringSync();
996 Expect.equals(0, text.length); 996 Expect.equals(0, text.length);
997 } 997 }
998 998
999 static void testReadAsLines() { 999 static void testReadAsLines() {
1000 var port = new ReceivePort(); 1000 var port = new ReceivePort();
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 testDirectorySync(); 1221 testDirectorySync();
1222 testWriteStringUtf8(); 1222 testWriteStringUtf8();
1223 testWriteStringUtf8Sync(); 1223 testWriteStringUtf8Sync();
1224 }); 1224 });
1225 } 1225 }
1226 } 1226 }
1227 1227
1228 main() { 1228 main() {
1229 FileTest.testMain(); 1229 FileTest.testMain();
1230 } 1230 }
OLDNEW
« no previous file with comments | « tests/standalone/io/file_system_links_test.dart ('k') | tests/standalone/io/http_client_connect_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698