OLD | NEW |
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 | 7 |
8 class FileTest { | 8 class FileTest { |
9 static Directory tempDirectory; | 9 static Directory tempDirectory; |
10 static int numLiveAsyncTests = 0; | 10 static int numLiveAsyncTests = 0; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 return 1; | 88 return 1; |
89 } | 89 } |
90 | 90 |
91 static int testRead() { | 91 static int testRead() { |
92 // Read a file and check part of it's contents. | 92 // Read a file and check part of it's contents. |
93 String filename = getFilename("bin/file_test.cc"); | 93 String filename = getFilename("bin/file_test.cc"); |
94 File file = new File(filename); | 94 File file = new File(filename); |
95 file.errorHandler = (s) { | 95 file.errorHandler = (s) { |
96 Expect.fail("No errors expected"); | 96 Expect.fail("No errors expected"); |
97 }; | 97 }; |
98 file.openHandler = () { | 98 file.openHandler = (RandomAccessFile file) { |
99 List<int> buffer = new List<int>(10); | 99 List<int> buffer = new List<int>(10); |
100 file.readListHandler = (bytes_read) { | 100 file.readListHandler = (bytes_read) { |
101 Expect.equals(5, bytes_read); | 101 Expect.equals(5, bytes_read); |
102 file.readListHandler = (bytes_read) { | 102 file.readListHandler = (bytes_read) { |
103 Expect.equals(5, bytes_read); | 103 Expect.equals(5, bytes_read); |
104 Expect.equals(47, buffer[0]); // represents '/' in the file. | 104 Expect.equals(47, buffer[0]); // represents '/' in the file. |
105 Expect.equals(47, buffer[1]); // represents '/' in the file. | 105 Expect.equals(47, buffer[1]); // represents '/' in the file. |
106 Expect.equals(32, buffer[2]); // represents ' ' in the file. | 106 Expect.equals(32, buffer[2]); // represents ' ' in the file. |
107 Expect.equals(67, buffer[3]); // represents 'C' in the file. | 107 Expect.equals(67, buffer[3]); // represents 'C' in the file. |
108 Expect.equals(111, buffer[4]); // represents 'o' in the file. | 108 Expect.equals(111, buffer[4]); // represents 'o' in the file. |
109 Expect.equals(112, buffer[5]); // represents 'p' in the file. | 109 Expect.equals(112, buffer[5]); // represents 'p' in the file. |
110 Expect.equals(121, buffer[6]); // represents 'y' in the file. | 110 Expect.equals(121, buffer[6]); // represents 'y' in the file. |
111 Expect.equals(114, buffer[7]); // represents 'r' in the file. | 111 Expect.equals(114, buffer[7]); // represents 'r' in the file. |
112 Expect.equals(105, buffer[8]); // represents 'i' in the file. | 112 Expect.equals(105, buffer[8]); // represents 'i' in the file. |
113 Expect.equals(103, buffer[9]); // represents 'g' in the file. | 113 Expect.equals(103, buffer[9]); // represents 'g' in the file. |
114 file.close(); | 114 file.close(); |
115 }; | 115 }; |
116 file.readList(buffer, 5, 5); | 116 file.readList(buffer, 5, 5); |
117 }; | 117 }; |
118 file.readList(buffer, 0, 5); | 118 file.readList(buffer, 0, 5); |
119 }; | 119 }; |
120 file.open(); | 120 file.open(); |
121 return 1; | 121 return 1; |
122 } | 122 } |
123 | 123 |
124 static int testReadSync() { | 124 static int testReadSync() { |
125 // Read a file and check part of it's contents. | 125 // Read a file and check part of it's contents. |
126 String filename = getFilename("bin/file_test.cc"); | 126 String filename = getFilename("bin/file_test.cc"); |
127 File file = new File(filename); | 127 RandomAccessFile file = (new File(filename)).openSync(); |
128 file.openSync(); | |
129 List<int> buffer = new List<int>(42); | 128 List<int> buffer = new List<int>(42); |
130 int bytes_read = 0; | 129 int bytes_read = 0; |
131 bytes_read = file.readListSync(buffer, 0, 12); | 130 bytes_read = file.readListSync(buffer, 0, 12); |
132 Expect.equals(12, bytes_read); | 131 Expect.equals(12, bytes_read); |
133 bytes_read = file.readListSync(buffer, 12, 30); | 132 bytes_read = file.readListSync(buffer, 12, 30); |
134 Expect.equals(30, bytes_read); | 133 Expect.equals(30, bytes_read); |
135 Expect.equals(47, buffer[0]); // represents '/' in the file. | 134 Expect.equals(47, buffer[0]); // represents '/' in the file. |
136 Expect.equals(47, buffer[1]); // represents '/' in the file. | 135 Expect.equals(47, buffer[1]); // represents '/' in the file. |
137 Expect.equals(32, buffer[2]); // represents ' ' in the file. | 136 Expect.equals(32, buffer[2]); // represents ' ' in the file. |
138 Expect.equals(67, buffer[3]); // represents 'C' in the file. | 137 Expect.equals(67, buffer[3]); // represents 'C' in the file. |
139 Expect.equals(111, buffer[4]); // represents 'o' in the file. | 138 Expect.equals(111, buffer[4]); // represents 'o' in the file. |
140 Expect.equals(112, buffer[5]); // represents 'p' in the file. | 139 Expect.equals(112, buffer[5]); // represents 'p' in the file. |
141 Expect.equals(121, buffer[6]); // represents 'y' in the file. | 140 Expect.equals(121, buffer[6]); // represents 'y' in the file. |
142 Expect.equals(114, buffer[7]); // represents 'r' in the file. | 141 Expect.equals(114, buffer[7]); // represents 'r' in the file. |
143 Expect.equals(105, buffer[8]); // represents 'i' in the file. | 142 Expect.equals(105, buffer[8]); // represents 'i' in the file. |
144 Expect.equals(103, buffer[9]); // represents 'g' in the file. | 143 Expect.equals(103, buffer[9]); // represents 'g' in the file. |
145 Expect.equals(104, buffer[10]); // represents 'h' in the file. | 144 Expect.equals(104, buffer[10]); // represents 'h' in the file. |
146 Expect.equals(116, buffer[11]); // represents 't' in the file. | 145 Expect.equals(116, buffer[11]); // represents 't' in the file. |
147 return 1; | 146 return 1; |
148 } | 147 } |
149 | 148 |
150 // Test for file read and write functionality. | 149 // Test for file read and write functionality. |
151 static int testReadWrite() { | 150 static int testReadWrite() { |
152 // Read a file. | 151 // Read a file. |
153 String inFilename = getFilename("tests/vm/data/fixed_length_file"); | 152 String inFilename = getFilename("tests/vm/data/fixed_length_file"); |
154 File file = new File(inFilename); | 153 File file = new File(inFilename); |
155 file.errorHandler = (s) { | 154 file.errorHandler = (s) { |
156 Expect.fail("No errors expected"); | 155 Expect.fail("No errors expected"); |
157 }; | 156 }; |
158 file.openHandler = () { | 157 file.openHandler = (RandomAccessFile openedFile) { |
159 List<int> buffer1 = new List<int>(42); | 158 List<int> buffer1 = new List<int>(42); |
160 file.readListHandler = (bytes_read) { | 159 openedFile.readListHandler = (bytes_read) { |
161 Expect.equals(42, bytes_read); | 160 Expect.equals(42, bytes_read); |
162 file.closeHandler = () { | 161 openedFile.closeHandler = () { |
163 // Write the contents of the file just read into another file. | 162 // Write the contents of the file just read into another file. |
164 String outFilename = tempDirectory.path + "/out_read_write"; | 163 String outFilename = tempDirectory.path + "/out_read_write"; |
165 file = new File(outFilename); | 164 file = new File(outFilename); |
166 file.errorHandler = (s) { | 165 file.errorHandler = (s) { |
167 Expect.fail("No errors expected"); | 166 Expect.fail("No errors expected"); |
168 }; | 167 }; |
169 file.createHandler = () { | 168 file.createHandler = () { |
170 file.fullPathHandler = (s) { | 169 file.fullPathHandler = (s) { |
171 Expect.isTrue(new File(s).existsSync()); | 170 Expect.isTrue(new File(s).existsSync()); |
172 if (s[0] != '/' && s[0] != '\\' && s[1] != ':') { | 171 if (s[0] != '/' && s[0] != '\\' && s[1] != ':') { |
173 Expect.fail("Not a full path"); | 172 Expect.fail("Not a full path"); |
174 } | 173 } |
175 file.openHandler = () { | 174 file.openHandler = (RandomAccessFile openedFile) { |
176 file.noPendingWriteHandler = () { | 175 openedFile.noPendingWriteHandler = () { |
177 file.closeHandler = () { | 176 openedFile.closeHandler = () { |
178 // Now read the contents of the file just written. | 177 // Now read the contents of the file just written. |
179 List<int> buffer2 = new List<int>(bytes_read); | 178 List<int> buffer2 = new List<int>(bytes_read); |
180 file = new File(outFilename); | 179 file = new File(outFilename); |
181 file.errorHandler = (s) { | 180 file.errorHandler = (s) { |
182 Expect.fail("No errors expected"); | 181 Expect.fail("No errors expected"); |
183 }; | 182 }; |
184 file.openHandler = () { | 183 file.openHandler = (RandomAccessFile openedfile) { |
185 file.readListHandler = (bytes_read) { | 184 openedFile.readListHandler = (bytes_read) { |
186 Expect.equals(42, bytes_read); | 185 Expect.equals(42, bytes_read); |
187 file.closeHandler = () { | 186 openedFile.closeHandler = () { |
188 // Now compare the two buffers to check if they | 187 // Now compare the two buffers to check if they |
189 // are identical. | 188 // are identical. |
190 Expect.equals(buffer1.length, buffer2.length); | 189 Expect.equals(buffer1.length, buffer2.length); |
191 for (int i = 0; i < buffer1.length; i++) { | 190 for (int i = 0; i < buffer1.length; i++) { |
192 Expect.equals(buffer1[i], buffer2[i]); | 191 Expect.equals(buffer1[i], buffer2[i]); |
193 } | 192 } |
194 // Delete the output file. | 193 // Delete the output file. |
195 file.deleteHandler = () { | 194 file.deleteHandler = () { |
196 file.existsHandler = (exists) { | 195 file.existsHandler = (exists) { |
197 Expect.isFalse(exists); | 196 Expect.isFalse(exists); |
198 asyncTestDone(); | 197 asyncTestDone(); |
199 }; | 198 }; |
200 file.exists(); | 199 file.exists(); |
201 }; | 200 }; |
202 file.delete(); | 201 file.delete(); |
203 }; | 202 }; |
204 file.close(); | 203 openedFile.close(); |
205 }; | 204 }; |
206 file.readList(buffer2, 0, 42); | 205 openedFile.readList(buffer2, 0, 42); |
207 }; | 206 }; |
208 file.open(); | 207 file.open(); |
209 }; | 208 }; |
210 file.close(); | 209 openedFile.close(); |
211 }; | 210 }; |
212 file.writeList(buffer1, 0, bytes_read); | 211 openedFile.writeList(buffer1, 0, bytes_read); |
213 }; | 212 }; |
214 file.open(true); | 213 file.open(true); |
215 }; | 214 }; |
216 file.fullPath(); | 215 file.fullPath(); |
217 }; | 216 }; |
218 file.create(); | 217 file.create(); |
219 }; | 218 }; |
220 file.close(); | 219 openedFile.close(); |
221 }; | 220 }; |
222 file.readList(buffer1, 0, 42); | 221 openedFile.readList(buffer1, 0, 42); |
223 }; | 222 }; |
224 asyncTestStarted(); | 223 asyncTestStarted(); |
225 file.open(); | 224 file.open(); |
226 return 1; | 225 return 1; |
227 | 226 |
228 } | 227 } |
229 | 228 |
230 static int testReadWriteSync() { | 229 static int testReadWriteSync() { |
231 // Read a file. | 230 // Read a file. |
232 String inFilename = getFilename("tests/vm/data/fixed_length_file"); | 231 String inFilename = getFilename("tests/vm/data/fixed_length_file"); |
233 File file = new File(inFilename); | 232 RandomAccessFile file = (new File(inFilename)).openSync(); |
234 file.openSync(); | |
235 List<int> buffer1 = new List<int>(42); | 233 List<int> buffer1 = new List<int>(42); |
236 int bytes_read = 0; | 234 int bytes_read = 0; |
237 int bytes_written = 0; | 235 int bytes_written = 0; |
238 bytes_read = file.readListSync(buffer1, 0, 42); | 236 bytes_read = file.readListSync(buffer1, 0, 42); |
239 Expect.equals(42, bytes_read); | 237 Expect.equals(42, bytes_read); |
240 file.closeSync(); | 238 file.closeSync(); |
241 // Write the contents of the file just read into another file. | 239 // Write the contents of the file just read into another file. |
242 String outFilename = tempDirectory.path + "/out_read_write_sync"; | 240 String outFilename = tempDirectory.path + "/out_read_write_sync"; |
243 file = new File(outFilename); | 241 File outFile = new File(outFilename); |
244 file.createSync(); | 242 outFile.createSync(); |
245 String path = file.fullPathSync(); | 243 String path = outFile.fullPathSync(); |
246 if (path[0] != '/' && path[0] != '\\' && path[1] != ':') { | 244 if (path[0] != '/' && path[0] != '\\' && path[1] != ':') { |
247 Expect.fail("Not a full path"); | 245 Expect.fail("Not a full path"); |
248 } | 246 } |
249 Expect.isTrue(new File(path).existsSync()); | 247 Expect.isTrue(new File(path).existsSync()); |
250 file.openSync(true); | 248 RandomAccessFile openedFile = outFile.openSync(true); |
251 file.writeListSync(buffer1, 0, bytes_read); | 249 openedFile.writeListSync(buffer1, 0, bytes_read); |
252 file.closeSync(); | 250 openedFile.closeSync(); |
253 // Now read the contents of the file just written. | 251 // Now read the contents of the file just written. |
254 List<int> buffer2 = new List<int>(bytes_read); | 252 List<int> buffer2 = new List<int>(bytes_read); |
255 file = new File(outFilename); | 253 openedFile = (new File(outFilename)).openSync(); |
256 file.openSync(); | 254 bytes_read = openedFile.readListSync(buffer2, 0, 42); |
257 bytes_read = file.readListSync(buffer2, 0, 42); | |
258 Expect.equals(42, bytes_read); | 255 Expect.equals(42, bytes_read); |
259 file.closeSync(); | 256 openedFile.closeSync(); |
260 // Now compare the two buffers to check if they are identical. | 257 // Now compare the two buffers to check if they are identical. |
261 Expect.equals(buffer1.length, buffer2.length); | 258 Expect.equals(buffer1.length, buffer2.length); |
262 for (int i = 0; i < buffer1.length; i++) { | 259 for (int i = 0; i < buffer1.length; i++) { |
263 Expect.equals(buffer1[i], buffer2[i]); | 260 Expect.equals(buffer1[i], buffer2[i]); |
264 } | 261 } |
265 // Delete the output file. | 262 // Delete the output file. |
266 file.deleteSync(); | 263 outFile.deleteSync(); |
267 Expect.isFalse(file.existsSync()); | 264 Expect.isFalse(outFile.existsSync()); |
268 return 1; | 265 return 1; |
269 } | 266 } |
270 | 267 |
271 // Test for file length functionality. | 268 // Test for file length functionality. |
272 static int testLength() { | 269 static int testLength() { |
273 String filename = getFilename("tests/vm/data/fixed_length_file"); | 270 String filename = getFilename("tests/vm/data/fixed_length_file"); |
274 File input = new File(filename); | 271 RandomAccessFile input = (new File(filename)).openSync(); |
275 input.errorHandler = (s) { | 272 input.errorHandler = (s) { |
276 Expect.fail("No errors expected"); | 273 Expect.fail("No errors expected"); |
277 }; | 274 }; |
278 input.openSync(); | |
279 input.lengthHandler = (length) { | 275 input.lengthHandler = (length) { |
280 Expect.equals(42, length); | 276 Expect.equals(42, length); |
281 input.close(); | 277 input.close(); |
282 }; | 278 }; |
283 input.length(); | 279 input.length(); |
284 return 1; | 280 return 1; |
285 } | 281 } |
286 | 282 |
287 static int testLengthSync() { | 283 static int testLengthSync() { |
288 String filename = getFilename("tests/vm/data/fixed_length_file"); | 284 String filename = getFilename("tests/vm/data/fixed_length_file"); |
289 File input = new File(filename); | 285 RandomAccessFile input = (new File(filename)).openSync(); |
290 input.openSync(); | |
291 Expect.equals(42, input.lengthSync()); | 286 Expect.equals(42, input.lengthSync()); |
292 input.closeSync(); | 287 input.closeSync(); |
293 return 1; | 288 return 1; |
294 } | 289 } |
295 | 290 |
296 // Test for file position functionality. | 291 // Test for file position functionality. |
297 static int testPosition() { | 292 static int testPosition() { |
298 String filename = getFilename("tests/vm/data/fixed_length_file"); | 293 String filename = getFilename("tests/vm/data/fixed_length_file"); |
299 File input = new File(filename); | 294 RandomAccessFile input = (new File(filename)).openSync(); |
300 input.errorHandler = (s) { | 295 input.errorHandler = (s) { |
301 Expect.fail("No errors expected"); | 296 Expect.fail("No errors expected"); |
302 }; | 297 }; |
303 input.openSync(); | |
304 input.positionHandler = (position) { | 298 input.positionHandler = (position) { |
305 Expect.equals(0, position); | 299 Expect.equals(0, position); |
306 List<int> buffer = new List<int>(100); | 300 List<int> buffer = new List<int>(100); |
307 input.readListHandler = (bytes_read) { | 301 input.readListHandler = (bytes_read) { |
308 input.positionHandler = (position) { | 302 input.positionHandler = (position) { |
309 Expect.equals(12, position); | 303 Expect.equals(12, position); |
310 input.readListHandler = (bytes_read) { | 304 input.readListHandler = (bytes_read) { |
311 input.positionHandler = (position) { | 305 input.positionHandler = (position) { |
312 Expect.equals(18, position); | 306 Expect.equals(18, position); |
313 input.setPositionHandler = () { | 307 input.setPositionHandler = () { |
(...skipping 11 matching lines...) Expand all Loading... |
325 input.position(); | 319 input.position(); |
326 }; | 320 }; |
327 input.readList(buffer, 0, 12); | 321 input.readList(buffer, 0, 12); |
328 }; | 322 }; |
329 input.position(); | 323 input.position(); |
330 return 1; | 324 return 1; |
331 } | 325 } |
332 | 326 |
333 static int testPositionSync() { | 327 static int testPositionSync() { |
334 String filename = getFilename("tests/vm/data/fixed_length_file"); | 328 String filename = getFilename("tests/vm/data/fixed_length_file"); |
335 File input = new File(filename); | 329 RandomAccessFile input = (new File(filename)).openSync(); |
336 input.openSync(); | |
337 Expect.equals(0, input.positionSync()); | 330 Expect.equals(0, input.positionSync()); |
338 List<int> buffer = new List<int>(100); | 331 List<int> buffer = new List<int>(100); |
339 input.readListSync(buffer, 0, 12); | 332 input.readListSync(buffer, 0, 12); |
340 Expect.equals(12, input.positionSync()); | 333 Expect.equals(12, input.positionSync()); |
341 input.readListSync(buffer, 12, 6); | 334 input.readListSync(buffer, 12, 6); |
342 Expect.equals(18, input.positionSync()); | 335 Expect.equals(18, input.positionSync()); |
343 input.setPositionSync(8); | 336 input.setPositionSync(8); |
344 Expect.equals(8, input.positionSync()); | 337 Expect.equals(8, input.positionSync()); |
345 input.closeSync(); | 338 input.closeSync(); |
346 return 1; | 339 return 1; |
347 } | 340 } |
348 | 341 |
349 static int testTruncate() { | 342 static int testTruncate() { |
350 File file = new File(tempDirectory.path + "/out_truncate"); | 343 File file = new File(tempDirectory.path + "/out_truncate"); |
351 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; | 344 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; |
352 file.errorHandler = (error) { | 345 file.errorHandler = (error) { |
353 Expect.fail("testTruncate: No errors expected"); | 346 Expect.fail("testTruncate: No errors expected"); |
354 }; | 347 }; |
355 file.openHandler = () { | 348 file.openHandler = (RandomAccessFile openedFile) { |
356 file.noPendingWriteHandler = () { | 349 openedFile.noPendingWriteHandler = () { |
357 file.lengthHandler = (length) { | 350 openedFile.lengthHandler = (length) { |
358 Expect.equals(10, length); | 351 Expect.equals(10, length); |
359 file.truncateHandler = () { | 352 openedFile.truncateHandler = () { |
360 file.lengthHandler = (length) { | 353 openedFile.lengthHandler = (length) { |
361 Expect.equals(5, length); | 354 Expect.equals(5, length); |
362 file.closeHandler = () { | 355 openedFile.closeHandler = () { |
363 file.deleteHandler = () { | 356 file.deleteHandler = () { |
364 file.existsHandler = (exists) { | 357 file.existsHandler = (exists) { |
365 Expect.isFalse(exists); | 358 Expect.isFalse(exists); |
366 asyncTestDone(); | 359 asyncTestDone(); |
367 }; | 360 }; |
368 file.exists(); | 361 file.exists(); |
369 }; | 362 }; |
370 file.delete(); | 363 file.delete(); |
371 }; | 364 }; |
372 file.close(); | 365 openedFile.close(); |
373 }; | 366 }; |
374 file.length(); | 367 openedFile.length(); |
375 }; | 368 }; |
376 file.truncate(5); | 369 openedFile.truncate(5); |
377 }; | 370 }; |
378 file.length(); | 371 openedFile.length(); |
379 }; | 372 }; |
380 file.writeList(buffer, 0, 10); | 373 openedFile.writeList(buffer, 0, 10); |
381 }; | 374 }; |
382 asyncTestStarted(); | 375 asyncTestStarted(); |
383 file.open(true); | 376 file.open(true); |
384 return 1; | 377 return 1; |
385 } | 378 } |
386 | 379 |
387 static int testTruncateSync() { | 380 static int testTruncateSync() { |
388 File file = new File(tempDirectory.path + "/out_truncate_sync"); | 381 File file = new File(tempDirectory.path + "/out_truncate_sync"); |
389 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; | 382 List buffer = const [65, 65, 65, 65, 65, 65, 65, 65, 65, 65]; |
390 file.openSync(true); | 383 RandomAccessFile openedFile = file.openSync(true); |
391 file.writeListSync(buffer, 0, 10); | 384 openedFile.writeListSync(buffer, 0, 10); |
392 Expect.equals(10, file.lengthSync()); | 385 Expect.equals(10, openedFile.lengthSync()); |
393 file.truncateSync(5); | 386 openedFile.truncateSync(5); |
394 Expect.equals(5, file.lengthSync()); | 387 Expect.equals(5, openedFile.lengthSync()); |
395 file.closeSync(); | 388 openedFile.closeSync(); |
396 file.deleteSync(); | 389 file.deleteSync(); |
397 Expect.isFalse(file.existsSync()); | 390 Expect.isFalse(file.existsSync()); |
398 return 1; | 391 return 1; |
399 } | 392 } |
400 | 393 |
401 // Tests exception handling after file was closed. | 394 // Tests exception handling after file was closed. |
402 static int testCloseException() { | 395 static int testCloseException() { |
403 bool exceptionCaught = false; | 396 bool exceptionCaught = false; |
404 bool wrongExceptionCaught = false; | 397 bool wrongExceptionCaught = false; |
405 File input = new File(tempDirectory.path + "/out_close_exception"); | 398 File input = new File(tempDirectory.path + "/out_close_exception"); |
406 input.openSync(true); | 399 RandomAccessFile openedFile = input.openSync(true); |
407 input.closeSync(); | 400 openedFile.closeSync(); |
408 try { | 401 try { |
409 input.readByteSync(); | 402 openedFile.readByteSync(); |
410 } catch (FileIOException ex) { | 403 } catch (FileIOException ex) { |
411 exceptionCaught = true; | 404 exceptionCaught = true; |
412 } catch (Exception ex) { | 405 } catch (Exception ex) { |
413 wrongExceptionCaught = true; | 406 wrongExceptionCaught = true; |
414 } | 407 } |
415 Expect.equals(true, exceptionCaught); | 408 Expect.equals(true, exceptionCaught); |
416 Expect.equals(true, !wrongExceptionCaught); | 409 Expect.equals(true, !wrongExceptionCaught); |
417 exceptionCaught = false; | 410 exceptionCaught = false; |
418 try { | 411 try { |
419 input.writeByteSync(1); | 412 openedFile.writeByteSync(1); |
420 } catch (FileIOException ex) { | 413 } catch (FileIOException ex) { |
421 exceptionCaught = true; | 414 exceptionCaught = true; |
422 } catch (Exception ex) { | 415 } catch (Exception ex) { |
423 wrongExceptionCaught = true; | 416 wrongExceptionCaught = true; |
424 } | 417 } |
425 Expect.equals(true, exceptionCaught); | 418 Expect.equals(true, exceptionCaught); |
426 Expect.equals(true, !wrongExceptionCaught); | 419 Expect.equals(true, !wrongExceptionCaught); |
427 exceptionCaught = false; | 420 exceptionCaught = false; |
428 try { | 421 try { |
429 input.writeStringSync("Test"); | 422 openedFile.writeStringSync("Test"); |
430 } catch (FileIOException ex) { | 423 } catch (FileIOException ex) { |
431 exceptionCaught = true; | 424 exceptionCaught = true; |
432 } catch (Exception ex) { | 425 } catch (Exception ex) { |
433 wrongExceptionCaught = true; | 426 wrongExceptionCaught = true; |
434 } | 427 } |
435 Expect.equals(true, exceptionCaught); | 428 Expect.equals(true, exceptionCaught); |
436 Expect.equals(true, !wrongExceptionCaught); | 429 Expect.equals(true, !wrongExceptionCaught); |
437 exceptionCaught = false; | 430 exceptionCaught = false; |
438 try { | 431 try { |
439 List<int> buffer = new List<int>(100); | 432 List<int> buffer = new List<int>(100); |
440 input.readListSync(buffer, 0, 10); | 433 openedFile.readListSync(buffer, 0, 10); |
441 } catch (FileIOException ex) { | 434 } catch (FileIOException ex) { |
442 exceptionCaught = true; | 435 exceptionCaught = true; |
443 } catch (Exception ex) { | 436 } catch (Exception ex) { |
444 wrongExceptionCaught = true; | 437 wrongExceptionCaught = true; |
445 } | 438 } |
446 Expect.equals(true, exceptionCaught); | 439 Expect.equals(true, exceptionCaught); |
447 Expect.equals(true, !wrongExceptionCaught); | 440 Expect.equals(true, !wrongExceptionCaught); |
448 exceptionCaught = false; | 441 exceptionCaught = false; |
449 try { | 442 try { |
450 List<int> buffer = new List<int>(100); | 443 List<int> buffer = new List<int>(100); |
451 input.writeListSync(buffer, 0, 10); | 444 openedFile.writeListSync(buffer, 0, 10); |
452 } catch (FileIOException ex) { | 445 } catch (FileIOException ex) { |
453 exceptionCaught = true; | 446 exceptionCaught = true; |
454 } catch (Exception ex) { | 447 } catch (Exception ex) { |
455 wrongExceptionCaught = true; | 448 wrongExceptionCaught = true; |
456 } | 449 } |
457 Expect.equals(true, exceptionCaught); | 450 Expect.equals(true, exceptionCaught); |
458 Expect.equals(true, !wrongExceptionCaught); | 451 Expect.equals(true, !wrongExceptionCaught); |
459 exceptionCaught = false; | 452 exceptionCaught = false; |
460 try { | 453 try { |
461 input.positionSync(); | 454 openedFile.positionSync(); |
462 } catch (FileIOException ex) { | 455 } catch (FileIOException ex) { |
463 exceptionCaught = true; | 456 exceptionCaught = true; |
464 } catch (Exception ex) { | 457 } catch (Exception ex) { |
465 wrongExceptionCaught = true; | 458 wrongExceptionCaught = true; |
466 } | 459 } |
467 Expect.equals(true, exceptionCaught); | 460 Expect.equals(true, exceptionCaught); |
468 Expect.equals(true, !wrongExceptionCaught); | 461 Expect.equals(true, !wrongExceptionCaught); |
469 exceptionCaught = false; | 462 exceptionCaught = false; |
470 try { | 463 try { |
471 input.lengthSync(); | 464 openedFile.lengthSync(); |
472 } catch (FileIOException ex) { | 465 } catch (FileIOException ex) { |
473 exceptionCaught = true; | 466 exceptionCaught = true; |
474 } catch (Exception ex) { | 467 } catch (Exception ex) { |
475 wrongExceptionCaught = true; | 468 wrongExceptionCaught = true; |
476 } | 469 } |
477 Expect.equals(true, exceptionCaught); | 470 Expect.equals(true, exceptionCaught); |
478 Expect.equals(true, !wrongExceptionCaught); | 471 Expect.equals(true, !wrongExceptionCaught); |
479 exceptionCaught = false; | 472 exceptionCaught = false; |
480 try { | 473 try { |
481 input.flushSync(); | 474 openedFile.flushSync(); |
482 } catch (FileIOException ex) { | 475 } catch (FileIOException ex) { |
483 exceptionCaught = true; | 476 exceptionCaught = true; |
484 } catch (Exception ex) { | 477 } catch (Exception ex) { |
485 wrongExceptionCaught = true; | 478 wrongExceptionCaught = true; |
486 } | 479 } |
487 Expect.equals(true, exceptionCaught); | 480 Expect.equals(true, exceptionCaught); |
488 Expect.equals(true, !wrongExceptionCaught); | 481 Expect.equals(true, !wrongExceptionCaught); |
489 input.deleteSync(); | 482 input.deleteSync(); |
490 return 1; | 483 return 1; |
491 } | 484 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 Expect.equals(true, !wrongExceptionCaught); | 516 Expect.equals(true, !wrongExceptionCaught); |
524 file.deleteSync(); | 517 file.deleteSync(); |
525 return 1; | 518 return 1; |
526 } | 519 } |
527 | 520 |
528 // Tests buffer out of bounds exception. | 521 // Tests buffer out of bounds exception. |
529 static int testBufferOutOfBoundsException() { | 522 static int testBufferOutOfBoundsException() { |
530 bool exceptionCaught = false; | 523 bool exceptionCaught = false; |
531 bool wrongExceptionCaught = false; | 524 bool wrongExceptionCaught = false; |
532 File file = new File(tempDirectory.path + "/out_buffer_out_of_bounds"); | 525 File file = new File(tempDirectory.path + "/out_buffer_out_of_bounds"); |
533 file.openSync(true); | 526 RandomAccessFile openedFile = file.openSync(true); |
534 try { | 527 try { |
535 List<int> buffer = new List<int>(10); | 528 List<int> buffer = new List<int>(10); |
536 bool readDone = file.readListSync(buffer, 0, 12); | 529 bool readDone = openedFile.readListSync(buffer, 0, 12); |
537 } catch (IndexOutOfRangeException ex) { | 530 } catch (IndexOutOfRangeException ex) { |
538 exceptionCaught = true; | 531 exceptionCaught = true; |
539 } catch (Exception ex) { | 532 } catch (Exception ex) { |
540 wrongExceptionCaught = true; | 533 wrongExceptionCaught = true; |
541 } | 534 } |
542 Expect.equals(true, exceptionCaught); | 535 Expect.equals(true, exceptionCaught); |
543 Expect.equals(true, !wrongExceptionCaught); | 536 Expect.equals(true, !wrongExceptionCaught); |
544 exceptionCaught = false; | 537 exceptionCaught = false; |
545 try { | 538 try { |
546 List<int> buffer = new List<int>(10); | 539 List<int> buffer = new List<int>(10); |
547 bool readDone = file.readListSync(buffer, 6, 6); | 540 bool readDone = openedFile.readListSync(buffer, 6, 6); |
548 } catch (IndexOutOfRangeException ex) { | 541 } catch (IndexOutOfRangeException ex) { |
549 exceptionCaught = true; | 542 exceptionCaught = true; |
550 } catch (Exception ex) { | 543 } catch (Exception ex) { |
551 wrongExceptionCaught = true; | 544 wrongExceptionCaught = true; |
552 } | 545 } |
553 Expect.equals(true, exceptionCaught); | 546 Expect.equals(true, exceptionCaught); |
554 Expect.equals(true, !wrongExceptionCaught); | 547 Expect.equals(true, !wrongExceptionCaught); |
555 exceptionCaught = false; | 548 exceptionCaught = false; |
556 try { | 549 try { |
557 List<int> buffer = new List<int>(10); | 550 List<int> buffer = new List<int>(10); |
558 bool readDone = file.readListSync(buffer, -1, 1); | 551 bool readDone = openedFile.readListSync(buffer, -1, 1); |
559 } catch (IndexOutOfRangeException ex) { | 552 } catch (IndexOutOfRangeException ex) { |
560 exceptionCaught = true; | 553 exceptionCaught = true; |
561 } catch (Exception ex) { | 554 } catch (Exception ex) { |
562 wrongExceptionCaught = true; | 555 wrongExceptionCaught = true; |
563 } | 556 } |
564 Expect.equals(true, exceptionCaught); | 557 Expect.equals(true, exceptionCaught); |
565 Expect.equals(true, !wrongExceptionCaught); | 558 Expect.equals(true, !wrongExceptionCaught); |
566 exceptionCaught = false; | 559 exceptionCaught = false; |
567 try { | 560 try { |
568 List<int> buffer = new List<int>(10); | 561 List<int> buffer = new List<int>(10); |
569 bool readDone = file.readListSync(buffer, 0, -1); | 562 bool readDone = openedFile.readListSync(buffer, 0, -1); |
570 } catch (IndexOutOfRangeException ex) { | 563 } catch (IndexOutOfRangeException ex) { |
571 exceptionCaught = true; | 564 exceptionCaught = true; |
572 } catch (Exception ex) { | 565 } catch (Exception ex) { |
573 wrongExceptionCaught = true; | 566 wrongExceptionCaught = true; |
574 } | 567 } |
575 Expect.equals(true, exceptionCaught); | 568 Expect.equals(true, exceptionCaught); |
576 Expect.equals(true, !wrongExceptionCaught); | 569 Expect.equals(true, !wrongExceptionCaught); |
577 exceptionCaught = false; | 570 exceptionCaught = false; |
578 try { | 571 try { |
579 List<int> buffer = new List<int>(10); | 572 List<int> buffer = new List<int>(10); |
580 bool readDone = file.writeListSync(buffer, 0, 12); | 573 bool readDone = openedFile.writeListSync(buffer, 0, 12); |
581 } catch (IndexOutOfRangeException ex) { | 574 } catch (IndexOutOfRangeException ex) { |
582 exceptionCaught = true; | 575 exceptionCaught = true; |
583 } catch (Exception ex) { | 576 } catch (Exception ex) { |
584 wrongExceptionCaught = true; | 577 wrongExceptionCaught = true; |
585 } | 578 } |
586 Expect.equals(true, exceptionCaught); | 579 Expect.equals(true, exceptionCaught); |
587 Expect.equals(true, !wrongExceptionCaught); | 580 Expect.equals(true, !wrongExceptionCaught); |
588 exceptionCaught = false; | 581 exceptionCaught = false; |
589 try { | 582 try { |
590 List<int> buffer = new List<int>(10); | 583 List<int> buffer = new List<int>(10); |
591 bool readDone = file.writeListSync(buffer, 6, 6); | 584 bool readDone = openedFile.writeListSync(buffer, 6, 6); |
592 } catch (IndexOutOfRangeException ex) { | 585 } catch (IndexOutOfRangeException ex) { |
593 exceptionCaught = true; | 586 exceptionCaught = true; |
594 } catch (Exception ex) { | 587 } catch (Exception ex) { |
595 wrongExceptionCaught = true; | 588 wrongExceptionCaught = true; |
596 } | 589 } |
597 Expect.equals(true, exceptionCaught); | 590 Expect.equals(true, exceptionCaught); |
598 Expect.equals(true, !wrongExceptionCaught); | 591 Expect.equals(true, !wrongExceptionCaught); |
599 exceptionCaught = false; | 592 exceptionCaught = false; |
600 try { | 593 try { |
601 List<int> buffer = new List<int>(10); | 594 List<int> buffer = new List<int>(10); |
602 bool readDone = file.writeListSync(buffer, -1, 1); | 595 bool readDone = openedFile.writeListSync(buffer, -1, 1); |
603 } catch (IndexOutOfRangeException ex) { | 596 } catch (IndexOutOfRangeException ex) { |
604 exceptionCaught = true; | 597 exceptionCaught = true; |
605 } catch (Exception ex) { | 598 } catch (Exception ex) { |
606 wrongExceptionCaught = true; | 599 wrongExceptionCaught = true; |
607 } | 600 } |
608 Expect.equals(true, exceptionCaught); | 601 Expect.equals(true, exceptionCaught); |
609 Expect.equals(true, !wrongExceptionCaught); | 602 Expect.equals(true, !wrongExceptionCaught); |
610 exceptionCaught = false; | 603 exceptionCaught = false; |
611 try { | 604 try { |
612 List<int> buffer = new List<int>(10); | 605 List<int> buffer = new List<int>(10); |
613 bool readDone = file.writeListSync(buffer, 0, -1); | 606 bool readDone = openedFile.writeListSync(buffer, 0, -1); |
614 } catch (IndexOutOfRangeException ex) { | 607 } catch (IndexOutOfRangeException ex) { |
615 exceptionCaught = true; | 608 exceptionCaught = true; |
616 } catch (Exception ex) { | 609 } catch (Exception ex) { |
617 wrongExceptionCaught = true; | 610 wrongExceptionCaught = true; |
618 } | 611 } |
619 Expect.equals(true, exceptionCaught); | 612 Expect.equals(true, exceptionCaught); |
620 Expect.equals(true, !wrongExceptionCaught); | 613 Expect.equals(true, !wrongExceptionCaught); |
621 file.closeSync(); | 614 openedFile.closeSync(); |
622 file.deleteSync(); | 615 file.deleteSync(); |
623 return 1; | 616 return 1; |
624 } | 617 } |
625 | 618 |
626 static int testMixedSyncAndAsync() { | 619 static int testMixedSyncAndAsync() { |
627 var name = getFilename("tests/vm/data/fixed_length_file"); | 620 var name = getFilename("tests/vm/data/fixed_length_file"); |
628 var f = new File(name); | 621 var f = new File(name); |
629 f.errorHandler = (s) { | 622 f.errorHandler = (s) { |
630 Expect.fail("No errors expected"); | 623 Expect.fail("No errors expected"); |
631 }; | 624 }; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 Expect.equals(1, testCloseExceptionStream()); | 660 Expect.equals(1, testCloseExceptionStream()); |
668 Expect.equals(1, testBufferOutOfBoundsException()); | 661 Expect.equals(1, testBufferOutOfBoundsException()); |
669 asyncTestDone(); | 662 asyncTestDone(); |
670 }); | 663 }); |
671 } | 664 } |
672 } | 665 } |
673 | 666 |
674 main() { | 667 main() { |
675 FileTest.testMain(); | 668 FileTest.testMain(); |
676 } | 669 } |
OLD | NEW |