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

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

Powered by Google App Engine
This is Rietveld 408576698