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

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

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

Powered by Google App Engine
This is Rietveld 408576698