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

Side by Side Diff: tests/standalone/io/file_invalid_arguments_test.dart

Issue 18090003: Add FileException.path and clean up file exceptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: CLean up test and remove debug code. Created 7 years, 5 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
« no previous file with comments | « sdk/lib/io/link.dart ('k') | no next file » | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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:async"; 5 import "dart:async";
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import "dart:io"; 7 import "dart:io";
8 import "dart:isolate"; 8 import "dart:isolate";
9 9
10 void testReadInvalidArgs(arg) { 10 void testReadInvalidArgs(arg) {
11 var port = new ReceivePort();
12 String filename = getFilename("tests/vm/data/fixed_length_file"); 11 String filename = getFilename("tests/vm/data/fixed_length_file");
13 var file = (new File(filename)).openSync(); 12 var file = (new File(filename)).openSync();
14 try { 13 Expect.throws(() => file.readSync(arg),
15 file.readSync(arg); 14 (e) => e is ArgumentError);
16 Expect.fail('exception expected');
17 } catch (e) {
18 Expect.isTrue(e is FileException);
19 Expect.isTrue(e.toString().contains('Invalid arguments'));
20 }
21 15
22 var errors = 0; 16 Expect.throws(() => file.read(arg),
23 var readFuture = file.read(arg); 17 (e) => e is ArgumentError);
24 readFuture.then((bytes) {
25 Expect.fail('exception expected');
26 }).catchError((error) {
27 errors++;
28 Expect.isTrue(error is FileException);
29 Expect.isTrue(error.toString().contains('Invalid arguments'));
30 file.close().then((ignore) {
31 Expect.equals(1, errors);
32 port.close();
33 });
34 });
35 } 18 }
36 19
37 void testReadIntoInvalidArgs(buffer, start, end) { 20 void testReadIntoInvalidArgs(buffer, start, end) {
38 var port = new ReceivePort();
39 String filename = getFilename("tests/vm/data/fixed_length_file"); 21 String filename = getFilename("tests/vm/data/fixed_length_file");
40 var file = (new File(filename)).openSync(); 22 var file = (new File(filename)).openSync();
41 try { 23 Expect.throws(() => file.readIntoSync(buffer, start, end),
42 file.readIntoSync(buffer, start, end); 24 (e) => e is ArgumentError);
43 Expect.fail('exception expected');
44 } catch (e) {
45 Expect.isTrue(e is FileException);
46 Expect.isTrue(e.toString().contains('Invalid arguments'));
47 }
48 25
49 var errors = 0; 26 Expect.throws(() => file.readInto(buffer, start, end),
50 var readIntoFuture = file.readInto(buffer, start, end); 27 (e) => e is ArgumentError);
51 readIntoFuture.then((bytes) {
52 Expect.fail('exception expected');
53 }).catchError((error) {
54 errors++;
55 Expect.isTrue(error is FileException);
56 Expect.isTrue(error.toString().contains('Invalid arguments'));
57 file.close().then((ignore) {
58 Expect.equals(1, errors);
59 port.close();
60 });
61 });
62 } 28 }
63 29
64 void testWriteByteInvalidArgs(value) { 30 void testWriteByteInvalidArgs(value) {
65 var port = new ReceivePort();
66 String filename = getFilename("tests/vm/data/fixed_length_file"); 31 String filename = getFilename("tests/vm/data/fixed_length_file");
67 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); 32 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE);
68 try { 33 Expect.throws(() => file.writeByteSync(value),
69 file.writeByteSync(value); 34 (e) => e is ArgumentError);
70 Expect.fail('exception expected');
71 } catch (e) {
72 Expect.isTrue(e is FileException);
73 Expect.isTrue(e.toString().contains('Invalid argument'));
74 }
75 35
76 var writeByteFuture = file.writeByte(value); 36 Expect.throws(() => file.writeByte(value),
77 writeByteFuture.then((ignore) { 37 (e) => e is ArgumentError);
78 Expect.fail('exception expected');
79 }).catchError((error) {
80 Expect.isTrue(error is FileException);
81 Expect.isTrue(error.toString().contains('Invalid argument'));
82 file.close().then((ignore) {
83 port.close();
84 });
85 });
86 } 38 }
87 39
88 void testWriteFromInvalidArgs(buffer, start, end) { 40 void testWriteFromInvalidArgs(buffer, start, end) {
89 var port = new ReceivePort();
90 String filename = getFilename("tests/vm/data/fixed_length_file"); 41 String filename = getFilename("tests/vm/data/fixed_length_file");
91 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); 42 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE);
92 try { 43 Expect.throws(() => file.writeFromSync(buffer, start, end),
93 file.writeFromSync(buffer, start, end); 44 (e) => e is ArgumentError);
94 Expect.fail('exception expected');
95 } catch (e) {
96 Expect.isTrue(e is FileException);
97 Expect.isTrue(e.toString().contains('Invalid arguments'));
98 }
99 45
100 var writeFromFuture = file.writeFrom(buffer, start, end); 46 Expect.throws(() => file.writeFrom(buffer, start, end),
101 writeFromFuture.then((ignore) { 47 (e) => e is ArgumentError);
102 Expect.fail('exception expected');
103 }).catchError((error) {
104 Expect.isTrue(error is FileException);
105 Expect.isTrue(error.toString().contains('Invalid arguments'));
106 file.close().then((ignore) {
107 port.close();
108 });
109 });
110 } 48 }
111 49
112 void testWriteStringInvalidArgs(string, encoding) { 50 void testWriteStringInvalidArgs(string, encoding) {
113 var port = new ReceivePort();
114 String filename = getFilename("tests/vm/data/fixed_length_file"); 51 String filename = getFilename("tests/vm/data/fixed_length_file");
115 var file = new File("${filename}_out").openSync(mode: FileMode.WRITE); 52 var file = new File("${filename}_out").openSync(mode: FileMode.WRITE);
116 try { 53 Expect.throws(() => file.writeStringSync(string, encoding: encoding),
117 file.writeStringSync(string, encoding: encoding); 54 (e) => e is ArgumentError);
118 Expect.fail('exception expected');
119 } catch (e) {
120 Expect.isTrue(e is FileException);
121 }
122 55
123 var writeStringFuture = file.writeString(string, encoding: encoding); 56 Expect.throws(() => file.writeString(string, encoding: encoding),
124 writeStringFuture.then((ignore) { 57 (e) => e is ArgumentError);
125 Expect.fail('exception expected');
126 }).catchError((error) {
127 Expect.isTrue(error is FileException);
128 file.close().then((ignore) {
129 port.close();
130 });
131 });
132 } 58 }
133 59
134 Future futureThrows(Future result) { 60 Future futureThrows(Future result) {
135 return result.then((value) { 61 return result.then((value) {
136 throw new ExpectException( 62 throw new ExpectException(
137 "futureThrows received $value instead of an exception"); 63 "futureThrows received $value instead of an exception");
138 }, 64 },
139 onError: (_) => null 65 onError: (_) => null
140 ); 66 );
141 } 67 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 testReadIntoInvalidArgs(12, 0, 1); 101 testReadIntoInvalidArgs(12, 0, 1);
176 testReadIntoInvalidArgs(new List(10), '0', 1); 102 testReadIntoInvalidArgs(new List(10), '0', 1);
177 testReadIntoInvalidArgs(new List(10), 0, '1'); 103 testReadIntoInvalidArgs(new List(10), 0, '1');
178 testWriteByteInvalidArgs('asdf'); 104 testWriteByteInvalidArgs('asdf');
179 testWriteFromInvalidArgs(12, 0, 1); 105 testWriteFromInvalidArgs(12, 0, 1);
180 testWriteFromInvalidArgs(new List(10), '0', 1); 106 testWriteFromInvalidArgs(new List(10), '0', 1);
181 testWriteFromInvalidArgs(new List(10), 0, '1'); 107 testWriteFromInvalidArgs(new List(10), 0, '1');
182 testWriteStringInvalidArgs("Hello, world", 42); 108 testWriteStringInvalidArgs("Hello, world", 42);
183 testFileSystemEntity(); 109 testFileSystemEntity();
184 } 110 }
OLDNEW
« no previous file with comments | « sdk/lib/io/link.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698