OLD | NEW |
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 // Dart test program for testing error handling in file I/O. | 5 // Dart test program for testing error handling in file I/O. |
6 | 6 |
7 import "dart:convert"; | 7 import "dart:convert"; |
8 import "dart:io"; | 8 import "dart:io"; |
9 | 9 |
10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 var create = file.create(); | 124 var create = file.create(); |
125 create.then((ignore) => Expect.fail("Unreachable code")) | 125 create.then((ignore) => Expect.fail("Unreachable code")) |
126 .catchError((error) { | 126 .catchError((error) { |
127 checkCreateInNonExistentDirectoryException(error); | 127 checkCreateInNonExistentDirectoryException(error); |
128 temp.deleteSync(recursive: true); | 128 temp.deleteSync(recursive: true); |
129 asyncEnd(); | 129 asyncEnd(); |
130 }); | 130 }); |
131 } | 131 } |
132 | 132 |
133 bool checkFullPathOnNonExistentDirectoryException(e) { | 133 bool checkResolveSymbolicLinksOnNonExistentDirectoryException(e) { |
134 Expect.isTrue(e is FileException); | 134 Expect.isTrue(e is FileException); |
135 Expect.isTrue(e.osError != null); | 135 Expect.isTrue(e.osError != null); |
136 Expect.isTrue(e.toString().indexOf("Cannot retrieve full path") != -1); | 136 Expect.isTrue(e.toString().indexOf("Cannot resolve symbolic links") != -1); |
137 // File not not found has error code 2 on all supported platforms. | 137 // File not not found has error code 2 on all supported platforms. |
138 Expect.equals(2, e.osError.errorCode); | 138 Expect.equals(2, e.osError.errorCode); |
139 | 139 |
140 return true; | 140 return true; |
141 } | 141 } |
142 | 142 |
143 void testFullPathOnNonExistentDirectory() { | 143 void testResolveSymbolicLinksOnNonExistentDirectory() { |
144 asyncStart(); | 144 asyncStart(); |
145 Directory temp = tempDir(); | 145 Directory temp = tempDir(); |
146 var file = new File("${temp.path}/nonExistentDirectory"); | 146 var file = new File("${temp.path}/nonExistentDirectory"); |
147 | 147 |
148 // Full path non-existent directory should throw exception. | 148 // Full path non-existent directory should throw exception. |
149 Expect.throws(() => file.fullPathSync(), | 149 Expect.throws(() => file.resolveSymbolicLinksSync(), |
150 (e) => checkFullPathOnNonExistentDirectoryException(e)); | 150 (e) => checkResolveSymbolicLinksOnNonExistentDirectoryException(e)); |
151 | 151 |
152 var fullPathFuture = file.fullPath(); | 152 var resolvedFuture = file.resolveSymbolicLinks(); |
153 fullPathFuture.then((path) => Expect.fail("Unreachable code $path")) | 153 resolvedFuture.then((path) => Expect.fail("Unreachable code $path")) |
154 .catchError((error) { | 154 .catchError((error) { |
155 checkFullPathOnNonExistentDirectoryException(error); | 155 checkResolveSymbolicLinksOnNonExistentDirectoryException(error); |
156 temp.deleteSync(recursive: true); | 156 temp.deleteSync(recursive: true); |
157 asyncEnd(); | 157 asyncEnd(); |
158 }); | 158 }); |
159 } | 159 } |
160 | 160 |
161 void testReadAsBytesNonExistent() { | 161 void testReadAsBytesNonExistent() { |
162 asyncStart(); | 162 asyncStart(); |
163 Directory temp = tempDir(); | 163 Directory temp = tempDir(); |
164 var file = new File("${temp.path}/nonExistentFile3"); | 164 var file = new File("${temp.path}/nonExistentFile3"); |
165 | 165 |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 (e) => e is FileException); | 417 (e) => e is FileException); |
418 done(); | 418 done(); |
419 }); | 419 }); |
420 } | 420 } |
421 | 421 |
422 main() { | 422 main() { |
423 testOpenNonExistent(); | 423 testOpenNonExistent(); |
424 testDeleteNonExistent(); | 424 testDeleteNonExistent(); |
425 testLengthNonExistent(); | 425 testLengthNonExistent(); |
426 testCreateInNonExistentDirectory(); | 426 testCreateInNonExistentDirectory(); |
427 testFullPathOnNonExistentDirectory(); | 427 testResolveSymbolicLinksOnNonExistentDirectory(); |
428 testReadAsBytesNonExistent(); | 428 testReadAsBytesNonExistent(); |
429 testReadAsTextNonExistent(); | 429 testReadAsTextNonExistent(); |
430 testReadAsLinesNonExistent(); | 430 testReadAsLinesNonExistent(); |
431 testWriteByteToReadOnlyFile(); | 431 testWriteByteToReadOnlyFile(); |
432 testWriteFromToReadOnlyFile(); | 432 testWriteFromToReadOnlyFile(); |
433 testTruncateReadOnlyFile(); | 433 testTruncateReadOnlyFile(); |
434 testOperateOnClosedFile(); | 434 testOperateOnClosedFile(); |
435 testRepeatedlyCloseFile(); | 435 testRepeatedlyCloseFile(); |
436 testRepeatedlyCloseFileSync(); | 436 testRepeatedlyCloseFileSync(); |
437 testReadSyncBigInt(); | 437 testReadSyncBigInt(); |
438 testReadSyncClosedFile(); | 438 testReadSyncClosedFile(); |
439 } | 439 } |
OLD | NEW |