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

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

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