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

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

Issue 9251012: Fix standalone tests that didn't delete the temporary directories they created. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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 | tests/standalone/src/StreamPipeTest.dart » ('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 static Directory tempDirectory; 9 static Directory tempDirectory;
10 static int numLiveAsyncTests = 0; 10 static int numLiveAsyncTests = 0;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // Delete the output file. 116 // Delete the output file.
117 file.deleteSync(); 117 file.deleteSync();
118 Expect.isFalse(file.existsSync()); 118 Expect.isFalse(file.existsSync());
119 } 119 }
120 120
121 static void testRead() { 121 static void testRead() {
122 // Read a file and check part of it's contents. 122 // Read a file and check part of it's contents.
123 String filename = getFilename("bin/file_test.cc"); 123 String filename = getFilename("bin/file_test.cc");
124 File file = new File(filename); 124 File file = new File(filename);
125 file.errorHandler = (s) { 125 file.errorHandler = (s) {
126 Expect.fail("No errors expected"); 126 Expect.fail("No errors expected : $s");
127 }; 127 };
128 file.openHandler = (RandomAccessFile file) { 128 file.openHandler = (RandomAccessFile file) {
129 List<int> buffer = new List<int>(10); 129 List<int> buffer = new List<int>(10);
130 file.readListHandler = (bytes_read) { 130 file.readListHandler = (bytes_read) {
131 Expect.equals(5, bytes_read); 131 Expect.equals(5, bytes_read);
132 file.readListHandler = (bytes_read) { 132 file.readListHandler = (bytes_read) {
133 Expect.equals(5, bytes_read); 133 Expect.equals(5, bytes_read);
134 Expect.equals(47, buffer[0]); // represents '/' in the file. 134 Expect.equals(47, buffer[0]); // represents '/' in the file.
135 Expect.equals(47, buffer[1]); // represents '/' in the file. 135 Expect.equals(47, buffer[1]); // represents '/' in the file.
136 Expect.equals(32, buffer[2]); // represents ' ' in the file. 136 Expect.equals(32, buffer[2]); // represents ' ' in the file.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 Expect.equals(105, buffer[8]); // represents 'i' in the file. 171 Expect.equals(105, buffer[8]); // represents 'i' in the file.
172 Expect.equals(103, buffer[9]); // represents 'g' in the file. 172 Expect.equals(103, buffer[9]); // represents 'g' in the file.
173 Expect.equals(104, buffer[10]); // represents 'h' in the file. 173 Expect.equals(104, buffer[10]); // represents 'h' in the file.
174 Expect.equals(116, buffer[11]); // represents 't' in the file. 174 Expect.equals(116, buffer[11]); // represents 't' in the file.
175 } 175 }
176 176
177 // Test for file read and write functionality. 177 // Test for file read and write functionality.
178 static void testReadWrite() { 178 static void testReadWrite() {
179 // Read a file. 179 // Read a file.
180 String inFilename = getFilename("tests/vm/data/fixed_length_file"); 180 String inFilename = getFilename("tests/vm/data/fixed_length_file");
181 File file = new File(inFilename); 181 final File file = new File(inFilename);
182 file.errorHandler = (s) { 182 file.errorHandler = (s) {
183 Expect.fail("No errors expected"); 183 Expect.fail("No errors expected : $s");
184 }; 184 };
185 file.openHandler = (RandomAccessFile openedFile) { 185 file.openHandler = (RandomAccessFile openedFile) {
186 openedFile.errorHandler = (s) {
187 Expect.fail("No errors expected : $s");
188 };
186 List<int> buffer1 = new List<int>(42); 189 List<int> buffer1 = new List<int>(42);
187 openedFile.readListHandler = (bytes_read) { 190 openedFile.readListHandler = (bytes_read) {
188 Expect.equals(42, bytes_read); 191 Expect.equals(42, bytes_read);
189 openedFile.closeHandler = () { 192 openedFile.closeHandler = () {
190 // Write the contents of the file just read into another file. 193 // Write the contents of the file just read into another file.
191 String outFilename = tempDirectory.path + "/out_read_write"; 194 String outFilename = tempDirectory.path + "/out_read_write";
192 file = new File(outFilename); 195 final File file2 = new File(outFilename);
193 file.errorHandler = (s) { 196 file2.errorHandler = (s) {
194 Expect.fail("No errors expected"); 197 Expect.fail("No errors expected : $s");
195 }; 198 };
196 file.createHandler = () { 199 file2.createHandler = () {
197 file.fullPathHandler = (s) { 200 file2.fullPathHandler = (s) {
198 Expect.isTrue(new File(s).existsSync()); 201 Expect.isTrue(new File(s).existsSync());
199 if (s[0] != '/' && s[0] != '\\' && s[1] != ':') { 202 if (s[0] != '/' && s[0] != '\\' && s[1] != ':') {
200 Expect.fail("Not a full path"); 203 Expect.fail("Not a full path");
201 } 204 }
202 file.openHandler = (RandomAccessFile openedFile) { 205 file2.openHandler = (RandomAccessFile openedFile2) {
203 openedFile.noPendingWriteHandler = () { 206 openedFile2.errorHandler = (s) {
204 openedFile.closeHandler = () { 207 Expect.fail("No errors expected : $s");
205 // Now read the contents of the file just written. 208 };
209 openedFile2.noPendingWriteHandler = () {
210 openedFile2.closeHandler = () {
206 List<int> buffer2 = new List<int>(bytes_read); 211 List<int> buffer2 = new List<int>(bytes_read);
207 file = new File(outFilename); 212 final File file3 = new File(outFilename);
208 file.errorHandler = (s) { 213 file3.errorHandler = (s) {
209 Expect.fail("No errors expected"); 214 Expect.fail("No errors expected : $s");
210 }; 215 };
211 file.openHandler = (RandomAccessFile openedfile) { 216 file3.openHandler = (RandomAccessFile openedFile3) {
Bill Hesse 2012/01/18 14:51:25 This was the error (openedfile instead of openedFi
212 openedFile.readListHandler = (bytes_read) { 217 openedFile3.errorHandler = (s) {
213 Expect.equals(42, bytes_read); 218 Expect.fail("No errors expected : $s");
214 openedFile.closeHandler = () { 219 };
220 openedFile3.readListHandler = (bytes_read) {
221 Expect.equals(42, bytes_read);
222 openedFile3.closeHandler = () {
215 // Now compare the two buffers to check if they 223 // Now compare the two buffers to check if they
216 // are identical. 224 // are identical.
217 Expect.equals(buffer1.length, buffer2.length); 225 Expect.equals(buffer1.length, buffer2.length);
218 for (int i = 0; i < buffer1.length; i++) { 226 for (int i = 0; i < buffer1.length; i++) {
219 Expect.equals(buffer1[i], buffer2[i]); 227 Expect.equals(buffer1[i], buffer2[i]);
220 } 228 }
221 // Delete the output file. 229 // Delete the output file.
222 file.deleteHandler = () { 230 final file4 = file3;
223 file.existsHandler = (exists) { 231 file4.deleteHandler = () {
232 file4.existsHandler = (exists) {
224 Expect.isFalse(exists); 233 Expect.isFalse(exists);
225 asyncTestDone(); 234 asyncTestDone();
226 }; 235 };
227 file.exists(); 236 file4.exists();
228 }; 237 };
229 file.delete(); 238 file4.delete();
230 }; 239 };
231 openedFile.close(); 240 openedFile3.close();
232 }; 241 };
233 openedFile.readList(buffer2, 0, 42); 242 openedFile3.readList(buffer2, 0, 42);
234 }; 243 };
235 file.open(); 244 file3.open();
236 }; 245 };
237 openedFile.close(); 246 openedFile2.close();
238 }; 247 };
239 openedFile.writeList(buffer1, 0, bytes_read); 248 openedFile2.writeList(buffer1, 0, bytes_read);
240 }; 249 };
241 file.open(FileMode.WRITE); 250 file2.open(FileMode.WRITE);
242 }; 251 };
243 file.fullPath(); 252 file2.fullPath();
244 }; 253 };
245 file.create(); 254 file2.create();
246 }; 255 };
247 openedFile.close(); 256 openedFile.close();
248 }; 257 };
249 openedFile.readList(buffer1, 0, 42); 258 openedFile.readList(buffer1, 0, 42);
250 }; 259 };
251 asyncTestStarted(); 260 asyncTestStarted();
252 file.open(); 261 file.open();
253 } 262 }
254 263
255 static void testReadWriteSync() { 264 static void testReadWriteSync() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 outFile.deleteSync(); 298 outFile.deleteSync();
290 Expect.isFalse(outFile.existsSync()); 299 Expect.isFalse(outFile.existsSync());
291 } 300 }
292 301
293 static void testReadEmptyFileSync() { 302 static void testReadEmptyFileSync() {
294 String fileName = tempDirectory.path + "/empty_file_sync"; 303 String fileName = tempDirectory.path + "/empty_file_sync";
295 File file = new File(fileName); 304 File file = new File(fileName);
296 file.createSync(); 305 file.createSync();
297 RandomAccessFile openedFile = file.openSync(); 306 RandomAccessFile openedFile = file.openSync();
298 Expect.throws(() => openedFile.readByteSync(), (e) => e is FileIOException); 307 Expect.throws(() => openedFile.readByteSync(), (e) => e is FileIOException);
308 file.deleteSync();
299 } 309 }
300 310
301 static void testReadEmptyFile() { 311 static void testReadEmptyFile() {
302 String fileName = tempDirectory.path + "/empty_file"; 312 String fileName = tempDirectory.path + "/empty_file";
303 File file = new File(fileName); 313 File file = new File(fileName);
314 file.errorHandler = (s) {
315 Expect.fail("No errors expected : $s");
316 };
304 file.createHandler = () { 317 file.createHandler = () {
305 file.openHandler = (RandomAccessFile openedFile) { 318 file.openHandler = (RandomAccessFile openedFile) {
306 openedFile.readByteHandler = (int byte) { 319 openedFile.readByteHandler = (int byte) {
307 Expect.fail("Read byte from empty file"); 320 Expect.fail("Read byte from empty file");
308 }; 321 };
309 openedFile.errorHandler = (String err) { 322 openedFile.errorHandler = (String err) {
310 Expect.isTrue(err.indexOf("failed") != -1); 323 Expect.isTrue(err.indexOf("failed") != -1);
324 file.deleteHandler = () {
325 asyncTestDone();
326 };
327 file.delete();
311 }; 328 };
312 openedFile.readByte(); 329 openedFile.readByte();
313 }; 330 };
314 file.open(); 331 file.open();
315 }; 332 };
316 asyncTestStarted(); 333 asyncTestStarted();
317 file.create(); 334 file.create();
318 } 335 }
319 336
320 // Test for file length functionality. 337 // Test for file length functionality.
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 testAppend(); 763 testAppend();
747 testAppendSync(); 764 testAppendSync();
748 asyncTestDone(); 765 asyncTestDone();
749 }); 766 });
750 } 767 }
751 } 768 }
752 769
753 main() { 770 main() {
754 FileTest.testMain(); 771 FileTest.testMain();
755 } 772 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/src/StreamPipeTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698