OLD | NEW |
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 }); | 114 }); |
115 }); | 115 }); |
116 }); | 116 }); |
117 } | 117 } |
118 | 118 |
119 // Test for file stream buffered handling of large files. | 119 // Test for file stream buffered handling of large files. |
120 static void testReadWriteStreamLargeFile() { | 120 static void testReadWriteStreamLargeFile() { |
121 asyncTestStarted(); | 121 asyncTestStarted(); |
122 | 122 |
123 // Create the test data - arbitrary binary data. | 123 // Create the test data - arbitrary binary data. |
124 List<int> buffer = new List<int>.fixedLength(100000); | 124 List<int> buffer = new List<int>(100000); |
125 for (var i = 0; i < buffer.length; ++i) { | 125 for (var i = 0; i < buffer.length; ++i) { |
126 buffer[i] = i % 256; | 126 buffer[i] = i % 256; |
127 } | 127 } |
128 String filename = | 128 String filename = |
129 tempDirectory.path.concat("/out_read_write_stream_large_file"); | 129 tempDirectory.path.concat("/out_read_write_stream_large_file"); |
130 File file = new File(filename); | 130 File file = new File(filename); |
131 IOSink output = file.openWrite(); | 131 IOSink output = file.openWrite(); |
132 output.add(buffer); | 132 output.add(buffer); |
133 output.add(buffer); | 133 output.add(buffer); |
134 output.close(); | 134 output.close(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 }); | 194 }); |
195 return done.future; | 195 return done.future; |
196 } | 196 } |
197 | 197 |
198 static void testRead() { | 198 static void testRead() { |
199 ReceivePort port = new ReceivePort(); | 199 ReceivePort port = new ReceivePort(); |
200 // Read a file and check part of it's contents. | 200 // Read a file and check part of it's contents. |
201 String filename = getFilename("bin/file_test.cc"); | 201 String filename = getFilename("bin/file_test.cc"); |
202 File file = new File(filename); | 202 File file = new File(filename); |
203 file.open(FileMode.READ).then((RandomAccessFile file) { | 203 file.open(FileMode.READ).then((RandomAccessFile file) { |
204 List<int> buffer = new List<int>.fixedLength(10); | 204 List<int> buffer = new List<int>(10); |
205 file.readList(buffer, 0, 5).then((bytes_read) { | 205 file.readList(buffer, 0, 5).then((bytes_read) { |
206 Expect.equals(5, bytes_read); | 206 Expect.equals(5, bytes_read); |
207 file.readList(buffer, 5, 5).then((bytes_read) { | 207 file.readList(buffer, 5, 5).then((bytes_read) { |
208 Expect.equals(5, bytes_read); | 208 Expect.equals(5, bytes_read); |
209 Expect.equals(47, buffer[0]); // represents '/' in the file. | 209 Expect.equals(47, buffer[0]); // represents '/' in the file. |
210 Expect.equals(47, buffer[1]); // represents '/' in the file. | 210 Expect.equals(47, buffer[1]); // represents '/' in the file. |
211 Expect.equals(32, buffer[2]); // represents ' ' in the file. | 211 Expect.equals(32, buffer[2]); // represents ' ' in the file. |
212 Expect.equals(67, buffer[3]); // represents 'C' in the file. | 212 Expect.equals(67, buffer[3]); // represents 'C' in the file. |
213 Expect.equals(111, buffer[4]); // represents 'o' in the file. | 213 Expect.equals(111, buffer[4]); // represents 'o' in the file. |
214 Expect.equals(112, buffer[5]); // represents 'p' in the file. | 214 Expect.equals(112, buffer[5]); // represents 'p' in the file. |
215 Expect.equals(121, buffer[6]); // represents 'y' in the file. | 215 Expect.equals(121, buffer[6]); // represents 'y' in the file. |
216 Expect.equals(114, buffer[7]); // represents 'r' in the file. | 216 Expect.equals(114, buffer[7]); // represents 'r' in the file. |
217 Expect.equals(105, buffer[8]); // represents 'i' in the file. | 217 Expect.equals(105, buffer[8]); // represents 'i' in the file. |
218 Expect.equals(103, buffer[9]); // represents 'g' in the file. | 218 Expect.equals(103, buffer[9]); // represents 'g' in the file. |
219 file.close().then((ignore) => port.close()); | 219 file.close().then((ignore) => port.close()); |
220 }); | 220 }); |
221 }); | 221 }); |
222 }); | 222 }); |
223 } | 223 } |
224 | 224 |
225 static void testReadSync() { | 225 static void testReadSync() { |
226 // Read a file and check part of it's contents. | 226 // Read a file and check part of it's contents. |
227 String filename = getFilename("bin/file_test.cc"); | 227 String filename = getFilename("bin/file_test.cc"); |
228 RandomAccessFile file = (new File(filename)).openSync(); | 228 RandomAccessFile file = (new File(filename)).openSync(); |
229 List<int> buffer = new List<int>.fixedLength(42); | 229 List<int> buffer = new List<int>(42); |
230 int bytes_read = 0; | 230 int bytes_read = 0; |
231 bytes_read = file.readListSync(buffer, 0, 12); | 231 bytes_read = file.readListSync(buffer, 0, 12); |
232 Expect.equals(12, bytes_read); | 232 Expect.equals(12, bytes_read); |
233 bytes_read = file.readListSync(buffer, 12, 30); | 233 bytes_read = file.readListSync(buffer, 12, 30); |
234 Expect.equals(30, bytes_read); | 234 Expect.equals(30, bytes_read); |
235 Expect.equals(47, buffer[0]); // represents '/' in the file. | 235 Expect.equals(47, buffer[0]); // represents '/' in the file. |
236 Expect.equals(47, buffer[1]); // represents '/' in the file. | 236 Expect.equals(47, buffer[1]); // represents '/' in the file. |
237 Expect.equals(32, buffer[2]); // represents ' ' in the file. | 237 Expect.equals(32, buffer[2]); // represents ' ' in the file. |
238 Expect.equals(67, buffer[3]); // represents 'C' in the file. | 238 Expect.equals(67, buffer[3]); // represents 'C' in the file. |
239 Expect.equals(111, buffer[4]); // represents 'o' in the file. | 239 Expect.equals(111, buffer[4]); // represents 'o' in the file. |
240 Expect.equals(112, buffer[5]); // represents 'p' in the file. | 240 Expect.equals(112, buffer[5]); // represents 'p' in the file. |
241 Expect.equals(121, buffer[6]); // represents 'y' in the file. | 241 Expect.equals(121, buffer[6]); // represents 'y' in the file. |
242 Expect.equals(114, buffer[7]); // represents 'r' in the file. | 242 Expect.equals(114, buffer[7]); // represents 'r' in the file. |
243 Expect.equals(105, buffer[8]); // represents 'i' in the file. | 243 Expect.equals(105, buffer[8]); // represents 'i' in the file. |
244 Expect.equals(103, buffer[9]); // represents 'g' in the file. | 244 Expect.equals(103, buffer[9]); // represents 'g' in the file. |
245 Expect.equals(104, buffer[10]); // represents 'h' in the file. | 245 Expect.equals(104, buffer[10]); // represents 'h' in the file. |
246 Expect.equals(116, buffer[11]); // represents 't' in the file. | 246 Expect.equals(116, buffer[11]); // represents 't' in the file. |
247 } | 247 } |
248 | 248 |
249 // Test for file read and write functionality. | 249 // Test for file read and write functionality. |
250 static void testReadWrite() { | 250 static void testReadWrite() { |
251 // Read a file. | 251 // Read a file. |
252 String inFilename = getFilename("tests/vm/data/fixed_length_file"); | 252 String inFilename = getFilename("tests/vm/data/fixed_length_file"); |
253 final File file = new File(inFilename); | 253 final File file = new File(inFilename); |
254 file.open(FileMode.READ).then((openedFile) { | 254 file.open(FileMode.READ).then((openedFile) { |
255 List<int> buffer1 = new List<int>.fixedLength(42); | 255 List<int> buffer1 = new List<int>(42); |
256 openedFile.readList(buffer1, 0, 42).then((bytes_read) { | 256 openedFile.readList(buffer1, 0, 42).then((bytes_read) { |
257 Expect.equals(42, bytes_read); | 257 Expect.equals(42, bytes_read); |
258 openedFile.close().then((ignore) { | 258 openedFile.close().then((ignore) { |
259 // Write the contents of the file just read into another file. | 259 // Write the contents of the file just read into another file. |
260 String outFilename = tempDirectory.path.concat("/out_read_write"); | 260 String outFilename = tempDirectory.path.concat("/out_read_write"); |
261 final File file2 = new File(outFilename); | 261 final File file2 = new File(outFilename); |
262 file2.create().then((ignore) { | 262 file2.create().then((ignore) { |
263 file2.fullPath().then((s) { | 263 file2.fullPath().then((s) { |
264 Expect.isTrue(new File(s).existsSync()); | 264 Expect.isTrue(new File(s).existsSync()); |
265 if (s[0] != '/' && s[0] != '\\' && s[1] != ':') { | 265 if (s[0] != '/' && s[0] != '\\' && s[1] != ':') { |
266 Expect.fail("Not a full path"); | 266 Expect.fail("Not a full path"); |
267 } | 267 } |
268 file2.open(FileMode.WRITE).then((openedFile2) { | 268 file2.open(FileMode.WRITE).then((openedFile2) { |
269 openedFile2.writeList(buffer1, 0, bytes_read).then((ignore) { | 269 openedFile2.writeList(buffer1, 0, bytes_read).then((ignore) { |
270 openedFile2.close().then((ignore) { | 270 openedFile2.close().then((ignore) { |
271 List<int> buffer2 = new List<int>.fixedLength(bytes_read); | 271 List<int> buffer2 = new List<int>(bytes_read); |
272 final File file3 = new File(outFilename); | 272 final File file3 = new File(outFilename); |
273 file3.open(FileMode.READ).then((openedFile3) { | 273 file3.open(FileMode.READ).then((openedFile3) { |
274 openedFile3.readList(buffer2, 0, 42).then((bytes_read) { | 274 openedFile3.readList(buffer2, 0, 42).then((bytes_read) { |
275 Expect.equals(42, bytes_read); | 275 Expect.equals(42, bytes_read); |
276 openedFile3.close().then((ignore) { | 276 openedFile3.close().then((ignore) { |
277 // Now compare the two buffers to check if they | 277 // Now compare the two buffers to check if they |
278 // are identical. | 278 // are identical. |
279 Expect.equals(buffer1.length, buffer2.length); | 279 Expect.equals(buffer1.length, buffer2.length); |
280 for (int i = 0; i < buffer1.length; i++) { | 280 for (int i = 0; i < buffer1.length; i++) { |
281 Expect.equals(buffer1[i], buffer2[i]); | 281 Expect.equals(buffer1[i], buffer2[i]); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 }); | 379 }); |
380 }); | 380 }); |
381 asyncTestStarted(); | 381 asyncTestStarted(); |
382 } | 382 } |
383 | 383 |
384 | 384 |
385 static void testReadWriteSync() { | 385 static void testReadWriteSync() { |
386 // Read a file. | 386 // Read a file. |
387 String inFilename = getFilename("tests/vm/data/fixed_length_file"); | 387 String inFilename = getFilename("tests/vm/data/fixed_length_file"); |
388 RandomAccessFile file = (new File(inFilename)).openSync(); | 388 RandomAccessFile file = (new File(inFilename)).openSync(); |
389 List<int> buffer1 = new List<int>.fixedLength(42); | 389 List<int> buffer1 = new List<int>(42); |
390 int bytes_read = 0; | 390 int bytes_read = 0; |
391 int bytes_written = 0; | 391 int bytes_written = 0; |
392 bytes_read = file.readListSync(buffer1, 0, 42); | 392 bytes_read = file.readListSync(buffer1, 0, 42); |
393 Expect.equals(42, bytes_read); | 393 Expect.equals(42, bytes_read); |
394 file.closeSync(); | 394 file.closeSync(); |
395 // Write the contents of the file just read into another file. | 395 // Write the contents of the file just read into another file. |
396 String outFilename = tempDirectory.path.concat("/out_read_write_sync"); | 396 String outFilename = tempDirectory.path.concat("/out_read_write_sync"); |
397 File outFile = new File(outFilename); | 397 File outFile = new File(outFilename); |
398 outFile.createSync(); | 398 outFile.createSync(); |
399 String path = outFile.fullPathSync(); | 399 String path = outFile.fullPathSync(); |
400 if (path[0] != '/' && path[0] != '\\' && path[1] != ':') { | 400 if (path[0] != '/' && path[0] != '\\' && path[1] != ':') { |
401 Expect.fail("Not a full path"); | 401 Expect.fail("Not a full path"); |
402 } | 402 } |
403 Expect.isTrue(new File(path).existsSync()); | 403 Expect.isTrue(new File(path).existsSync()); |
404 RandomAccessFile openedFile = outFile.openSync(FileMode.WRITE); | 404 RandomAccessFile openedFile = outFile.openSync(FileMode.WRITE); |
405 openedFile.writeListSync(buffer1, 0, bytes_read); | 405 openedFile.writeListSync(buffer1, 0, bytes_read); |
406 openedFile.closeSync(); | 406 openedFile.closeSync(); |
407 // Now read the contents of the file just written. | 407 // Now read the contents of the file just written. |
408 List<int> buffer2 = new List<int>.fixedLength(bytes_read); | 408 List<int> buffer2 = new List<int>(bytes_read); |
409 openedFile = (new File(outFilename)).openSync(); | 409 openedFile = (new File(outFilename)).openSync(); |
410 bytes_read = openedFile.readListSync(buffer2, 0, 42); | 410 bytes_read = openedFile.readListSync(buffer2, 0, 42); |
411 Expect.equals(42, bytes_read); | 411 Expect.equals(42, bytes_read); |
412 openedFile.closeSync(); | 412 openedFile.closeSync(); |
413 // Now compare the two buffers to check if they are identical. | 413 // Now compare the two buffers to check if they are identical. |
414 Expect.equals(buffer1.length, buffer2.length); | 414 Expect.equals(buffer1.length, buffer2.length); |
415 for (int i = 0; i < buffer1.length; i++) { | 415 for (int i = 0; i < buffer1.length; i++) { |
416 Expect.equals(buffer1[i], buffer2[i]); | 416 Expect.equals(buffer1[i], buffer2[i]); |
417 } | 417 } |
418 // Delete the output file. | 418 // Delete the output file. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 openedFile.writeList(new MyListOfOneElement(262), 0, 1); | 466 openedFile.writeList(new MyListOfOneElement(262), 0, 1); |
467 x = 12345678901234567890123456789012345678901234567890; | 467 x = 12345678901234567890123456789012345678901234567890; |
468 y = 12345678901234567890123456789012345678901234568153; | 468 y = 12345678901234567890123456789012345678901234568153; |
469 openedFile.writeList([y - x], 0, 1).then((ignore) { | 469 openedFile.writeList([y - x], 0, 1).then((ignore) { |
470 openedFile.close().then((ignore) { | 470 openedFile.close().then((ignore) { |
471 // Check the written bytes. | 471 // Check the written bytes. |
472 final File file2 = new File(fileName); | 472 final File file2 = new File(fileName); |
473 var openedFile2 = file2.openSync(); | 473 var openedFile2 = file2.openSync(); |
474 var length = openedFile2.lengthSync(); | 474 var length = openedFile2.lengthSync(); |
475 Expect.equals(8, length); | 475 Expect.equals(8, length); |
476 List data = new List.fixedLength(length); | 476 List data = new List(length); |
477 openedFile2.readListSync(data, 0, length); | 477 openedFile2.readListSync(data, 0, length); |
478 for (var i = 0; i < data.length; i++) { | 478 for (var i = 0; i < data.length; i++) { |
479 Expect.equals(i, data[i]); | 479 Expect.equals(i, data[i]); |
480 } | 480 } |
481 openedFile2.closeSync(); | 481 openedFile2.closeSync(); |
482 file2.deleteSync(); | 482 file2.deleteSync(); |
483 asyncTestDone("testWriteVariousLists"); | 483 asyncTestDone("testWriteVariousLists"); |
484 }); | 484 }); |
485 }); | 485 }); |
486 }); | 486 }); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 openedFile.closeSync(); | 570 openedFile.closeSync(); |
571 } | 571 } |
572 | 572 |
573 // Test for file position functionality. | 573 // Test for file position functionality. |
574 static void testPosition() { | 574 static void testPosition() { |
575 var port = new ReceivePort(); | 575 var port = new ReceivePort(); |
576 String filename = getFilename("tests/vm/data/fixed_length_file"); | 576 String filename = getFilename("tests/vm/data/fixed_length_file"); |
577 RandomAccessFile input = (new File(filename)).openSync(); | 577 RandomAccessFile input = (new File(filename)).openSync(); |
578 input.position().then((position) { | 578 input.position().then((position) { |
579 Expect.equals(0, position); | 579 Expect.equals(0, position); |
580 List<int> buffer = new List<int>.fixedLength(100); | 580 List<int> buffer = new List<int>(100); |
581 input.readList(buffer, 0, 12).then((bytes_read) { | 581 input.readList(buffer, 0, 12).then((bytes_read) { |
582 input.position().then((position) { | 582 input.position().then((position) { |
583 Expect.equals(12, position); | 583 Expect.equals(12, position); |
584 input.readList(buffer, 12, 6).then((bytes_read) { | 584 input.readList(buffer, 12, 6).then((bytes_read) { |
585 input.position().then((position) { | 585 input.position().then((position) { |
586 Expect.equals(18, position); | 586 Expect.equals(18, position); |
587 input.setPosition(8).then((ignore) { | 587 input.setPosition(8).then((ignore) { |
588 input.position().then((position) { | 588 input.position().then((position) { |
589 Expect.equals(8, position); | 589 Expect.equals(8, position); |
590 input.close().then((ignore) => port.close()); | 590 input.close().then((ignore) => port.close()); |
591 }); | 591 }); |
592 }); | 592 }); |
593 }); | 593 }); |
594 }); | 594 }); |
595 }); | 595 }); |
596 }); | 596 }); |
597 }); | 597 }); |
598 } | 598 } |
599 | 599 |
600 static void testPositionSync() { | 600 static void testPositionSync() { |
601 String filename = getFilename("tests/vm/data/fixed_length_file"); | 601 String filename = getFilename("tests/vm/data/fixed_length_file"); |
602 RandomAccessFile input = (new File(filename)).openSync(); | 602 RandomAccessFile input = (new File(filename)).openSync(); |
603 Expect.equals(0, input.positionSync()); | 603 Expect.equals(0, input.positionSync()); |
604 List<int> buffer = new List<int>.fixedLength(100); | 604 List<int> buffer = new List<int>(100); |
605 input.readListSync(buffer, 0, 12); | 605 input.readListSync(buffer, 0, 12); |
606 Expect.equals(12, input.positionSync()); | 606 Expect.equals(12, input.positionSync()); |
607 input.readListSync(buffer, 12, 6); | 607 input.readListSync(buffer, 12, 6); |
608 Expect.equals(18, input.positionSync()); | 608 Expect.equals(18, input.positionSync()); |
609 input.setPositionSync(8); | 609 input.setPositionSync(8); |
610 Expect.equals(8, input.positionSync()); | 610 Expect.equals(8, input.positionSync()); |
611 input.closeSync(); | 611 input.closeSync(); |
612 } | 612 } |
613 | 613 |
614 static void testTruncate() { | 614 static void testTruncate() { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 openedFile.writeStringSync("Test"); | 681 openedFile.writeStringSync("Test"); |
682 } on FileIOException catch (ex) { | 682 } on FileIOException catch (ex) { |
683 exceptionCaught = true; | 683 exceptionCaught = true; |
684 } on Exception catch (ex) { | 684 } on Exception catch (ex) { |
685 wrongExceptionCaught = true; | 685 wrongExceptionCaught = true; |
686 } | 686 } |
687 Expect.equals(true, exceptionCaught); | 687 Expect.equals(true, exceptionCaught); |
688 Expect.equals(true, !wrongExceptionCaught); | 688 Expect.equals(true, !wrongExceptionCaught); |
689 exceptionCaught = false; | 689 exceptionCaught = false; |
690 try { | 690 try { |
691 List<int> buffer = new List<int>.fixedLength(100); | 691 List<int> buffer = new List<int>(100); |
692 openedFile.readListSync(buffer, 0, 10); | 692 openedFile.readListSync(buffer, 0, 10); |
693 } on FileIOException catch (ex) { | 693 } on FileIOException catch (ex) { |
694 exceptionCaught = true; | 694 exceptionCaught = true; |
695 } on Exception catch (ex) { | 695 } on Exception catch (ex) { |
696 wrongExceptionCaught = true; | 696 wrongExceptionCaught = true; |
697 } | 697 } |
698 Expect.equals(true, exceptionCaught); | 698 Expect.equals(true, exceptionCaught); |
699 Expect.equals(true, !wrongExceptionCaught); | 699 Expect.equals(true, !wrongExceptionCaught); |
700 exceptionCaught = false; | 700 exceptionCaught = false; |
701 try { | 701 try { |
702 List<int> buffer = new List<int>.fixedLength(100); | 702 List<int> buffer = new List<int>(100); |
703 openedFile.writeListSync(buffer, 0, 10); | 703 openedFile.writeListSync(buffer, 0, 10); |
704 } on FileIOException catch (ex) { | 704 } on FileIOException catch (ex) { |
705 exceptionCaught = true; | 705 exceptionCaught = true; |
706 } on Exception catch (ex) { | 706 } on Exception catch (ex) { |
707 wrongExceptionCaught = true; | 707 wrongExceptionCaught = true; |
708 } | 708 } |
709 Expect.equals(true, exceptionCaught); | 709 Expect.equals(true, exceptionCaught); |
710 Expect.equals(true, !wrongExceptionCaught); | 710 Expect.equals(true, !wrongExceptionCaught); |
711 exceptionCaught = false; | 711 exceptionCaught = false; |
712 try { | 712 try { |
(...skipping 24 matching lines...) Expand all Loading... |
737 wrongExceptionCaught = true; | 737 wrongExceptionCaught = true; |
738 } | 738 } |
739 Expect.equals(true, exceptionCaught); | 739 Expect.equals(true, exceptionCaught); |
740 Expect.equals(true, !wrongExceptionCaught); | 740 Expect.equals(true, !wrongExceptionCaught); |
741 input.deleteSync(); | 741 input.deleteSync(); |
742 } | 742 } |
743 | 743 |
744 // Tests stream exception handling after file was closed. | 744 // Tests stream exception handling after file was closed. |
745 static void testCloseExceptionStream() { | 745 static void testCloseExceptionStream() { |
746 asyncTestStarted(); | 746 asyncTestStarted(); |
747 List<int> buffer = new List<int>.fixedLength(42); | 747 List<int> buffer = new List<int>(42); |
748 File file = | 748 File file = |
749 new File(tempDirectory.path.concat("/out_close_exception_stream")); | 749 new File(tempDirectory.path.concat("/out_close_exception_stream")); |
750 file.createSync(); | 750 file.createSync(); |
751 var output = file.openWrite(); | 751 var output = file.openWrite(); |
752 output.close(); | 752 output.close(); |
753 Expect.throws(() => output.add(buffer)); | 753 Expect.throws(() => output.add(buffer)); |
754 output.done.then((_) { | 754 output.done.then((_) { |
755 file.deleteSync(); | 755 file.deleteSync(); |
756 asyncTestDone("testCloseExceptionStream"); | 756 asyncTestDone("testCloseExceptionStream"); |
757 }); | 757 }); |
758 } | 758 } |
759 | 759 |
760 // Tests buffer out of bounds exception. | 760 // Tests buffer out of bounds exception. |
761 static void testBufferOutOfBoundsException() { | 761 static void testBufferOutOfBoundsException() { |
762 bool exceptionCaught = false; | 762 bool exceptionCaught = false; |
763 bool wrongExceptionCaught = false; | 763 bool wrongExceptionCaught = false; |
764 File file = | 764 File file = |
765 new File(tempDirectory.path.concat("/out_buffer_out_of_bounds")); | 765 new File(tempDirectory.path.concat("/out_buffer_out_of_bounds")); |
766 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); | 766 RandomAccessFile openedFile = file.openSync(FileMode.WRITE); |
767 try { | 767 try { |
768 List<int> buffer = new List<int>.fixedLength(10); | 768 List<int> buffer = new List<int>(10); |
769 openedFile.readListSync(buffer, 0, 12); | 769 openedFile.readListSync(buffer, 0, 12); |
770 } on RangeError catch (ex) { | 770 } on RangeError catch (ex) { |
771 exceptionCaught = true; | 771 exceptionCaught = true; |
772 } on Exception catch (ex) { | 772 } on Exception catch (ex) { |
773 wrongExceptionCaught = true; | 773 wrongExceptionCaught = true; |
774 } | 774 } |
775 Expect.equals(true, exceptionCaught); | 775 Expect.equals(true, exceptionCaught); |
776 Expect.equals(true, !wrongExceptionCaught); | 776 Expect.equals(true, !wrongExceptionCaught); |
777 exceptionCaught = false; | 777 exceptionCaught = false; |
778 try { | 778 try { |
779 List<int> buffer = new List<int>.fixedLength(10); | 779 List<int> buffer = new List<int>(10); |
780 openedFile.readListSync(buffer, 6, 6); | 780 openedFile.readListSync(buffer, 6, 6); |
781 } on RangeError catch (ex) { | 781 } on RangeError catch (ex) { |
782 exceptionCaught = true; | 782 exceptionCaught = true; |
783 } on Exception catch (ex) { | 783 } on Exception catch (ex) { |
784 wrongExceptionCaught = true; | 784 wrongExceptionCaught = true; |
785 } | 785 } |
786 Expect.equals(true, exceptionCaught); | 786 Expect.equals(true, exceptionCaught); |
787 Expect.equals(true, !wrongExceptionCaught); | 787 Expect.equals(true, !wrongExceptionCaught); |
788 exceptionCaught = false; | 788 exceptionCaught = false; |
789 try { | 789 try { |
790 List<int> buffer = new List<int>.fixedLength(10); | 790 List<int> buffer = new List<int>(10); |
791 openedFile.readListSync(buffer, -1, 1); | 791 openedFile.readListSync(buffer, -1, 1); |
792 } on RangeError catch (ex) { | 792 } on RangeError catch (ex) { |
793 exceptionCaught = true; | 793 exceptionCaught = true; |
794 } on Exception catch (ex) { | 794 } on Exception catch (ex) { |
795 wrongExceptionCaught = true; | 795 wrongExceptionCaught = true; |
796 } | 796 } |
797 Expect.equals(true, exceptionCaught); | 797 Expect.equals(true, exceptionCaught); |
798 Expect.equals(true, !wrongExceptionCaught); | 798 Expect.equals(true, !wrongExceptionCaught); |
799 exceptionCaught = false; | 799 exceptionCaught = false; |
800 try { | 800 try { |
801 List<int> buffer = new List<int>.fixedLength(10); | 801 List<int> buffer = new List<int>(10); |
802 openedFile.readListSync(buffer, 0, -1); | 802 openedFile.readListSync(buffer, 0, -1); |
803 } on RangeError catch (ex) { | 803 } on RangeError catch (ex) { |
804 exceptionCaught = true; | 804 exceptionCaught = true; |
805 } on Exception catch (ex) { | 805 } on Exception catch (ex) { |
806 wrongExceptionCaught = true; | 806 wrongExceptionCaught = true; |
807 } | 807 } |
808 Expect.equals(true, exceptionCaught); | 808 Expect.equals(true, exceptionCaught); |
809 Expect.equals(true, !wrongExceptionCaught); | 809 Expect.equals(true, !wrongExceptionCaught); |
810 exceptionCaught = false; | 810 exceptionCaught = false; |
811 try { | 811 try { |
812 List<int> buffer = new List<int>.fixedLength(10); | 812 List<int> buffer = new List<int>(10); |
813 openedFile.writeListSync(buffer, 0, 12); | 813 openedFile.writeListSync(buffer, 0, 12); |
814 } on RangeError catch (ex) { | 814 } on RangeError catch (ex) { |
815 exceptionCaught = true; | 815 exceptionCaught = true; |
816 } on Exception catch (ex) { | 816 } on Exception catch (ex) { |
817 wrongExceptionCaught = true; | 817 wrongExceptionCaught = true; |
818 } | 818 } |
819 Expect.equals(true, exceptionCaught); | 819 Expect.equals(true, exceptionCaught); |
820 Expect.equals(true, !wrongExceptionCaught); | 820 Expect.equals(true, !wrongExceptionCaught); |
821 exceptionCaught = false; | 821 exceptionCaught = false; |
822 try { | 822 try { |
823 List<int> buffer = new List<int>.fixedLength(10); | 823 List<int> buffer = new List<int>(10); |
824 openedFile.writeListSync(buffer, 6, 6); | 824 openedFile.writeListSync(buffer, 6, 6); |
825 } on RangeError catch (ex) { | 825 } on RangeError catch (ex) { |
826 exceptionCaught = true; | 826 exceptionCaught = true; |
827 } on Exception catch (ex) { | 827 } on Exception catch (ex) { |
828 wrongExceptionCaught = true; | 828 wrongExceptionCaught = true; |
829 } | 829 } |
830 Expect.equals(true, exceptionCaught); | 830 Expect.equals(true, exceptionCaught); |
831 Expect.equals(true, !wrongExceptionCaught); | 831 Expect.equals(true, !wrongExceptionCaught); |
832 exceptionCaught = false; | 832 exceptionCaught = false; |
833 try { | 833 try { |
834 List<int> buffer = new List<int>.fixedLength(10); | 834 List<int> buffer = new List<int>(10); |
835 openedFile.writeListSync(buffer, -1, 1); | 835 openedFile.writeListSync(buffer, -1, 1); |
836 } on RangeError catch (ex) { | 836 } on RangeError catch (ex) { |
837 exceptionCaught = true; | 837 exceptionCaught = true; |
838 } on Exception catch (ex) { | 838 } on Exception catch (ex) { |
839 wrongExceptionCaught = true; | 839 wrongExceptionCaught = true; |
840 } | 840 } |
841 Expect.equals(true, exceptionCaught); | 841 Expect.equals(true, exceptionCaught); |
842 Expect.equals(true, !wrongExceptionCaught); | 842 Expect.equals(true, !wrongExceptionCaught); |
843 exceptionCaught = false; | 843 exceptionCaught = false; |
844 try { | 844 try { |
845 List<int> buffer = new List<int>.fixedLength(10); | 845 List<int> buffer = new List<int>(10); |
846 openedFile.writeListSync(buffer, 0, -1); | 846 openedFile.writeListSync(buffer, 0, -1); |
847 } on RangeError catch (ex) { | 847 } on RangeError catch (ex) { |
848 exceptionCaught = true; | 848 exceptionCaught = true; |
849 } on Exception catch (ex) { | 849 } on Exception catch (ex) { |
850 wrongExceptionCaught = true; | 850 wrongExceptionCaught = true; |
851 } | 851 } |
852 Expect.equals(true, exceptionCaught); | 852 Expect.equals(true, exceptionCaught); |
853 Expect.equals(true, !wrongExceptionCaught); | 853 Expect.equals(true, !wrongExceptionCaught); |
854 openedFile.closeSync(); | 854 openedFile.closeSync(); |
855 file.deleteSync(); | 855 file.deleteSync(); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
OLD | NEW |