| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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); |
| 431 for (int i = 0; i < buffer1.length; i++) { |
| 432 Expect.equals(buffer1[i], buffer2[i]); |
| 433 } |
| 434 // Delete the output file. |
| 435 outFile.deleteSync(); |
| 436 Expect.isFalse(outFile.existsSync()); |
| 437 } |
| 438 |
| 439 static void testReadWriteNoArgsSync() { |
| 440 // Read a file. |
| 441 String inFilename = getFilename("tests/vm/data/fixed_length_file"); |
| 442 RandomAccessFile file = (new File(inFilename)).openSync(); |
| 443 List<int> buffer1 = new List<int>(42); |
| 444 int bytes_read = 0; |
| 445 int bytes_written = 0; |
| 446 bytes_read = file.readIntoSync(buffer1); |
| 447 Expect.equals(42, bytes_read); |
| 448 file.closeSync(); |
| 449 // Write the contents of the file just read into another file. |
| 450 String outFilename = tempDirectory.path + "/out_read_write_sync"; |
| 451 File outFile = new File(outFilename); |
| 452 outFile.createSync(); |
| 453 String path = outFile.fullPathSync(); |
| 454 if (path[0] != '/' && path[0] != '\\' && path[1] != ':') { |
| 455 Expect.fail("Not a full path"); |
| 456 } |
| 457 Expect.isTrue(new File(path).existsSync()); |
| 458 RandomAccessFile openedFile = outFile.openSync(mode: WRITE); |
| 459 openedFile.writeFromSync(buffer1); |
| 460 openedFile.closeSync(); |
| 461 // Now read the contents of the file just written. |
| 462 List<int> buffer2 = new List<int>(bytes_read); |
| 463 openedFile = (new File(outFilename)).openSync(); |
| 464 bytes_read = openedFile.readIntoSync(buffer2, 0); |
| 465 Expect.equals(42, bytes_read); |
| 466 openedFile.closeSync(); |
| 467 // Now compare the two buffers to check if they are identical. |
| 430 Expect.equals(buffer1.length, buffer2.length); | 468 Expect.equals(buffer1.length, buffer2.length); |
| 431 for (int i = 0; i < buffer1.length; i++) { | 469 for (int i = 0; i < buffer1.length; i++) { |
| 432 Expect.equals(buffer1[i], buffer2[i]); | 470 Expect.equals(buffer1[i], buffer2[i]); |
| 433 } | 471 } |
| 434 // Delete the output file. | 472 // Delete the output file. |
| 435 outFile.deleteSync(); | 473 outFile.deleteSync(); |
| 436 Expect.isFalse(outFile.existsSync()); | 474 Expect.isFalse(outFile.existsSync()); |
| 437 } | 475 } |
| 438 | 476 |
| 439 static void testReadEmptyFileSync() { | 477 static void testReadEmptyFileSync() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 464 } | 502 } |
| 465 | 503 |
| 466 // Test for file write of different types of lists. | 504 // Test for file write of different types of lists. |
| 467 static void testWriteVariousLists() { | 505 static void testWriteVariousLists() { |
| 468 asyncTestStarted(); | 506 asyncTestStarted(); |
| 469 final String fileName = "${tempDirectory.path}/testWriteVariousLists"; | 507 final String fileName = "${tempDirectory.path}/testWriteVariousLists"; |
| 470 final File file = new File(fileName); | 508 final File file = new File(fileName); |
| 471 file.create().then((ignore) { | 509 file.create().then((ignore) { |
| 472 file.open(mode: WRITE).then((RandomAccessFile openedFile) { | 510 file.open(mode: WRITE).then((RandomAccessFile openedFile) { |
| 473 // Write bytes from 0 to 7. | 511 // Write bytes from 0 to 7. |
| 474 openedFile.writeList([0], 0, 1); | 512 openedFile.writeFrom([0], 0, 1); |
| 475 openedFile.writeList(const [1], 0, 1); | 513 openedFile.writeFrom(const [1], 0, 1); |
| 476 openedFile.writeList(new MyListOfOneElement(2), 0, 1); | 514 openedFile.writeFrom(new MyListOfOneElement(2), 0, 1); |
| 477 var x = 12345678901234567890123456789012345678901234567890; | 515 var x = 12345678901234567890123456789012345678901234567890; |
| 478 var y = 12345678901234567890123456789012345678901234567893; | 516 var y = 12345678901234567890123456789012345678901234567893; |
| 479 openedFile.writeList([y - x], 0, 1); | 517 openedFile.writeFrom([y - x], 0, 1); |
| 480 openedFile.writeList([260], 0, 1); // 260 = 256 + 4 = 0x104. | 518 openedFile.writeFrom([260], 0, 1); // 260 = 256 + 4 = 0x104. |
| 481 openedFile.writeList(const [261], 0, 1); | 519 openedFile.writeFrom(const [261], 0, 1); |
| 482 openedFile.writeList(new MyListOfOneElement(262), 0, 1); | 520 openedFile.writeFrom(new MyListOfOneElement(262), 0, 1); |
| 483 x = 12345678901234567890123456789012345678901234567890; | 521 x = 12345678901234567890123456789012345678901234567890; |
| 484 y = 12345678901234567890123456789012345678901234568153; | 522 y = 12345678901234567890123456789012345678901234568153; |
| 485 openedFile.writeList([y - x], 0, 1).then((ignore) { | 523 openedFile.writeFrom([y - x], 0, 1).then((ignore) { |
| 486 openedFile.close().then((ignore) { | 524 openedFile.close().then((ignore) { |
| 487 // Check the written bytes. | 525 // Check the written bytes. |
| 488 final File file2 = new File(fileName); | 526 final File file2 = new File(fileName); |
| 489 var openedFile2 = file2.openSync(); | 527 var openedFile2 = file2.openSync(); |
| 490 var length = openedFile2.lengthSync(); | 528 var length = openedFile2.lengthSync(); |
| 491 Expect.equals(8, length); | 529 Expect.equals(8, length); |
| 492 List data = new List(length); | 530 List data = new List(length); |
| 493 openedFile2.readListSync(data, 0, length); | 531 openedFile2.readIntoSync(data, 0, length); |
| 494 for (var i = 0; i < data.length; i++) { | 532 for (var i = 0; i < data.length; i++) { |
| 495 Expect.equals(i, data[i]); | 533 Expect.equals(i, data[i]); |
| 496 } | 534 } |
| 497 openedFile2.closeSync(); | 535 openedFile2.closeSync(); |
| 498 file2.deleteSync(); | 536 file2.deleteSync(); |
| 499 asyncTestDone("testWriteVariousLists"); | 537 asyncTestDone("testWriteVariousLists"); |
| 500 }); | 538 }); |
| 501 }); | 539 }); |
| 502 }); | 540 }); |
| 503 }); | 541 }); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 } | 625 } |
| 588 | 626 |
| 589 // Test for file position functionality. | 627 // Test for file position functionality. |
| 590 static void testPosition() { | 628 static void testPosition() { |
| 591 var port = new ReceivePort(); | 629 var port = new ReceivePort(); |
| 592 String filename = getFilename("tests/vm/data/fixed_length_file"); | 630 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 593 RandomAccessFile input = (new File(filename)).openSync(); | 631 RandomAccessFile input = (new File(filename)).openSync(); |
| 594 input.position().then((position) { | 632 input.position().then((position) { |
| 595 Expect.equals(0, position); | 633 Expect.equals(0, position); |
| 596 List<int> buffer = new List<int>(100); | 634 List<int> buffer = new List<int>(100); |
| 597 input.readList(buffer, 0, 12).then((bytes_read) { | 635 input.readInto(buffer, 0, 12).then((bytes_read) { |
| 598 input.position().then((position) { | 636 input.position().then((position) { |
| 599 Expect.equals(12, position); | 637 Expect.equals(12, position); |
| 600 input.readList(buffer, 12, 6).then((bytes_read) { | 638 input.readInto(buffer, 12, 18).then((bytes_read) { |
| 601 input.position().then((position) { | 639 input.position().then((position) { |
| 602 Expect.equals(18, position); | 640 Expect.equals(18, position); |
| 603 input.setPosition(8).then((ignore) { | 641 input.setPosition(8).then((ignore) { |
| 604 input.position().then((position) { | 642 input.position().then((position) { |
| 605 Expect.equals(8, position); | 643 Expect.equals(8, position); |
| 606 input.close().then((ignore) => port.close()); | 644 input.close().then((ignore) => port.close()); |
| 607 }); | 645 }); |
| 608 }); | 646 }); |
| 609 }); | 647 }); |
| 610 }); | 648 }); |
| 611 }); | 649 }); |
| 612 }); | 650 }); |
| 613 }); | 651 }); |
| 614 } | 652 } |
| 615 | 653 |
| 616 static void testPositionSync() { | 654 static void testPositionSync() { |
| 617 String filename = getFilename("tests/vm/data/fixed_length_file"); | 655 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 618 RandomAccessFile input = (new File(filename)).openSync(); | 656 RandomAccessFile input = (new File(filename)).openSync(); |
| 619 Expect.equals(0, input.positionSync()); | 657 Expect.equals(0, input.positionSync()); |
| 620 List<int> buffer = new List<int>(100); | 658 List<int> buffer = new List<int>(100); |
| 621 input.readListSync(buffer, 0, 12); | 659 input.readIntoSync(buffer, 0, 12); |
| 622 Expect.equals(12, input.positionSync()); | 660 Expect.equals(12, input.positionSync()); |
| 623 input.readListSync(buffer, 12, 6); | 661 input.readIntoSync(buffer, 12, 18); |
| 624 Expect.equals(18, input.positionSync()); | 662 Expect.equals(18, input.positionSync()); |
| 625 input.setPositionSync(8); | 663 input.setPositionSync(8); |
| 626 Expect.equals(8, input.positionSync()); | 664 Expect.equals(8, input.positionSync()); |
| 627 input.closeSync(); | 665 input.closeSync(); |
| 628 } | 666 } |
| 629 | 667 |
| 630 static void testTruncate() { | 668 static void testTruncate() { |
| 631 File file = new File(tempDirectory.path + "/out_truncate"); | 669 File file = new File(tempDirectory.path + "/out_truncate"); |
| 632 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; | 670 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; |
| 633 file.open(mode: WRITE).then((RandomAccessFile openedFile) { | 671 file.open(mode: WRITE).then((RandomAccessFile openedFile) { |
| 634 openedFile.writeList(buffer, 0, 10).then((ignore) { | 672 openedFile.writeFrom(buffer, 0, 10).then((ignore) { |
| 635 openedFile.length().then((length) { | 673 openedFile.length().then((length) { |
| 636 Expect.equals(10, length); | 674 Expect.equals(10, length); |
| 637 openedFile.truncate(5).then((ignore) { | 675 openedFile.truncate(5).then((ignore) { |
| 638 openedFile.length().then((length) { | 676 openedFile.length().then((length) { |
| 639 Expect.equals(5, length); | 677 Expect.equals(5, length); |
| 640 openedFile.close().then((ignore) { | 678 openedFile.close().then((ignore) { |
| 641 file.delete().then((ignore) { | 679 file.delete().then((ignore) { |
| 642 file.exists().then((exists) { | 680 file.exists().then((exists) { |
| 643 Expect.isFalse(exists); | 681 Expect.isFalse(exists); |
| 644 asyncTestDone("testTruncate"); | 682 asyncTestDone("testTruncate"); |
| 645 }); | 683 }); |
| 646 }); | 684 }); |
| 647 }); | 685 }); |
| 648 }); | 686 }); |
| 649 }); | 687 }); |
| 650 }); | 688 }); |
| 651 }); | 689 }); |
| 652 }); | 690 }); |
| 653 asyncTestStarted(); | 691 asyncTestStarted(); |
| 654 } | 692 } |
| 655 | 693 |
| 656 static void testTruncateSync() { | 694 static void testTruncateSync() { |
| 657 File file = new File(tempDirectory.path + "/out_truncate_sync"); | 695 File file = new File(tempDirectory.path + "/out_truncate_sync"); |
| 658 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; | 696 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; |
| 659 RandomAccessFile openedFile = file.openSync(mode: WRITE); | 697 RandomAccessFile openedFile = file.openSync(mode: WRITE); |
| 660 openedFile.writeListSync(buffer, 0, 10); | 698 openedFile.writeFromSync(buffer, 0, 10); |
| 661 Expect.equals(10, openedFile.lengthSync()); | 699 Expect.equals(10, openedFile.lengthSync()); |
| 662 openedFile.truncateSync(5); | 700 openedFile.truncateSync(5); |
| 663 Expect.equals(5, openedFile.lengthSync()); | 701 Expect.equals(5, openedFile.lengthSync()); |
| 664 openedFile.closeSync(); | 702 openedFile.closeSync(); |
| 665 file.deleteSync(); | 703 file.deleteSync(); |
| 666 Expect.isFalse(file.existsSync()); | 704 Expect.isFalse(file.existsSync()); |
| 667 } | 705 } |
| 668 | 706 |
| 669 // Tests exception handling after file was closed. | 707 // Tests exception handling after file was closed. |
| 670 static void testCloseException() { | 708 static void testCloseException() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 698 } on FileIOException catch (ex) { | 736 } on FileIOException catch (ex) { |
| 699 exceptionCaught = true; | 737 exceptionCaught = true; |
| 700 } on Exception catch (ex) { | 738 } on Exception catch (ex) { |
| 701 wrongExceptionCaught = true; | 739 wrongExceptionCaught = true; |
| 702 } | 740 } |
| 703 Expect.equals(true, exceptionCaught); | 741 Expect.equals(true, exceptionCaught); |
| 704 Expect.equals(true, !wrongExceptionCaught); | 742 Expect.equals(true, !wrongExceptionCaught); |
| 705 exceptionCaught = false; | 743 exceptionCaught = false; |
| 706 try { | 744 try { |
| 707 List<int> buffer = new List<int>(100); | 745 List<int> buffer = new List<int>(100); |
| 708 openedFile.readListSync(buffer, 0, 10); | 746 openedFile.readIntoSync(buffer, 0, 10); |
| 709 } on FileIOException catch (ex) { | 747 } on FileIOException catch (ex) { |
| 710 exceptionCaught = true; | 748 exceptionCaught = true; |
| 711 } on Exception catch (ex) { | 749 } on Exception catch (ex) { |
| 712 wrongExceptionCaught = true; | 750 wrongExceptionCaught = true; |
| 713 } | 751 } |
| 714 Expect.equals(true, exceptionCaught); | 752 Expect.equals(true, exceptionCaught); |
| 715 Expect.equals(true, !wrongExceptionCaught); | 753 Expect.equals(true, !wrongExceptionCaught); |
| 716 exceptionCaught = false; | 754 exceptionCaught = false; |
| 717 try { | 755 try { |
| 718 List<int> buffer = new List<int>(100); | 756 List<int> buffer = new List<int>(100); |
| 719 openedFile.writeListSync(buffer, 0, 10); | 757 openedFile.writeFromSync(buffer, 0, 10); |
| 720 } on FileIOException catch (ex) { | 758 } on FileIOException catch (ex) { |
| 721 exceptionCaught = true; | 759 exceptionCaught = true; |
| 722 } on Exception catch (ex) { | 760 } on Exception catch (ex) { |
| 723 wrongExceptionCaught = true; | 761 wrongExceptionCaught = true; |
| 724 } | 762 } |
| 725 Expect.equals(true, exceptionCaught); | 763 Expect.equals(true, exceptionCaught); |
| 726 Expect.equals(true, !wrongExceptionCaught); | 764 Expect.equals(true, !wrongExceptionCaught); |
| 727 exceptionCaught = false; | 765 exceptionCaught = false; |
| 728 try { | 766 try { |
| 729 openedFile.positionSync(); | 767 openedFile.positionSync(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 | 813 |
| 776 // Tests buffer out of bounds exception. | 814 // Tests buffer out of bounds exception. |
| 777 static void testBufferOutOfBoundsException() { | 815 static void testBufferOutOfBoundsException() { |
| 778 bool exceptionCaught = false; | 816 bool exceptionCaught = false; |
| 779 bool wrongExceptionCaught = false; | 817 bool wrongExceptionCaught = false; |
| 780 File file = | 818 File file = |
| 781 new File(tempDirectory.path + "/out_buffer_out_of_bounds"); | 819 new File(tempDirectory.path + "/out_buffer_out_of_bounds"); |
| 782 RandomAccessFile openedFile = file.openSync(mode: WRITE); | 820 RandomAccessFile openedFile = file.openSync(mode: WRITE); |
| 783 try { | 821 try { |
| 784 List<int> buffer = new List<int>(10); | 822 List<int> buffer = new List<int>(10); |
| 785 openedFile.readListSync(buffer, 0, 12); | 823 openedFile.readIntoSync(buffer, 0, 12); |
| 786 } on RangeError catch (ex) { | 824 } on RangeError catch (ex) { |
| 787 exceptionCaught = true; | 825 exceptionCaught = true; |
| 788 } on Exception catch (ex) { | 826 } on Exception catch (ex) { |
| 789 wrongExceptionCaught = true; | 827 wrongExceptionCaught = true; |
| 790 } | 828 } |
| 791 Expect.equals(true, exceptionCaught); | 829 Expect.equals(true, exceptionCaught); |
| 792 Expect.equals(true, !wrongExceptionCaught); | 830 Expect.equals(true, !wrongExceptionCaught); |
| 793 exceptionCaught = false; | 831 exceptionCaught = false; |
| 794 try { | 832 try { |
| 795 List<int> buffer = new List<int>(10); | 833 List<int> buffer = new List<int>(10); |
| 796 openedFile.readListSync(buffer, 6, 6); | 834 openedFile.readIntoSync(buffer, 6, 12); |
| 797 } on RangeError catch (ex) { | 835 } on RangeError catch (ex) { |
| 798 exceptionCaught = true; | 836 exceptionCaught = true; |
| 799 } on Exception catch (ex) { | 837 } on Exception catch (ex) { |
| 800 wrongExceptionCaught = true; | 838 wrongExceptionCaught = true; |
| 801 } | 839 } |
| 802 Expect.equals(true, exceptionCaught); | 840 Expect.equals(true, exceptionCaught); |
| 803 Expect.equals(true, !wrongExceptionCaught); | 841 Expect.equals(true, !wrongExceptionCaught); |
| 804 exceptionCaught = false; | 842 exceptionCaught = false; |
| 805 try { | 843 try { |
| 806 List<int> buffer = new List<int>(10); | 844 List<int> buffer = new List<int>(10); |
| 807 openedFile.readListSync(buffer, -1, 1); | 845 openedFile.readIntoSync(buffer, -1, 1); |
| 808 } on RangeError catch (ex) { | 846 } on RangeError catch (ex) { |
| 809 exceptionCaught = true; | 847 exceptionCaught = true; |
| 810 } on Exception catch (ex) { | 848 } on Exception catch (ex) { |
| 811 wrongExceptionCaught = true; | 849 wrongExceptionCaught = true; |
| 812 } | 850 } |
| 813 Expect.equals(true, exceptionCaught); | 851 Expect.equals(true, exceptionCaught); |
| 814 Expect.equals(true, !wrongExceptionCaught); | 852 Expect.equals(true, !wrongExceptionCaught); |
| 815 exceptionCaught = false; | 853 exceptionCaught = false; |
| 816 try { | 854 try { |
| 817 List<int> buffer = new List<int>(10); | 855 List<int> buffer = new List<int>(10); |
| 818 openedFile.readListSync(buffer, 0, -1); | 856 openedFile.readIntoSync(buffer, 0, -1); |
| 819 } on RangeError catch (ex) { | 857 } on RangeError catch (ex) { |
| 820 exceptionCaught = true; | 858 exceptionCaught = true; |
| 821 } on Exception catch (ex) { | 859 } on Exception catch (ex) { |
| 822 wrongExceptionCaught = true; | 860 wrongExceptionCaught = true; |
| 823 } | 861 } |
| 824 Expect.equals(true, exceptionCaught); | 862 Expect.equals(true, exceptionCaught); |
| 825 Expect.equals(true, !wrongExceptionCaught); | 863 Expect.equals(true, !wrongExceptionCaught); |
| 826 exceptionCaught = false; | 864 exceptionCaught = false; |
| 827 try { | 865 try { |
| 828 List<int> buffer = new List<int>(10); | 866 List<int> buffer = new List<int>(10); |
| 829 openedFile.writeListSync(buffer, 0, 12); | 867 openedFile.writeFromSync(buffer, 0, 12); |
| 830 } on RangeError catch (ex) { | 868 } on RangeError catch (ex) { |
| 831 exceptionCaught = true; | 869 exceptionCaught = true; |
| 832 } on Exception catch (ex) { | 870 } on Exception catch (ex) { |
| 833 wrongExceptionCaught = true; | 871 wrongExceptionCaught = true; |
| 834 } | 872 } |
| 835 Expect.equals(true, exceptionCaught); | 873 Expect.equals(true, exceptionCaught); |
| 836 Expect.equals(true, !wrongExceptionCaught); | 874 Expect.equals(true, !wrongExceptionCaught); |
| 837 exceptionCaught = false; | 875 exceptionCaught = false; |
| 838 try { | 876 try { |
| 839 List<int> buffer = new List<int>(10); | 877 List<int> buffer = new List<int>(10); |
| 840 openedFile.writeListSync(buffer, 6, 6); | 878 openedFile.writeFromSync(buffer, 6, 12); |
| 841 } on RangeError catch (ex) { | 879 } on RangeError catch (ex) { |
| 842 exceptionCaught = true; | 880 exceptionCaught = true; |
| 843 } on Exception catch (ex) { | 881 } on Exception catch (ex) { |
| 844 wrongExceptionCaught = true; | 882 wrongExceptionCaught = true; |
| 845 } | 883 } |
| 846 Expect.equals(true, exceptionCaught); | 884 Expect.equals(true, exceptionCaught); |
| 847 Expect.equals(true, !wrongExceptionCaught); | 885 Expect.equals(true, !wrongExceptionCaught); |
| 848 exceptionCaught = false; | 886 exceptionCaught = false; |
| 849 try { | 887 try { |
| 850 List<int> buffer = new List<int>(10); | 888 List<int> buffer = new List<int>(10); |
| 851 openedFile.writeListSync(buffer, -1, 1); | 889 openedFile.writeFromSync(buffer, -1, 1); |
| 852 } on RangeError catch (ex) { | 890 } on RangeError catch (ex) { |
| 853 exceptionCaught = true; | 891 exceptionCaught = true; |
| 854 } on Exception catch (ex) { | 892 } on Exception catch (ex) { |
| 855 wrongExceptionCaught = true; | 893 wrongExceptionCaught = true; |
| 856 } | 894 } |
| 857 Expect.equals(true, exceptionCaught); | 895 Expect.equals(true, exceptionCaught); |
| 858 Expect.equals(true, !wrongExceptionCaught); | 896 Expect.equals(true, !wrongExceptionCaught); |
| 859 exceptionCaught = false; | 897 exceptionCaught = false; |
| 860 try { | 898 try { |
| 861 List<int> buffer = new List<int>(10); | 899 List<int> buffer = new List<int>(10); |
| 862 openedFile.writeListSync(buffer, 0, -1); | 900 openedFile.writeFromSync(buffer, 0, -1); |
| 863 } on RangeError catch (ex) { | 901 } on RangeError catch (ex) { |
| 864 exceptionCaught = true; | 902 exceptionCaught = true; |
| 865 } on Exception catch (ex) { | 903 } on Exception catch (ex) { |
| 866 wrongExceptionCaught = true; | 904 wrongExceptionCaught = true; |
| 867 } | 905 } |
| 868 Expect.equals(true, exceptionCaught); | 906 Expect.equals(true, exceptionCaught); |
| 869 Expect.equals(true, !wrongExceptionCaught); | 907 Expect.equals(true, !wrongExceptionCaught); |
| 870 openedFile.closeSync(); | 908 openedFile.closeSync(); |
| 871 file.deleteSync(); | 909 file.deleteSync(); |
| 872 } | 910 } |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 testReadAsTextSyncEmptyFile(); | 1249 testReadAsTextSyncEmptyFile(); |
| 1212 testReadAsLines(); | 1250 testReadAsLines(); |
| 1213 testReadAsLinesSync(); | 1251 testReadAsLinesSync(); |
| 1214 testReadAsErrors(); | 1252 testReadAsErrors(); |
| 1215 testLastModified(); | 1253 testLastModified(); |
| 1216 testLastModifiedSync(); | 1254 testLastModifiedSync(); |
| 1217 | 1255 |
| 1218 createTempDirectory(() { | 1256 createTempDirectory(() { |
| 1219 testReadWrite(); | 1257 testReadWrite(); |
| 1220 testReadWriteSync(); | 1258 testReadWriteSync(); |
| 1259 testReadWriteNoArgsSync(); |
| 1221 testReadWriteStream(); | 1260 testReadWriteStream(); |
| 1222 testReadEmptyFileSync(); | 1261 testReadEmptyFileSync(); |
| 1223 testReadEmptyFile(); | 1262 testReadEmptyFile(); |
| 1224 testReadWriteStreamLargeFile(); | 1263 testReadWriteStreamLargeFile(); |
| 1225 testTruncate(); | 1264 testTruncate(); |
| 1226 testTruncateSync(); | 1265 testTruncateSync(); |
| 1227 testCloseException(); | 1266 testCloseException(); |
| 1228 testCloseExceptionStream(); | 1267 testCloseExceptionStream(); |
| 1229 testBufferOutOfBoundsException(); | 1268 testBufferOutOfBoundsException(); |
| 1230 testAppend(); | 1269 testAppend(); |
| 1231 testAppendSync(); | 1270 testAppendSync(); |
| 1232 testWriteAppend(); | 1271 testWriteAppend(); |
| 1233 testOutputStreamWriteAppend(); | 1272 testOutputStreamWriteAppend(); |
| 1234 testOutputStreamWriteString(); | 1273 testOutputStreamWriteString(); |
| 1235 testWriteVariousLists(); | 1274 testWriteVariousLists(); |
| 1236 testDirectory(); | 1275 testDirectory(); |
| 1237 testDirectorySync(); | 1276 testDirectorySync(); |
| 1238 testWriteStringUtf8(); | 1277 testWriteStringUtf8(); |
| 1239 testWriteStringUtf8Sync(); | 1278 testWriteStringUtf8Sync(); |
| 1240 }); | 1279 }); |
| 1241 } | 1280 } |
| 1242 } | 1281 } |
| 1243 | 1282 |
| 1244 main() { | 1283 main() { |
| 1245 FileTest.testMain(); | 1284 FileTest.testMain(); |
| 1246 } | 1285 } |
| OLD | NEW |