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

Side by Side Diff: tests/standalone/io/file_write_only_test.dart

Issue 1193653002: Add file modes for opening a file write only (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Addressed review comments + fixed analyzer reported issues Created 5 years, 6 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
« no previous file with comments | « sdk/lib/io/file_impl.dart ('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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 //
5 // Dart test program for testing file I/O.
6
7 import 'dart:async';
8 import 'dart:io';
9
10 import "package:async_helper/async_helper.dart";
11 import "package:expect/expect.dart";
12
13 Future withTempDir(String prefix, void test(Directory dir)) async {
14 var tempDir = Directory.systemTemp.createTempSync(prefix);
15 try {
16 await test(tempDir);
17 } finally {
18 tempDir.deleteSync(recursive: true);
19 }
20 }
21
22 void withTempDirSync(String prefix, void test(Directory dir)) async {
23 var tempDir = Directory.systemTemp.createTempSync(prefix);
24 try {
25 test(tempDir);
26 } finally {
27 tempDir.deleteSync(recursive: true);
28 }
29 }
30
31 Futire expectThrowsAsync(Future future, String message) {
32 return future.then((r) => Expect.fail(message))
33 .catchError((e) {});
34 }
35
36
37 Future write(Directory dir) async {
38 var f = new File('x');
39 var raf = await f.open(mode: WRITE_ONLY);
40 await raf.writeString('Hello');
41 await raf.setPosition(0);
42 await raf.writeString('Hello');
43 await raf.setPosition(0);
44 await expectThrowsAsync(
45 raf.readByte(), 'Read from write only file succeeded');
46 await raf.close();
47 raf = await f.open(mode: WRITE_ONLY_APPEND);
48 await raf.writeString('Hello');
49 await expectThrowsAsync(
50 raf.readByte(), 'Read from write only file succeeded');
51 await raf.setPosition(0);
52 await raf.writeString('Hello');
53 await raf.close();
54 Expect.equals(f.lengthSync(), 10);
55 }
56
57 Future writeSync(Directory dir) {
58 var f = new File('x');
59 var raf = f.openSync(mode: WRITE_ONLY);
60 raf.writeStringSync('Hello');
61 raf.setPositionSync(0);
62 raf.writeStringSync('Hello');
63 raf.setPositionSync(0);
64 Expect.throws(() => raf.readByteSync());
65 }
66
67 Future openWrite(Directory dir) async {
68 var f = new File('x');
69 var sink = f.openWrite(mode: WRITE_ONLY);
70 sink.write('Hello');
71 await sink.close();
72 sink = await f.openWrite(mode: WRITE_ONLY_APPEND);
73 sink.write('Hello');
74 await sink.close();
75 Expect.equals(f.lengthSync(), 10);
76 }
77
78 main() async {
79 asyncStart();
80 await withTempDir('file_write_only_test', write);
81 withTempDirSync('file_write_only_test', writeSync);
82 await withTempDir('file_write_only_test', openWrite);
83 asyncEnd();
84 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698