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

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

Issue 14018007: Rename RandomAccessFile.readList and RandomAccessFile.writeList to RandomAccessFile.readInto and Ra… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix return type. Created 7 years, 8 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) 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 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:isolate'; 10 import 'dart:isolate';
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 return done.future; 196 return done.future;
197 } 197 }
198 198
199 static void testRead() { 199 static void testRead() {
200 ReceivePort port = new ReceivePort(); 200 ReceivePort port = new ReceivePort();
201 // Read a file and check part of it's contents. 201 // Read a file and check part of it's contents.
202 String filename = getFilename("bin/file_test.cc"); 202 String filename = getFilename("bin/file_test.cc");
203 File file = new File(filename); 203 File file = new File(filename);
204 file.open(mode: READ).then((RandomAccessFile file) { 204 file.open(mode: READ).then((RandomAccessFile file) {
205 List<int> buffer = new List<int>(10); 205 List<int> buffer = new List<int>(10);
206 file.readList(buffer, 0, 5).then((bytes_read) { 206 file.readInto(buffer, 0, 5).then((bytes_read) {
207 Expect.equals(5, bytes_read); 207 Expect.equals(5, bytes_read);
208 file.readList(buffer, 5, 5).then((bytes_read) { 208 file.readInto(buffer, 5, 10).then((bytes_read) {
209 Expect.equals(5, bytes_read); 209 Expect.equals(5, bytes_read);
210 Expect.equals(47, buffer[0]); // represents '/' in the file. 210 Expect.equals(47, buffer[0]); // represents '/' in the file.
211 Expect.equals(47, buffer[1]); // represents '/' in the file. 211 Expect.equals(47, buffer[1]); // represents '/' in the file.
212 Expect.equals(32, buffer[2]); // represents ' ' in the file. 212 Expect.equals(32, buffer[2]); // represents ' ' in the file.
213 Expect.equals(67, buffer[3]); // represents 'C' in the file. 213 Expect.equals(67, buffer[3]); // represents 'C' in the file.
214 Expect.equals(111, buffer[4]); // represents 'o' in the file. 214 Expect.equals(111, buffer[4]); // represents 'o' in the file.
215 Expect.equals(112, buffer[5]); // represents 'p' in the file. 215 Expect.equals(112, buffer[5]); // represents 'p' in the file.
216 Expect.equals(121, buffer[6]); // represents 'y' in the file. 216 Expect.equals(121, buffer[6]); // represents 'y' in the file.
217 Expect.equals(114, buffer[7]); // represents 'r' in the file. 217 Expect.equals(114, buffer[7]); // represents 'r' in the file.
218 Expect.equals(105, buffer[8]); // represents 'i' in the file. 218 Expect.equals(105, buffer[8]); // represents 'i' in the file.
219 Expect.equals(103, buffer[9]); // represents 'g' in the file. 219 Expect.equals(103, buffer[9]); // represents 'g' in the file.
220 file.close().then((ignore) => port.close()); 220 file.close().then((ignore) => port.close());
221 }); 221 });
222 }); 222 });
223 }); 223 });
224 } 224 }
225 225
226 static void testReadSync() { 226 static void testReadSync() {
227 // Read a file and check part of it's contents. 227 // Read a file and check part of it's contents.
228 String filename = getFilename("bin/file_test.cc"); 228 String filename = getFilename("bin/file_test.cc");
229 RandomAccessFile raf = (new File(filename)).openSync(); 229 RandomAccessFile raf = (new File(filename)).openSync();
230 List<int> buffer = new List<int>(42); 230 List<int> buffer = new List<int>(42);
231 int bytes_read = 0; 231 int bytes_read = 0;
232 bytes_read = raf.readListSync(buffer, 0, 12); 232 bytes_read = raf.readIntoSync(buffer, 0, 12);
233 Expect.equals(12, bytes_read); 233 Expect.equals(12, bytes_read);
234 bytes_read = raf.readListSync(buffer, 12, 30); 234 bytes_read = raf.readIntoSync(buffer, 12, 42);
235 Expect.equals(30, bytes_read); 235 Expect.equals(30, bytes_read);
236 Expect.equals(47, buffer[0]); // represents '/' in the file. 236 Expect.equals(47, buffer[0]); // represents '/' in the file.
237 Expect.equals(47, buffer[1]); // represents '/' in the file. 237 Expect.equals(47, buffer[1]); // represents '/' in the file.
238 Expect.equals(32, buffer[2]); // represents ' ' in the file. 238 Expect.equals(32, buffer[2]); // represents ' ' in the file.
239 Expect.equals(67, buffer[3]); // represents 'C' in the file. 239 Expect.equals(67, buffer[3]); // represents 'C' in the file.
240 Expect.equals(111, buffer[4]); // represents 'o' in the file. 240 Expect.equals(111, buffer[4]); // represents 'o' in the file.
241 Expect.equals(112, buffer[5]); // represents 'p' in the file. 241 Expect.equals(112, buffer[5]); // represents 'p' in the file.
242 Expect.equals(121, buffer[6]); // represents 'y' in the file. 242 Expect.equals(121, buffer[6]); // represents 'y' in the file.
243 Expect.equals(114, buffer[7]); // represents 'r' in the file. 243 Expect.equals(114, buffer[7]); // represents 'r' in the file.
244 Expect.equals(105, buffer[8]); // represents 'i' in the file. 244 Expect.equals(105, buffer[8]); // represents 'i' in the file.
(...skipping 13 matching lines...) Expand all
258 Expect.equals(len, file.openSync().readSync(len * 10).length); 258 Expect.equals(len, file.openSync().readSync(len * 10).length);
259 } 259 }
260 260
261 // Test for file read and write functionality. 261 // Test for file read and write functionality.
262 static void testReadWrite() { 262 static void testReadWrite() {
263 // Read a file. 263 // Read a file.
264 String inFilename = getFilename("tests/vm/data/fixed_length_file"); 264 String inFilename = getFilename("tests/vm/data/fixed_length_file");
265 final File file = new File(inFilename); 265 final File file = new File(inFilename);
266 file.open(mode: READ).then((openedFile) { 266 file.open(mode: READ).then((openedFile) {
267 List<int> buffer1 = new List<int>(42); 267 List<int> buffer1 = new List<int>(42);
268 openedFile.readList(buffer1, 0, 42).then((bytes_read) { 268 openedFile.readInto(buffer1, 0, 42).then((bytes_read) {
269 Expect.equals(42, bytes_read); 269 Expect.equals(42, bytes_read);
270 openedFile.close().then((ignore) { 270 openedFile.close().then((ignore) {
271 // Write the contents of the file just read into another file. 271 // Write the contents of the file just read into another file.
272 String outFilename = tempDirectory.path + "/out_read_write"; 272 String outFilename = tempDirectory.path + "/out_read_write";
273 final File file2 = new File(outFilename); 273 final File file2 = new File(outFilename);
274 file2.create().then((ignore) { 274 file2.create().then((ignore) {
275 file2.fullPath().then((s) { 275 file2.fullPath().then((s) {
276 Expect.isTrue(new File(s).existsSync()); 276 Expect.isTrue(new File(s).existsSync());
277 if (s[0] != '/' && s[0] != '\\' && s[1] != ':') { 277 if (s[0] != '/' && s[0] != '\\' && s[1] != ':') {
278 Expect.fail("Not a full path"); 278 Expect.fail("Not a full path");
279 } 279 }
280 file2.open(mode: WRITE).then((openedFile2) { 280 file2.open(mode: WRITE).then((openedFile2) {
281 openedFile2.writeList(buffer1, 0, bytes_read).then((ignore) { 281 openedFile2.writeFrom(buffer1, 0, bytes_read).then((ignore) {
282 openedFile2.close().then((ignore) { 282 openedFile2.close().then((ignore) {
283 List<int> buffer2 = new List<int>(bytes_read); 283 List<int> buffer2 = new List<int>(bytes_read);
284 final File file3 = new File(outFilename); 284 final File file3 = new File(outFilename);
285 file3.open(mode: READ).then((openedFile3) { 285 file3.open(mode: READ).then((openedFile3) {
286 openedFile3.readList(buffer2, 0, 42).then((bytes_read) { 286 openedFile3.readInto(buffer2, 0, 42).then((bytes_read) {
287 Expect.equals(42, bytes_read); 287 Expect.equals(42, bytes_read);
288 openedFile3.close().then((ignore) { 288 openedFile3.close().then((ignore) {
289 // Now compare the two buffers to check if they 289 // Now compare the two buffers to check if they
290 // are identical. 290 // are identical.
291 Expect.equals(buffer1.length, buffer2.length); 291 Expect.equals(buffer1.length, buffer2.length);
292 for (int i = 0; i < buffer1.length; i++) { 292 for (int i = 0; i < buffer1.length; i++) {
293 Expect.equals(buffer1[i], buffer2[i]); 293 Expect.equals(buffer1[i], buffer2[i]);
294 } 294 }
295 // Delete the output file. 295 // Delete the output file.
296 final file4 = file3; 296 final file4 = file3;
(...skipping 18 matching lines...) Expand all
315 } 315 }
316 316
317 static void testWriteAppend() { 317 static void testWriteAppend() {
318 String content = "foobar"; 318 String content = "foobar";
319 String filename = tempDirectory.path + "/write_append"; 319 String filename = tempDirectory.path + "/write_append";
320 File file = new File(filename); 320 File file = new File(filename);
321 file.createSync(); 321 file.createSync();
322 Expect.isTrue(new File(filename).existsSync()); 322 Expect.isTrue(new File(filename).existsSync());
323 List<int> buffer = content.codeUnits; 323 List<int> buffer = content.codeUnits;
324 RandomAccessFile openedFile = file.openSync(mode: WRITE); 324 RandomAccessFile openedFile = file.openSync(mode: WRITE);
325 openedFile.writeListSync(buffer, 0, buffer.length); 325 openedFile.writeFromSync(buffer, 0, buffer.length);
326 openedFile.closeSync(); 326 openedFile.closeSync();
327 // Reopen the file in write mode to ensure that we overwrite the content. 327 // Reopen the file in write mode to ensure that we overwrite the content.
328 openedFile = (new File(filename)).openSync(mode: WRITE); 328 openedFile = (new File(filename)).openSync(mode: WRITE);
329 openedFile.writeListSync(buffer, 0, buffer.length); 329 openedFile.writeFromSync(buffer, 0, buffer.length);
330 Expect.equals(content.length, openedFile.lengthSync()); 330 Expect.equals(content.length, openedFile.lengthSync());
331 openedFile.closeSync(); 331 openedFile.closeSync();
332 // Open the file in append mode and ensure that we do not overwrite 332 // Open the file in append mode and ensure that we do not overwrite
333 // the existing content. 333 // the existing content.
334 openedFile = (new File(filename)).openSync(mode: APPEND); 334 openedFile = (new File(filename)).openSync(mode: APPEND);
335 openedFile.writeListSync(buffer, 0, buffer.length); 335 openedFile.writeFromSync(buffer, 0, buffer.length);
336 Expect.equals(content.length * 2, openedFile.lengthSync()); 336 Expect.equals(content.length * 2, openedFile.lengthSync());
337 openedFile.closeSync(); 337 openedFile.closeSync();
338 file.deleteSync(); 338 file.deleteSync();
339 } 339 }
340 340
341 static void testOutputStreamWriteAppend() { 341 static void testOutputStreamWriteAppend() {
342 String content = "foobar"; 342 String content = "foobar";
343 String filename = tempDirectory.path + "/outstream_write_append"; 343 String filename = tempDirectory.path + "/outstream_write_append";
344 File file = new File(filename); 344 File file = new File(filename);
345 file.createSync(); 345 file.createSync();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 } 398 }
399 399
400 400
401 static void testReadWriteSync() { 401 static void testReadWriteSync() {
402 // Read a file. 402 // Read a file.
403 String inFilename = getFilename("tests/vm/data/fixed_length_file"); 403 String inFilename = getFilename("tests/vm/data/fixed_length_file");
404 RandomAccessFile file = (new File(inFilename)).openSync(); 404 RandomAccessFile file = (new File(inFilename)).openSync();
405 List<int> buffer1 = new List<int>(42); 405 List<int> buffer1 = new List<int>(42);
406 int bytes_read = 0; 406 int bytes_read = 0;
407 int bytes_written = 0; 407 int bytes_written = 0;
408 bytes_read = file.readListSync(buffer1, 0, 42); 408 bytes_read = file.readIntoSync(buffer1, 0, 42);
409 Expect.equals(42, bytes_read); 409 Expect.equals(42, bytes_read);
410 file.closeSync(); 410 file.closeSync();
411 // Write the contents of the file just read into another file. 411 // Write the contents of the file just read into another file.
412 String outFilename = tempDirectory.path + "/out_read_write_sync"; 412 String outFilename = tempDirectory.path + "/out_read_write_sync";
413 File outFile = new File(outFilename); 413 File outFile = new File(outFilename);
414 outFile.createSync(); 414 outFile.createSync();
415 String path = outFile.fullPathSync(); 415 String path = outFile.fullPathSync();
416 if (path[0] != '/' && path[0] != '\\' && path[1] != ':') { 416 if (path[0] != '/' && path[0] != '\\' && path[1] != ':') {
417 Expect.fail("Not a full path"); 417 Expect.fail("Not a full path");
418 } 418 }
419 Expect.isTrue(new File(path).existsSync()); 419 Expect.isTrue(new File(path).existsSync());
420 RandomAccessFile openedFile = outFile.openSync(mode: WRITE); 420 RandomAccessFile openedFile = outFile.openSync(mode: WRITE);
421 openedFile.writeListSync(buffer1, 0, bytes_read); 421 openedFile.writeFromSync(buffer1, 0, bytes_read);
422 openedFile.closeSync(); 422 openedFile.closeSync();
423 // Now read the contents of the file just written. 423 // Now read the contents of the file just written.
424 List<int> buffer2 = new List<int>(bytes_read); 424 List<int> buffer2 = new List<int>(bytes_read);
425 openedFile = (new File(outFilename)).openSync(); 425 openedFile = (new File(outFilename)).openSync();
426 bytes_read = openedFile.readListSync(buffer2, 0, 42); 426 bytes_read = openedFile.readIntoSync(buffer2, 0, 42);
427 Expect.equals(42, bytes_read); 427 Expect.equals(42, bytes_read);
428 openedFile.closeSync(); 428 openedFile.closeSync();
429 // Now compare the two buffers to check if they are identical. 429 // Now compare the two buffers to check if they are identical.
430 Expect.equals(buffer1.length, buffer2.length); 430 Expect.equals(buffer1.length, buffer2.length);
431 for (int i = 0; i < buffer1.length; i++) { 431 for (int i = 0; i < buffer1.length; i++) {
432 Expect.equals(buffer1[i], buffer2[i]); 432 Expect.equals(buffer1[i], buffer2[i]);
433 } 433 }
434 // Delete the output file. 434 // Delete the output file.
435 outFile.deleteSync(); 435 outFile.deleteSync();
436 Expect.isFalse(outFile.existsSync()); 436 Expect.isFalse(outFile.existsSync());
(...skipping 27 matching lines...) Expand all
464 } 464 }
465 465
466 // Test for file write of different types of lists. 466 // Test for file write of different types of lists.
467 static void testWriteVariousLists() { 467 static void testWriteVariousLists() {
468 asyncTestStarted(); 468 asyncTestStarted();
469 final String fileName = "${tempDirectory.path}/testWriteVariousLists"; 469 final String fileName = "${tempDirectory.path}/testWriteVariousLists";
470 final File file = new File(fileName); 470 final File file = new File(fileName);
471 file.create().then((ignore) { 471 file.create().then((ignore) {
472 file.open(mode: WRITE).then((RandomAccessFile openedFile) { 472 file.open(mode: WRITE).then((RandomAccessFile openedFile) {
473 // Write bytes from 0 to 7. 473 // Write bytes from 0 to 7.
474 openedFile.writeList([0], 0, 1); 474 openedFile.writeFrom([0], 0, 1);
475 openedFile.writeList(const [1], 0, 1); 475 openedFile.writeFrom(const [1], 0, 1);
476 openedFile.writeList(new MyListOfOneElement(2), 0, 1); 476 openedFile.writeFrom(new MyListOfOneElement(2), 0, 1);
477 var x = 12345678901234567890123456789012345678901234567890; 477 var x = 12345678901234567890123456789012345678901234567890;
478 var y = 12345678901234567890123456789012345678901234567893; 478 var y = 12345678901234567890123456789012345678901234567893;
479 openedFile.writeList([y - x], 0, 1); 479 openedFile.writeFrom([y - x], 0, 1);
480 openedFile.writeList([260], 0, 1); // 260 = 256 + 4 = 0x104. 480 openedFile.writeFrom([260], 0, 1); // 260 = 256 + 4 = 0x104.
481 openedFile.writeList(const [261], 0, 1); 481 openedFile.writeFrom(const [261], 0, 1);
482 openedFile.writeList(new MyListOfOneElement(262), 0, 1); 482 openedFile.writeFrom(new MyListOfOneElement(262), 0, 1);
483 x = 12345678901234567890123456789012345678901234567890; 483 x = 12345678901234567890123456789012345678901234567890;
484 y = 12345678901234567890123456789012345678901234568153; 484 y = 12345678901234567890123456789012345678901234568153;
485 openedFile.writeList([y - x], 0, 1).then((ignore) { 485 openedFile.writeFrom([y - x], 0, 1).then((ignore) {
486 openedFile.close().then((ignore) { 486 openedFile.close().then((ignore) {
487 // Check the written bytes. 487 // Check the written bytes.
488 final File file2 = new File(fileName); 488 final File file2 = new File(fileName);
489 var openedFile2 = file2.openSync(); 489 var openedFile2 = file2.openSync();
490 var length = openedFile2.lengthSync(); 490 var length = openedFile2.lengthSync();
491 Expect.equals(8, length); 491 Expect.equals(8, length);
492 List data = new List(length); 492 List data = new List(length);
493 openedFile2.readListSync(data, 0, length); 493 openedFile2.readIntoSync(data, 0, length);
494 for (var i = 0; i < data.length; i++) { 494 for (var i = 0; i < data.length; i++) {
495 Expect.equals(i, data[i]); 495 Expect.equals(i, data[i]);
496 } 496 }
497 openedFile2.closeSync(); 497 openedFile2.closeSync();
498 file2.deleteSync(); 498 file2.deleteSync();
499 asyncTestDone("testWriteVariousLists"); 499 asyncTestDone("testWriteVariousLists");
500 }); 500 });
501 }); 501 });
502 }); 502 });
503 }); 503 });
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 } 587 }
588 588
589 // Test for file position functionality. 589 // Test for file position functionality.
590 static void testPosition() { 590 static void testPosition() {
591 var port = new ReceivePort(); 591 var port = new ReceivePort();
592 String filename = getFilename("tests/vm/data/fixed_length_file"); 592 String filename = getFilename("tests/vm/data/fixed_length_file");
593 RandomAccessFile input = (new File(filename)).openSync(); 593 RandomAccessFile input = (new File(filename)).openSync();
594 input.position().then((position) { 594 input.position().then((position) {
595 Expect.equals(0, position); 595 Expect.equals(0, position);
596 List<int> buffer = new List<int>(100); 596 List<int> buffer = new List<int>(100);
597 input.readList(buffer, 0, 12).then((bytes_read) { 597 input.readInto(buffer, 0, 12).then((bytes_read) {
598 input.position().then((position) { 598 input.position().then((position) {
599 Expect.equals(12, position); 599 Expect.equals(12, position);
600 input.readList(buffer, 12, 6).then((bytes_read) { 600 input.readInto(buffer, 12, 18).then((bytes_read) {
601 input.position().then((position) { 601 input.position().then((position) {
602 Expect.equals(18, position); 602 Expect.equals(18, position);
603 input.setPosition(8).then((ignore) { 603 input.setPosition(8).then((ignore) {
604 input.position().then((position) { 604 input.position().then((position) {
605 Expect.equals(8, position); 605 Expect.equals(8, position);
606 input.close().then((ignore) => port.close()); 606 input.close().then((ignore) => port.close());
607 }); 607 });
608 }); 608 });
609 }); 609 });
610 }); 610 });
611 }); 611 });
612 }); 612 });
613 }); 613 });
614 } 614 }
615 615
616 static void testPositionSync() { 616 static void testPositionSync() {
617 String filename = getFilename("tests/vm/data/fixed_length_file"); 617 String filename = getFilename("tests/vm/data/fixed_length_file");
618 RandomAccessFile input = (new File(filename)).openSync(); 618 RandomAccessFile input = (new File(filename)).openSync();
619 Expect.equals(0, input.positionSync()); 619 Expect.equals(0, input.positionSync());
620 List<int> buffer = new List<int>(100); 620 List<int> buffer = new List<int>(100);
621 input.readListSync(buffer, 0, 12); 621 input.readIntoSync(buffer, 0, 12);
622 Expect.equals(12, input.positionSync()); 622 Expect.equals(12, input.positionSync());
623 input.readListSync(buffer, 12, 6); 623 input.readIntoSync(buffer, 12, 18);
624 Expect.equals(18, input.positionSync()); 624 Expect.equals(18, input.positionSync());
625 input.setPositionSync(8); 625 input.setPositionSync(8);
626 Expect.equals(8, input.positionSync()); 626 Expect.equals(8, input.positionSync());
627 input.closeSync(); 627 input.closeSync();
628 } 628 }
629 629
630 static void testTruncate() { 630 static void testTruncate() {
631 File file = new File(tempDirectory.path + "/out_truncate"); 631 File file = new File(tempDirectory.path + "/out_truncate");
632 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; 632 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65];
633 file.open(mode: WRITE).then((RandomAccessFile openedFile) { 633 file.open(mode: WRITE).then((RandomAccessFile openedFile) {
634 openedFile.writeList(buffer, 0, 10).then((ignore) { 634 openedFile.writeFrom(buffer, 0, 10).then((ignore) {
635 openedFile.length().then((length) { 635 openedFile.length().then((length) {
636 Expect.equals(10, length); 636 Expect.equals(10, length);
637 openedFile.truncate(5).then((ignore) { 637 openedFile.truncate(5).then((ignore) {
638 openedFile.length().then((length) { 638 openedFile.length().then((length) {
639 Expect.equals(5, length); 639 Expect.equals(5, length);
640 openedFile.close().then((ignore) { 640 openedFile.close().then((ignore) {
641 file.delete().then((ignore) { 641 file.delete().then((ignore) {
642 file.exists().then((exists) { 642 file.exists().then((exists) {
643 Expect.isFalse(exists); 643 Expect.isFalse(exists);
644 asyncTestDone("testTruncate"); 644 asyncTestDone("testTruncate");
645 }); 645 });
646 }); 646 });
647 }); 647 });
648 }); 648 });
649 }); 649 });
650 }); 650 });
651 }); 651 });
652 }); 652 });
653 asyncTestStarted(); 653 asyncTestStarted();
654 } 654 }
655 655
656 static void testTruncateSync() { 656 static void testTruncateSync() {
657 File file = new File(tempDirectory.path + "/out_truncate_sync"); 657 File file = new File(tempDirectory.path + "/out_truncate_sync");
658 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; 658 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65];
659 RandomAccessFile openedFile = file.openSync(mode: WRITE); 659 RandomAccessFile openedFile = file.openSync(mode: WRITE);
660 openedFile.writeListSync(buffer, 0, 10); 660 openedFile.writeFromSync(buffer, 0, 10);
661 Expect.equals(10, openedFile.lengthSync()); 661 Expect.equals(10, openedFile.lengthSync());
662 openedFile.truncateSync(5); 662 openedFile.truncateSync(5);
663 Expect.equals(5, openedFile.lengthSync()); 663 Expect.equals(5, openedFile.lengthSync());
664 openedFile.closeSync(); 664 openedFile.closeSync();
665 file.deleteSync(); 665 file.deleteSync();
666 Expect.isFalse(file.existsSync()); 666 Expect.isFalse(file.existsSync());
667 } 667 }
668 668
669 // Tests exception handling after file was closed. 669 // Tests exception handling after file was closed.
670 static void testCloseException() { 670 static void testCloseException() {
(...skipping 27 matching lines...) Expand all
698 } on FileIOException catch (ex) { 698 } on FileIOException catch (ex) {
699 exceptionCaught = true; 699 exceptionCaught = true;
700 } on Exception catch (ex) { 700 } on Exception catch (ex) {
701 wrongExceptionCaught = true; 701 wrongExceptionCaught = true;
702 } 702 }
703 Expect.equals(true, exceptionCaught); 703 Expect.equals(true, exceptionCaught);
704 Expect.equals(true, !wrongExceptionCaught); 704 Expect.equals(true, !wrongExceptionCaught);
705 exceptionCaught = false; 705 exceptionCaught = false;
706 try { 706 try {
707 List<int> buffer = new List<int>(100); 707 List<int> buffer = new List<int>(100);
708 openedFile.readListSync(buffer, 0, 10); 708 openedFile.readIntoSync(buffer, 0, 10);
709 } on FileIOException catch (ex) { 709 } on FileIOException catch (ex) {
710 exceptionCaught = true; 710 exceptionCaught = true;
711 } on Exception catch (ex) { 711 } on Exception catch (ex) {
712 wrongExceptionCaught = true; 712 wrongExceptionCaught = true;
713 } 713 }
714 Expect.equals(true, exceptionCaught); 714 Expect.equals(true, exceptionCaught);
715 Expect.equals(true, !wrongExceptionCaught); 715 Expect.equals(true, !wrongExceptionCaught);
716 exceptionCaught = false; 716 exceptionCaught = false;
717 try { 717 try {
718 List<int> buffer = new List<int>(100); 718 List<int> buffer = new List<int>(100);
719 openedFile.writeListSync(buffer, 0, 10); 719 openedFile.writeFromSync(buffer, 0, 10);
720 } on FileIOException catch (ex) { 720 } on FileIOException catch (ex) {
721 exceptionCaught = true; 721 exceptionCaught = true;
722 } on Exception catch (ex) { 722 } on Exception catch (ex) {
723 wrongExceptionCaught = true; 723 wrongExceptionCaught = true;
724 } 724 }
725 Expect.equals(true, exceptionCaught); 725 Expect.equals(true, exceptionCaught);
726 Expect.equals(true, !wrongExceptionCaught); 726 Expect.equals(true, !wrongExceptionCaught);
727 exceptionCaught = false; 727 exceptionCaught = false;
728 try { 728 try {
729 openedFile.positionSync(); 729 openedFile.positionSync();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 775
776 // Tests buffer out of bounds exception. 776 // Tests buffer out of bounds exception.
777 static void testBufferOutOfBoundsException() { 777 static void testBufferOutOfBoundsException() {
778 bool exceptionCaught = false; 778 bool exceptionCaught = false;
779 bool wrongExceptionCaught = false; 779 bool wrongExceptionCaught = false;
780 File file = 780 File file =
781 new File(tempDirectory.path + "/out_buffer_out_of_bounds"); 781 new File(tempDirectory.path + "/out_buffer_out_of_bounds");
782 RandomAccessFile openedFile = file.openSync(mode: WRITE); 782 RandomAccessFile openedFile = file.openSync(mode: WRITE);
783 try { 783 try {
784 List<int> buffer = new List<int>(10); 784 List<int> buffer = new List<int>(10);
785 openedFile.readListSync(buffer, 0, 12); 785 openedFile.readIntoSync(buffer, 0, 12);
786 } on RangeError catch (ex) { 786 } on RangeError catch (ex) {
787 exceptionCaught = true; 787 exceptionCaught = true;
788 } on Exception catch (ex) { 788 } on Exception catch (ex) {
789 wrongExceptionCaught = true; 789 wrongExceptionCaught = true;
790 } 790 }
791 Expect.equals(true, exceptionCaught); 791 Expect.equals(true, exceptionCaught);
792 Expect.equals(true, !wrongExceptionCaught); 792 Expect.equals(true, !wrongExceptionCaught);
793 exceptionCaught = false; 793 exceptionCaught = false;
794 try { 794 try {
795 List<int> buffer = new List<int>(10); 795 List<int> buffer = new List<int>(10);
796 openedFile.readListSync(buffer, 6, 6); 796 openedFile.readIntoSync(buffer, 6, 12);
797 } on RangeError catch (ex) { 797 } on RangeError catch (ex) {
798 exceptionCaught = true; 798 exceptionCaught = true;
799 } on Exception catch (ex) { 799 } on Exception catch (ex) {
800 wrongExceptionCaught = true; 800 wrongExceptionCaught = true;
801 } 801 }
802 Expect.equals(true, exceptionCaught); 802 Expect.equals(true, exceptionCaught);
803 Expect.equals(true, !wrongExceptionCaught); 803 Expect.equals(true, !wrongExceptionCaught);
804 exceptionCaught = false; 804 exceptionCaught = false;
805 try { 805 try {
806 List<int> buffer = new List<int>(10); 806 List<int> buffer = new List<int>(10);
807 openedFile.readListSync(buffer, -1, 1); 807 openedFile.readIntoSync(buffer, -1, 1);
808 } on RangeError catch (ex) { 808 } on RangeError catch (ex) {
809 exceptionCaught = true; 809 exceptionCaught = true;
810 } on Exception catch (ex) { 810 } on Exception catch (ex) {
811 wrongExceptionCaught = true; 811 wrongExceptionCaught = true;
812 } 812 }
813 Expect.equals(true, exceptionCaught); 813 Expect.equals(true, exceptionCaught);
814 Expect.equals(true, !wrongExceptionCaught); 814 Expect.equals(true, !wrongExceptionCaught);
815 exceptionCaught = false; 815 exceptionCaught = false;
816 try { 816 try {
817 List<int> buffer = new List<int>(10); 817 List<int> buffer = new List<int>(10);
818 openedFile.readListSync(buffer, 0, -1); 818 openedFile.readIntoSync(buffer, 0, -1);
819 } on RangeError catch (ex) { 819 } on RangeError catch (ex) {
820 exceptionCaught = true; 820 exceptionCaught = true;
821 } on Exception catch (ex) { 821 } on Exception catch (ex) {
822 wrongExceptionCaught = true; 822 wrongExceptionCaught = true;
823 } 823 }
824 Expect.equals(true, exceptionCaught); 824 Expect.equals(true, exceptionCaught);
825 Expect.equals(true, !wrongExceptionCaught); 825 Expect.equals(true, !wrongExceptionCaught);
826 exceptionCaught = false; 826 exceptionCaught = false;
827 try { 827 try {
828 List<int> buffer = new List<int>(10); 828 List<int> buffer = new List<int>(10);
829 openedFile.writeListSync(buffer, 0, 12); 829 openedFile.writeFromSync(buffer, 0, 12);
830 } on RangeError catch (ex) { 830 } on RangeError catch (ex) {
831 exceptionCaught = true; 831 exceptionCaught = true;
832 } on Exception catch (ex) { 832 } on Exception catch (ex) {
833 wrongExceptionCaught = true; 833 wrongExceptionCaught = true;
834 } 834 }
835 Expect.equals(true, exceptionCaught); 835 Expect.equals(true, exceptionCaught);
836 Expect.equals(true, !wrongExceptionCaught); 836 Expect.equals(true, !wrongExceptionCaught);
837 exceptionCaught = false; 837 exceptionCaught = false;
838 try { 838 try {
839 List<int> buffer = new List<int>(10); 839 List<int> buffer = new List<int>(10);
840 openedFile.writeListSync(buffer, 6, 6); 840 openedFile.writeFromSync(buffer, 6, 12);
841 } on RangeError catch (ex) { 841 } on RangeError catch (ex) {
842 exceptionCaught = true; 842 exceptionCaught = true;
843 } on Exception catch (ex) { 843 } on Exception catch (ex) {
844 wrongExceptionCaught = true; 844 wrongExceptionCaught = true;
845 } 845 }
846 Expect.equals(true, exceptionCaught); 846 Expect.equals(true, exceptionCaught);
847 Expect.equals(true, !wrongExceptionCaught); 847 Expect.equals(true, !wrongExceptionCaught);
848 exceptionCaught = false; 848 exceptionCaught = false;
849 try { 849 try {
850 List<int> buffer = new List<int>(10); 850 List<int> buffer = new List<int>(10);
851 openedFile.writeListSync(buffer, -1, 1); 851 openedFile.writeFromSync(buffer, -1, 1);
852 } on RangeError catch (ex) { 852 } on RangeError catch (ex) {
853 exceptionCaught = true; 853 exceptionCaught = true;
854 } on Exception catch (ex) { 854 } on Exception catch (ex) {
855 wrongExceptionCaught = true; 855 wrongExceptionCaught = true;
856 } 856 }
857 Expect.equals(true, exceptionCaught); 857 Expect.equals(true, exceptionCaught);
858 Expect.equals(true, !wrongExceptionCaught); 858 Expect.equals(true, !wrongExceptionCaught);
859 exceptionCaught = false; 859 exceptionCaught = false;
860 try { 860 try {
861 List<int> buffer = new List<int>(10); 861 List<int> buffer = new List<int>(10);
862 openedFile.writeListSync(buffer, 0, -1); 862 openedFile.writeFromSync(buffer, 0, -1);
863 } on RangeError catch (ex) { 863 } on RangeError catch (ex) {
864 exceptionCaught = true; 864 exceptionCaught = true;
865 } on Exception catch (ex) { 865 } on Exception catch (ex) {
866 wrongExceptionCaught = true; 866 wrongExceptionCaught = true;
867 } 867 }
868 Expect.equals(true, exceptionCaught); 868 Expect.equals(true, exceptionCaught);
869 Expect.equals(true, !wrongExceptionCaught); 869 Expect.equals(true, !wrongExceptionCaught);
870 openedFile.closeSync(); 870 openedFile.closeSync();
871 file.deleteSync(); 871 file.deleteSync();
872 } 872 }
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 testDirectorySync(); 1237 testDirectorySync();
1238 testWriteStringUtf8(); 1238 testWriteStringUtf8();
1239 testWriteStringUtf8Sync(); 1239 testWriteStringUtf8Sync();
1240 }); 1240 });
1241 } 1241 }
1242 } 1242 }
1243 1243
1244 main() { 1244 main() {
1245 FileTest.testMain(); 1245 FileTest.testMain();
1246 } 1246 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698