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

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

Issue 9572005: Move all tests using dart:io to a separate directory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 8 years, 9 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
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 #import("dart:io");
6
7 class FileTest {
8 static void testOpenInvalidArgs(name, [writable = false]) {
9 var file = new File(name);
10 try {
11 file.openSync();
12 Expect.fail('exception expected');
13 } catch (var e) {
14 Expect.isTrue(e is FileIOException);
15 Expect.isTrue(e.toString().contains('open file'));
16 }
17
18 file.onError = (s) {
19 Expect.isTrue(s.contains('open file'));
20 };
21 file.open(FileMode.READ, (opened) {
22 Expect.fail('non-string name open');
23 });
24 }
25
26 static void testExistsInvalidArgs(name) {
27 var file = new File(name);
28 try {
29 file.existsSync();
30 Expect.fail('exception expected');
31 } catch (var e) {
32 Expect.isTrue(e is FileIOException);
33 Expect.isTrue(e.toString().contains('is not a string'));
34 }
35
36 file.onError = (s) {
37 Expect.isTrue(s.contains('is not a string'));
38 };
39 file.exists((bool) {
40 Expect.fail('non-string name exists');
41 });
42 }
43
44 static void testCreateInvalidArgs(name) {
45 var file = new File(name);
46 try {
47 file.createSync();
48 Expect.fail('exception expected');
49 } catch (var e) {
50 Expect.isTrue(e is FileIOException);
51 Expect.isTrue(e.toString().contains('Cannot create file'));
52 }
53
54 file.onError = (s) {
55 Expect.isTrue(s.contains('Cannot create file'));
56 };
57 file.create((created) {
58 Expect.fail('non-string name exists');
59 });
60 }
61
62 static void testReadListInvalidArgs(buffer, offset, length) {
63 String filename = getFilename("tests/vm/data/fixed_length_file");
64 var file = (new File(filename)).openSync();
65 try {
66 file.readListSync(buffer, offset, length);
67 Expect.fail('exception expected');
68 } catch (var e) {
69 Expect.isTrue(e is FileIOException);
70 Expect.isTrue(e.toString().contains('Invalid arguments'));
71 }
72
73 var errors = 0;
74 file.onError = (s) {
75 errors++;
76 Expect.isTrue(s.contains('Invalid arguments'));
77 file.close(() {
78 Expect.equals(1, errors);
79 });
80 };
81 file.readList(buffer, offset, length, (bytes) {
82 Expect.fail('read list invalid arguments');
83 });
84 }
85
86 static void testWriteByteInvalidArgs(value) {
87 String filename = getFilename("tests/vm/data/fixed_length_file");
88 var file = (new File(filename + "_out")).openSync(FileMode.WRITE);
89 try {
90 file.writeByteSync(value);
91 Expect.fail('exception expected');
92 } catch (var e) {
93 Expect.isTrue(e is FileIOException);
94 Expect.isTrue(e.toString().contains('Invalid argument'));
95 }
96
97 var errors = 0;
98 file.onError = (s) {
99 errors++;
100 Expect.isTrue(s.contains('Invalid argument'));
101 file.close(() {
102 Expect.equals(1, errors);
103 });
104 };
105 var calls = 0;
106 file.writeByte(value);
107 file.onNoPendingWrites = () {
108 if (++calls > 1) Expect.fail('write list invalid argument');
109 };
110 }
111
112 static void testWriteListInvalidArgs(buffer, offset, bytes) {
113 String filename = getFilename("tests/vm/data/fixed_length_file");
114 var file = (new File(filename + "_out")).openSync(FileMode.WRITE);
115 try {
116 file.writeListSync(buffer, offset, bytes);
117 Expect.fail('exception expected');
118 } catch (var e) {
119 Expect.isTrue(e is FileIOException);
120 Expect.isTrue(e.toString().contains('Invalid arguments'));
121 }
122
123 var errors = 0;
124 file.onError = (s) {
125 errors++;
126 Expect.isTrue(s.contains('Invalid arguments'));
127 file.close(() {
128 Expect.equals(1, errors);
129 });
130 };
131 var calls = 0;
132 file.writeList(buffer, offset, bytes);
133 file.onNoPendingWrites = () {
134 if (++calls > 1) Expect.fail('write string invalid argument');
135 };
136 }
137
138 static void testWriteStringInvalidArgs(string) {
139 String filename = getFilename("tests/vm/data/fixed_length_file");
140 var file = new File(filename + "_out");
141 file.openSync(FileMode.WRITE);
142 try {
143 file.writeString(string);
144 Expect.fail('exception expected');
145 } catch (var e) {
146 Expect.isTrue(e is FileIOException);
147 Expect.isTrue(e.toString().contains('writeString failed'));
148 }
149
150 var errors = 0;
151 file.onError = (s) {
152 errors++;
153 Expect.isTrue(s.contains('writeString failed'));
154 };
155 var calls = 0;
156 file.onNoPendingWrites = () {
157 if (++calls > 1) Expect.fail('write list invalid argument');
158 };
159 file.writeString(string);
160 file.onClosed = () {
161 Expect.equals(1, errors);
162 };
163 file.close();
164 }
165
166 static void testFullPathInvalidArgs(name) {
167 var file = new File(name);
168 try {
169 file.fullPathSync();
170 Expect.fail('exception expected');
171 } catch (var e) {
172 Expect.isTrue(e is FileIOException);
173 Expect.isTrue(e.toString().contains('fullPath failed'));
174 }
175
176 file.onError = (s) {
177 Expect.isTrue(s.contains('fullPath failed'));
178 };
179 file.fullPath((path) {
180 Expect.fail('full path invalid argument');
181 });
182 }
183
184 static String getFilename(String path) =>
185 new File(path).existsSync() ? path : 'runtime/' + path;
186 }
187
188 main() {
189 FileTest.testOpenInvalidArgs(0);
190 FileTest.testOpenInvalidArgs('name', 0);
191 FileTest.testExistsInvalidArgs(0);
192 FileTest.testCreateInvalidArgs(0);
193 FileTest.testReadListInvalidArgs(12, 0, 1);
194 FileTest.testReadListInvalidArgs(new List(10), '0', 1);
195 FileTest.testReadListInvalidArgs(new List(10), 0, '1');
196 FileTest.testWriteByteInvalidArgs('asdf');
197 FileTest.testWriteListInvalidArgs(12, 0, 1);
198 FileTest.testWriteListInvalidArgs(new List(10), '0', 1);
199 FileTest.testWriteListInvalidArgs(new List(10), 0, '1');
200 FileTest.testFullPathInvalidArgs(12);
201 }
OLDNEW
« no previous file with comments | « tests/standalone/src/FileInputStreamTest.dart ('k') | tests/standalone/src/FileOutputStreamTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698