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

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

Issue 10984086: Fix standalone/io/file_invalid_arguments_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 2 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 | « no previous file | dart/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) 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) {
9 var file = new File(name);
10 try {
11 file.openSync();
12 Expect.fail('exception expected');
13 } catch (e) {
14 Expect.isTrue(e is ArgumentError);
15 }
16
17 var openFuture = file.open(FileMode.READ);
18 openFuture.handleException((e) {
19 Expect.isTrue(e is ArgumentError);
20 return true;
21 });
22 openFuture.then((opened) {
23 Expect.fail('non-string name open');
24 });
25 }
26
27 static void testExistsInvalidArgs(name) {
28 var file = new File(name);
29 try {
30 file.existsSync();
31 Expect.fail('exception expected');
32 } catch (e) {
33 Expect.isTrue(e is ArgumentError);
34 }
35
36 var existsFuture = file.exists();
37 existsFuture.handleException((e) {
38 Expect.isTrue(e is ArgumentError);
39 return true;
40 });
41 existsFuture.then((bool) {
42 Expect.fail('non-string name exists');
43 });
44 }
45
46 static void testCreateInvalidArgs(name) {
47 var file = new File(name);
48 try {
49 file.createSync();
50 Expect.fail('exception expected');
51 } catch (e) {
52 Expect.isTrue(e is ArgumentError);
53 }
54
55 var createFuture = file.create();
56 createFuture.handleException((e) {
57 Expect.isTrue(e is ArgumentError);
58 return true;
59 });
60 createFuture.then((ignore) => Expect.fail('non-string name exists'));
61 }
62
63 static void testReadListInvalidArgs(buffer, offset, length) { 8 static void testReadListInvalidArgs(buffer, offset, length) {
64 String filename = getFilename("tests/vm/data/fixed_length_file"); 9 String filename = getFilename("tests/vm/data/fixed_length_file");
65 var file = (new File(filename)).openSync(); 10 var file = (new File(filename)).openSync();
66 try { 11 try {
67 file.readListSync(buffer, offset, length); 12 file.readListSync(buffer, offset, length);
68 Expect.fail('exception expected'); 13 Expect.fail('exception expected');
69 } catch (e) { 14 } catch (e) {
70 Expect.isTrue(e is FileIOException); 15 Expect.isTrue(e is FileIOException);
71 Expect.isTrue(e.toString().contains('Invalid arguments')); 16 Expect.isTrue(e.toString().contains('Invalid arguments'));
72 } 17 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 file.onNoPendingWrites = () { 99 file.onNoPendingWrites = () {
155 if (++calls > 1) Expect.fail('write list invalid argument'); 100 if (++calls > 1) Expect.fail('write list invalid argument');
156 }; 101 };
157 file.writeString(string); 102 file.writeString(string);
158 file.onClosed = () { 103 file.onClosed = () {
159 Expect.equals(1, errors); 104 Expect.equals(1, errors);
160 }; 105 };
161 file.close(); 106 file.close();
162 } 107 }
163 108
164 static void testFullPathInvalidArgs(name) {
165 var file = new File(name);
166 try {
167 file.fullPathSync();
168 Expect.fail('exception expected');
169 } catch (e) {
170 Expect.isTrue(e is ArgumentError);
171 }
172
173 var fullPathFuture = file.fullPath();
174 fullPathFuture.handleException((e) {
175 Expect.isTrue(e is ArgumentError);
176 return true;
177 });
178 fullPathFuture.then((path) {
179 Expect.fail('full path invalid argument');
180 });
181 }
182
183 static String getFilename(String path) => 109 static String getFilename(String path) =>
184 new File(path).existsSync() ? path : 'runtime/$path'; 110 new File(path).existsSync() ? path : 'runtime/$path';
185 } 111 }
186 112
187 main() { 113 main() {
188 FileTest.testOpenInvalidArgs(0);
189 FileTest.testExistsInvalidArgs(0);
190 FileTest.testCreateInvalidArgs(0);
191 FileTest.testReadListInvalidArgs(12, 0, 1); 114 FileTest.testReadListInvalidArgs(12, 0, 1);
192 FileTest.testReadListInvalidArgs(new List(10), '0', 1); 115 FileTest.testReadListInvalidArgs(new List(10), '0', 1);
193 FileTest.testReadListInvalidArgs(new List(10), 0, '1'); 116 FileTest.testReadListInvalidArgs(new List(10), 0, '1');
194 FileTest.testWriteByteInvalidArgs('asdf'); 117 FileTest.testWriteByteInvalidArgs('asdf');
195 FileTest.testWriteListInvalidArgs(12, 0, 1); 118 FileTest.testWriteListInvalidArgs(12, 0, 1);
196 FileTest.testWriteListInvalidArgs(new List(10), '0', 1); 119 FileTest.testWriteListInvalidArgs(new List(10), '0', 1);
197 FileTest.testWriteListInvalidArgs(new List(10), 0, '1'); 120 FileTest.testWriteListInvalidArgs(new List(10), 0, '1');
198 FileTest.testFullPathInvalidArgs(12);
199 } 121 }
OLDNEW
« no previous file with comments | « no previous file | dart/tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698