| 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 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 openedFile.writeFromSync(buffer, 0, buffer.length); | 342 openedFile.writeFromSync(buffer, 0, buffer.length); |
| 343 openedFile.closeSync(); | 343 openedFile.closeSync(); |
| 344 // Reopen the file in write mode to ensure that we overwrite the content. | 344 // Reopen the file in write mode to ensure that we overwrite the content. |
| 345 openedFile = (new File(filename)).openSync(mode: WRITE); | 345 openedFile = (new File(filename)).openSync(mode: WRITE); |
| 346 openedFile.writeFromSync(buffer, 0, buffer.length); | 346 openedFile.writeFromSync(buffer, 0, buffer.length); |
| 347 Expect.equals(content.length, openedFile.lengthSync()); | 347 Expect.equals(content.length, openedFile.lengthSync()); |
| 348 openedFile.closeSync(); | 348 openedFile.closeSync(); |
| 349 // Open the file in append mode and ensure that we do not overwrite | 349 // Open the file in append mode and ensure that we do not overwrite |
| 350 // the existing content. | 350 // the existing content. |
| 351 openedFile = (new File(filename)).openSync(mode: APPEND); | 351 openedFile = (new File(filename)).openSync(mode: APPEND); |
| 352 openedFile.writeFromSync(buffer, 0, buffer.length); | 352 openedFile.writeFromSync(buffer, 2, buffer.length - 2); |
| 353 Expect.equals(content.length * 2, openedFile.lengthSync()); | 353 Expect.equals(content.length + content.length - 4, |
| 354 openedFile.lengthSync()); |
| 355 Expect.equals(content + content.substring(2, content.length - 2), |
| 356 file.readAsStringSync()); |
| 354 openedFile.closeSync(); | 357 openedFile.closeSync(); |
| 355 file.deleteSync(); | 358 file.deleteSync(); |
| 356 } | 359 } |
| 357 | 360 |
| 358 static void testOutputStreamWriteAppend() { | 361 static void testOutputStreamWriteAppend() { |
| 359 asyncTestStarted(); | 362 asyncTestStarted(); |
| 360 String content = "foobar"; | 363 String content = "foobar"; |
| 361 String filename = tempDirectory.path + "/outstream_write_append"; | 364 String filename = tempDirectory.path + "/outstream_write_append"; |
| 362 File file = new File(filename); | 365 File file = new File(filename); |
| 363 file.createSync(); | 366 file.createSync(); |
| (...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 testLastModified(); | 1329 testLastModified(); |
| 1327 testDoubleAsyncOperation(); | 1330 testDoubleAsyncOperation(); |
| 1328 asyncEnd(); | 1331 asyncEnd(); |
| 1329 }); | 1332 }); |
| 1330 } | 1333 } |
| 1331 } | 1334 } |
| 1332 | 1335 |
| 1333 main() { | 1336 main() { |
| 1334 FileTest.testMain(); | 1337 FileTest.testMain(); |
| 1335 } | 1338 } |
| OLD | NEW |