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

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

Issue 8372056: Fix file test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Test for file read functionality. 9 // Test for file read functionality.
10 static int testReadStream() { 10 static int testReadStream() {
(...skipping 26 matching lines...) Expand all
37 static int testReadWriteStream() { 37 static int testReadWriteStream() {
38 // Read a file. 38 // Read a file.
39 String inFilename = getFilename("tests/vm/data/fixed_length_file"); 39 String inFilename = getFilename("tests/vm/data/fixed_length_file");
40 File file = new File(inFilename); 40 File file = new File(inFilename);
41 FileInputStream input = file.openInputStream(); 41 FileInputStream input = file.openInputStream();
42 List<int> buffer1 = new List<int>(42); 42 List<int> buffer1 = new List<int>(42);
43 int bytesRead = input.readInto(buffer1, 0, 42); 43 int bytesRead = input.readInto(buffer1, 0, 42);
44 Expect.equals(42, bytesRead); 44 Expect.equals(42, bytesRead);
45 input.close(); 45 input.close();
46 // Write the contents of the file just read into another file. 46 // Write the contents of the file just read into another file.
47 String outFilename = getFilename("tests/vm/data/fixed_length_file_out"); 47 String outFilename = getFilename("tests/vm/data/fixed_length_file");
48 file = new File(outFilename); 48 file = new File(outFilename + "_out");
49 OutputStream output = file.openOutputStream(); 49 OutputStream output = file.openOutputStream();
50 bool writeDone = output.writeFrom(buffer1, 0, 42); 50 bool writeDone = output.writeFrom(buffer1, 0, 42);
51 Expect.equals(true, writeDone); 51 Expect.equals(true, writeDone);
52 output.close(); 52 output.close();
53 // Now read the contents of the file just written. 53 // Now read the contents of the file just written.
54 List<int> buffer2 = new List<int>(42); 54 List<int> buffer2 = new List<int>(42);
55 file = new File(outFilename); 55 file = new File(outFilename);
56 input = file.openInputStream(); 56 input = file.openInputStream();
57 bytesRead = input.readInto(buffer2, 0, 42); 57 bytesRead = input.readInto(buffer2, 0, 42);
58 input.close(); 58 input.close();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 file.errorHandler = (s) { 131 file.errorHandler = (s) {
132 Expect.fail("No errors expected"); 132 Expect.fail("No errors expected");
133 }; 133 };
134 file.openHandler = () { 134 file.openHandler = () {
135 List<int> buffer1 = new List<int>(42); 135 List<int> buffer1 = new List<int>(42);
136 file.readListHandler = (bytes_read) { 136 file.readListHandler = (bytes_read) {
137 Expect.equals(42, bytes_read); 137 Expect.equals(42, bytes_read);
138 file.closeHandler = () { 138 file.closeHandler = () {
139 // Write the contents of the file just read into another file. 139 // Write the contents of the file just read into another file.
140 String outFilenameBase = 140 String outFilenameBase =
141 getFilename("tests/vm/data/fixed_length_file_out"); 141 getFilename("tests/vm/data/fixed_length_file");
142 file = new File(outFilenameBase); 142 file = new File(outFilenameBase + "_out");
143 file.errorHandler = (s) { 143 file.errorHandler = (s) {
144 Expect.fail("No errors expected"); 144 Expect.fail("No errors expected");
145 }; 145 };
146 file.openHandler = () { 146 file.openHandler = () {
147 file.noPendingWriteHandler = () { 147 file.noPendingWriteHandler = () {
148 file.closeHandler = () { 148 file.closeHandler = () {
149 // Now read the contents of the file just written. 149 // Now read the contents of the file just written.
150 List<int> buffer2 = new List<int>(bytes_read); 150 List<int> buffer2 = new List<int>(bytes_read);
151 file = new File(getFilename(outFilenameBase)); 151 file = new File(getFilename(outFilenameBase));
152 file.errorHandler = (s) { 152 file.errorHandler = (s) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 String inFilename = getFilename("tests/vm/data/fixed_length_file"); 189 String inFilename = getFilename("tests/vm/data/fixed_length_file");
190 File file = new File(inFilename); 190 File file = new File(inFilename);
191 file.openSync(); 191 file.openSync();
192 List<int> buffer1 = new List<int>(42); 192 List<int> buffer1 = new List<int>(42);
193 int bytes_read = 0; 193 int bytes_read = 0;
194 int bytes_written = 0; 194 int bytes_written = 0;
195 bytes_read = file.readListSync(buffer1, 0, 42); 195 bytes_read = file.readListSync(buffer1, 0, 42);
196 Expect.equals(42, bytes_read); 196 Expect.equals(42, bytes_read);
197 file.closeSync(); 197 file.closeSync();
198 // Write the contents of the file just read into another file. 198 // Write the contents of the file just read into another file.
199 String outFilenameBase = getFilename("tests/vm/data/fixed_length_file_out"); 199 String outFilenameBase = getFilename("tests/vm/data/fixed_length_file");
200 file = new File(outFilenameBase); 200 file = new File(outFilenameBase + "_out");
201 file.openSync(true); 201 file.openSync(true);
202 file.writeListSync(buffer1, 0, bytes_read); 202 file.writeListSync(buffer1, 0, bytes_read);
203 file.closeSync(); 203 file.closeSync();
204 // Now read the contents of the file just written. 204 // Now read the contents of the file just written.
205 List<int> buffer2 = new List<int>(bytes_read); 205 List<int> buffer2 = new List<int>(bytes_read);
206 file = new File(getFilename(outFilenameBase)); 206 file = new File(getFilename(outFilenameBase));
207 file.openSync(); 207 file.openSync();
208 bytes_read = file.readListSync(buffer2, 0, 42); 208 bytes_read = file.readListSync(buffer2, 0, 42);
209 Expect.equals(42, bytes_read); 209 Expect.equals(42, bytes_read);
210 file.closeSync(); 210 file.closeSync();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 input.readListSync(buffer, 12, 6); 282 input.readListSync(buffer, 12, 6);
283 Expect.equals(18, input.positionSync()); 283 Expect.equals(18, input.positionSync());
284 input.closeSync(); 284 input.closeSync();
285 return 1; 285 return 1;
286 } 286 }
287 287
288 // Tests exception handling after file was closed. 288 // Tests exception handling after file was closed.
289 static int testCloseException() { 289 static int testCloseException() {
290 bool exceptionCaught = false; 290 bool exceptionCaught = false;
291 bool wrongExceptionCaught = false; 291 bool wrongExceptionCaught = false;
292 String filename = getFilename("tests/vm/data/fixed_length_file_out"); 292 String filename = getFilename("tests/vm/data/fixed_length_file");
293 File input = new File(filename); 293 File input = new File(filename + "_out");
294 input.openSync(true); 294 input.openSync(true);
295 input.closeSync(); 295 input.closeSync();
296 try { 296 try {
297 input.readByteSync(); 297 input.readByteSync();
298 } catch (FileIOException ex) { 298 } catch (FileIOException ex) {
299 exceptionCaught = true; 299 exceptionCaught = true;
300 } catch (Exception ex) { 300 } catch (Exception ex) {
301 wrongExceptionCaught = true; 301 wrongExceptionCaught = true;
302 } 302 }
303 Expect.equals(true, exceptionCaught); 303 Expect.equals(true, exceptionCaught);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 } 374 }
375 Expect.equals(true, exceptionCaught); 375 Expect.equals(true, exceptionCaught);
376 Expect.equals(true, !wrongExceptionCaught); 376 Expect.equals(true, !wrongExceptionCaught);
377 return 1; 377 return 1;
378 } 378 }
379 379
380 // Tests stream exception handling after file was closed. 380 // Tests stream exception handling after file was closed.
381 static int testCloseExceptionStream() { 381 static int testCloseExceptionStream() {
382 bool exceptionCaught = false; 382 bool exceptionCaught = false;
383 bool wrongExceptionCaught = false; 383 bool wrongExceptionCaught = false;
384 String filename = getFilename("tests/vm/data/fixed_length_file_out"); 384 String filename = getFilename("tests/vm/data/fixed_length_file");
385 File file = new File(filename); 385 File file = new File(filename + "_out");
386 FileInputStream input = file.openInputStream(); 386 FileInputStream input = file.openInputStream();
387 input.close(); 387 input.close();
388 try { 388 try {
389 List<int> buffer = new List<int>(42); 389 List<int> buffer = new List<int>(42);
390 input.readInto(buffer, 0, 12); 390 input.readInto(buffer, 0, 12);
391 } catch (FileIOException ex) { 391 } catch (FileIOException ex) {
392 exceptionCaught = true; 392 exceptionCaught = true;
393 } catch (Exception ex) { 393 } catch (Exception ex) {
394 wrongExceptionCaught = true; 394 wrongExceptionCaught = true;
395 } 395 }
(...skipping 12 matching lines...) Expand all
408 } 408 }
409 Expect.equals(true, exceptionCaught); 409 Expect.equals(true, exceptionCaught);
410 Expect.equals(true, !wrongExceptionCaught); 410 Expect.equals(true, !wrongExceptionCaught);
411 return 1; 411 return 1;
412 } 412 }
413 413
414 // Tests buffer out of bounds exception. 414 // Tests buffer out of bounds exception.
415 static int testBufferOutOfBoundsException() { 415 static int testBufferOutOfBoundsException() {
416 bool exceptionCaught = false; 416 bool exceptionCaught = false;
417 bool wrongExceptionCaught = false; 417 bool wrongExceptionCaught = false;
418 String filename = getFilename("tests/vm/data/fixed_length_file_out"); 418 String filename = getFilename("tests/vm/data/fixed_length_file");
419 File file = new File(filename); 419 File file = new File(filename + "_out");
420 file.openSync(true); 420 file.openSync(true);
421 try { 421 try {
422 List<int> buffer = new List<int>(10); 422 List<int> buffer = new List<int>(10);
423 bool readDone = file.readListSync(buffer, 0, 12); 423 bool readDone = file.readListSync(buffer, 0, 12);
424 } catch (IndexOutOfRangeException ex) { 424 } catch (IndexOutOfRangeException ex) {
425 exceptionCaught = true; 425 exceptionCaught = true;
426 } catch (Exception ex) { 426 } catch (Exception ex) {
427 wrongExceptionCaught = true; 427 wrongExceptionCaught = true;
428 } 428 }
429 Expect.equals(true, exceptionCaught); 429 Expect.equals(true, exceptionCaught);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 Expect.equals(1, testCloseException()); 547 Expect.equals(1, testCloseException());
548 Expect.equals(1, testCloseExceptionStream()); 548 Expect.equals(1, testCloseExceptionStream());
549 Expect.equals(1, testBufferOutOfBoundsException()); 549 Expect.equals(1, testBufferOutOfBoundsException());
550 Expect.equals(1, testMixedSyncAndAsync()); 550 Expect.equals(1, testMixedSyncAndAsync());
551 } 551 }
552 } 552 }
553 553
554 main() { 554 main() {
555 FileTest.testMain(); 555 FileTest.testMain();
556 } 556 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698