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

Side by Side Diff: tests/standalone/src/FileTest.dart

Issue 9346015: Change file opening operation to set position at the end of the file when FileMode.APPEND is used. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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
« runtime/bin/file_linux.cc ('K') | « runtime/bin/file_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #import("dart:io"); 7 #import("dart:io");
8 8
9 class FileTest { 9 class FileTest {
10 static Directory tempDirectory; 10 static Directory tempDirectory;
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 file2.create(); 255 file2.create();
256 }; 256 };
257 openedFile.close(); 257 openedFile.close();
258 }; 258 };
259 openedFile.readList(buffer1, 0, 42); 259 openedFile.readList(buffer1, 0, 42);
260 }; 260 };
261 asyncTestStarted(); 261 asyncTestStarted();
262 file.open(); 262 file.open();
263 } 263 }
264 264
265 static void testWriteAppend() {
266 String content = "foobar";
267 String filename = tempDirectory.path + "/write_append";
268 File file = new File(filename);
269 file.createSync();
270 Expect.isTrue(new File(filename).existsSync());
271 List<int> buffer = content.charCodes();
272 RandomAccessFile openedFile = file.openSync(FileMode.WRITE);
273 openedFile.writeListSync(buffer, 0, buffer.length);
274 openedFile.closeSync();
275 // Reopen the file in write mode to ensure that we overwrite the content.
276 openedFile = (new File(filename)).openSync(FileMode.WRITE);
277 openedFile.writeListSync(buffer, 0, buffer.length);
278 Expect.equals(content.length, openedFile.lengthSync());
279 openedFile.closeSync();
280 // Open the file in append mode and ensure that we do not overwrite
281 // the existing content.
282 openedFile = (new File(filename)).openSync(FileMode.APPEND);
283 openedFile.writeListSync(buffer, 0, buffer.length);
284 Expect.equals(content.length * 2, openedFile.lengthSync());
285 openedFile.closeSync();
286 file.deleteSync();
287 }
288
289 static void testOutputStreamWriteAppend() {
290 String content = "foobar";
291 String filename = tempDirectory.path + "/outstream_write_append";
292 File file = new File(filename);
293 file.createSync();
294 List<int> buffer = content.charCodes();
295 OutputStream outStream = file.openOutputStream();
296 outStream.closeHandler = () {
297 File file2 = new File(filename);
298 OutputStream appendingOutput = file2.openOutputStream(FileMode.APPEND);
299 appendingOutput.write(buffer);
300 appendingOutput.closeHandler = () {
301 File file3 = new File(filename);
302 file3.openHandler = (RandomAccessFile openedFile) {
303 openedFile.lengthHandler = (int length) {
304 Expect.equals(content.length * 2, length);
305 openedFile.closeHandler = () {
306 asyncTestDone();
307 };
308 openedFile.close();
309 };
310 openedFile.length();
311 };
312 file3.open();
313 };
314 appendingOutput.close();
315 };
316 asyncTestStarted();
317 outStream.write(buffer);
318 outStream.close();
319 }
320
321
265 static void testReadWriteSync() { 322 static void testReadWriteSync() {
266 // Read a file. 323 // Read a file.
267 String inFilename = getFilename("tests/vm/data/fixed_length_file"); 324 String inFilename = getFilename("tests/vm/data/fixed_length_file");
268 RandomAccessFile file = (new File(inFilename)).openSync(); 325 RandomAccessFile file = (new File(inFilename)).openSync();
269 List<int> buffer1 = new List<int>(42); 326 List<int> buffer1 = new List<int>(42);
270 int bytes_read = 0; 327 int bytes_read = 0;
271 int bytes_written = 0; 328 int bytes_written = 0;
272 bytes_read = file.readListSync(buffer1, 0, 42); 329 bytes_read = file.readListSync(buffer1, 0, 42);
273 Expect.equals(42, bytes_read); 330 Expect.equals(42, bytes_read);
274 file.closeSync(); 331 file.closeSync();
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 testReadWriteStream(); 817 testReadWriteStream();
761 testReadEmptyFileSync(); 818 testReadEmptyFileSync();
762 testReadEmptyFile(); 819 testReadEmptyFile();
763 testTruncate(); 820 testTruncate();
764 testTruncateSync(); 821 testTruncateSync();
765 testCloseException(); 822 testCloseException();
766 testCloseExceptionStream(); 823 testCloseExceptionStream();
767 testBufferOutOfBoundsException(); 824 testBufferOutOfBoundsException();
768 testAppend(); 825 testAppend();
769 testAppendSync(); 826 testAppendSync();
827 testWriteAppend();
828 testOutputStreamWriteAppend();
770 asyncTestDone(); 829 asyncTestDone();
771 }); 830 });
772 } 831 }
773 } 832 }
774 833
775 main() { 834 main() {
776 FileTest.testMain(); 835 FileTest.testMain();
777 } 836 }
OLDNEW
« runtime/bin/file_linux.cc ('K') | « runtime/bin/file_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698