| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 | 7 |
| 8 class FileTest { | 8 class FileTest { |
| 9 // Test for file read functionality. | 9 // Test for file read functionality. |
| 10 static int testReadStream() { | 10 static int testReadStream() { |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 input.openSync(); | 267 input.openSync(); |
| 268 input.positionHandler = (position) { | 268 input.positionHandler = (position) { |
| 269 Expect.equals(0, position); | 269 Expect.equals(0, position); |
| 270 List<int> buffer = new List<int>(100); | 270 List<int> buffer = new List<int>(100); |
| 271 input.readListHandler = (bytes_read) { | 271 input.readListHandler = (bytes_read) { |
| 272 input.positionHandler = (position) { | 272 input.positionHandler = (position) { |
| 273 Expect.equals(12, position); | 273 Expect.equals(12, position); |
| 274 input.readListHandler = (bytes_read) { | 274 input.readListHandler = (bytes_read) { |
| 275 input.positionHandler = (position) { | 275 input.positionHandler = (position) { |
| 276 Expect.equals(18, position); | 276 Expect.equals(18, position); |
| 277 input.close(); | 277 input.setPositionHandler = () { |
| 278 input.positionHandler = (position) { |
| 279 Expect.equals(8, position); |
| 280 input.close(); |
| 281 }; |
| 282 input.position(); |
| 283 }; |
| 284 input.setPosition(8); |
| 278 }; | 285 }; |
| 279 }; | 286 }; |
| 280 input.readList(buffer, 12, 6); | 287 input.readList(buffer, 12, 6); |
| 281 }; | 288 }; |
| 282 input.position(); | 289 input.position(); |
| 283 }; | 290 }; |
| 284 input.readList(buffer, 0, 12); | 291 input.readList(buffer, 0, 12); |
| 285 }; | 292 }; |
| 286 input.position(); | 293 input.position(); |
| 287 return 1; | 294 return 1; |
| 288 } | 295 } |
| 289 | 296 |
| 290 static int testPositionSync() { | 297 static int testPositionSync() { |
| 291 String filename = getFilename("tests/vm/data/fixed_length_file"); | 298 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 292 File input = new File(filename); | 299 File input = new File(filename); |
| 293 input.openSync(); | 300 input.openSync(); |
| 294 Expect.equals(0, input.positionSync()); | 301 Expect.equals(0, input.positionSync()); |
| 295 List<int> buffer = new List<int>(100); | 302 List<int> buffer = new List<int>(100); |
| 296 input.readListSync(buffer, 0, 12); | 303 input.readListSync(buffer, 0, 12); |
| 297 Expect.equals(12, input.positionSync()); | 304 Expect.equals(12, input.positionSync()); |
| 298 input.readListSync(buffer, 12, 6); | 305 input.readListSync(buffer, 12, 6); |
| 299 Expect.equals(18, input.positionSync()); | 306 Expect.equals(18, input.positionSync()); |
| 307 input.setPositionSync(8); |
| 308 Expect.equals(8, input.positionSync()); |
| 300 input.closeSync(); | 309 input.closeSync(); |
| 301 return 1; | 310 return 1; |
| 302 } | 311 } |
| 303 | 312 |
| 304 // Tests exception handling after file was closed. | 313 // Tests exception handling after file was closed. |
| 305 static int testCloseException() { | 314 static int testCloseException() { |
| 306 bool exceptionCaught = false; | 315 bool exceptionCaught = false; |
| 307 bool wrongExceptionCaught = false; | 316 bool wrongExceptionCaught = false; |
| 308 String filename = getFilename("tests/vm/data/fixed_length_file"); | 317 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 309 File input = new File(filename + "_out"); | 318 File input = new File(filename + "_out"); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 Expect.equals(1, testCloseException()); | 572 Expect.equals(1, testCloseException()); |
| 564 Expect.equals(1, testCloseExceptionStream()); | 573 Expect.equals(1, testCloseExceptionStream()); |
| 565 Expect.equals(1, testBufferOutOfBoundsException()); | 574 Expect.equals(1, testBufferOutOfBoundsException()); |
| 566 Expect.equals(1, testMixedSyncAndAsync()); | 575 Expect.equals(1, testMixedSyncAndAsync()); |
| 567 } | 576 } |
| 568 } | 577 } |
| 569 | 578 |
| 570 main() { | 579 main() { |
| 571 FileTest.testMain(); | 580 FileTest.testMain(); |
| 572 } | 581 } |
| OLD | NEW |