| 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 "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import "dart:convert"; |
| 8 import "dart:io"; | 9 import "dart:io"; |
| 9 import "dart:isolate"; | 10 import "dart:isolate"; |
| 10 | 11 |
| 11 Directory tempDir() { | 12 Directory tempDir() { |
| 12 return new Directory('').createTempSync(); | 13 return new Directory('').createTempSync(); |
| 13 } | 14 } |
| 14 | 15 |
| 15 | 16 |
| 16 bool checkNonExistentFileException(e, str) { | 17 bool checkNonExistentFileException(e, str) { |
| 17 Expect.isTrue(e is FileException); | 18 Expect.isTrue(e is FileException); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 p.receive((x, y) { | 199 p.receive((x, y) { |
| 199 p.close(); | 200 p.close(); |
| 200 temp.deleteSync(recursive: true); | 201 temp.deleteSync(recursive: true); |
| 201 }); | 202 }); |
| 202 var file = new File("${temp.path}/nonExistentFile4"); | 203 var file = new File("${temp.path}/nonExistentFile4"); |
| 203 | 204 |
| 204 // Non-existing file should throw exception. | 205 // Non-existing file should throw exception. |
| 205 Expect.throws(() => file.readAsStringSync(), | 206 Expect.throws(() => file.readAsStringSync(), |
| 206 (e) => checkOpenNonExistentFileException(e)); | 207 (e) => checkOpenNonExistentFileException(e)); |
| 207 | 208 |
| 208 var readAsStringFuture = file.readAsString(encoding: Encoding.ASCII); | 209 var readAsStringFuture = file.readAsString(encoding: ASCII); |
| 209 readAsStringFuture.then((data) => Expect.fail("Unreachable code")) | 210 readAsStringFuture.then((data) => Expect.fail("Unreachable code")) |
| 210 .catchError((error) { | 211 .catchError((error) { |
| 211 checkOpenNonExistentFileException(error); | 212 checkOpenNonExistentFileException(error); |
| 212 p.toSendPort().send(null); | 213 p.toSendPort().send(null); |
| 213 }); | 214 }); |
| 214 } | 215 } |
| 215 | 216 |
| 216 testReadAsLinesNonExistent() { | 217 testReadAsLinesNonExistent() { |
| 217 Directory temp = tempDir(); | 218 Directory temp = tempDir(); |
| 218 ReceivePort p = new ReceivePort(); | 219 ReceivePort p = new ReceivePort(); |
| 219 p.receive((x, y) { | 220 p.receive((x, y) { |
| 220 p.close(); | 221 p.close(); |
| 221 temp.deleteSync(recursive: true); | 222 temp.deleteSync(recursive: true); |
| 222 }); | 223 }); |
| 223 var file = new File("${temp.path}/nonExistentFile5"); | 224 var file = new File("${temp.path}/nonExistentFile5"); |
| 224 | 225 |
| 225 // Non-existing file should throw exception. | 226 // Non-existing file should throw exception. |
| 226 Expect.throws(() => file.readAsLinesSync(), | 227 Expect.throws(() => file.readAsLinesSync(), |
| 227 (e) => checkOpenNonExistentFileException(e)); | 228 (e) => checkOpenNonExistentFileException(e)); |
| 228 | 229 |
| 229 var readAsLinesFuture = file.readAsLines(encoding: Encoding.ASCII); | 230 var readAsLinesFuture = file.readAsLines(encoding: ASCII); |
| 230 readAsLinesFuture.then((data) => Expect.fail("Unreachable code")) | 231 readAsLinesFuture.then((data) => Expect.fail("Unreachable code")) |
| 231 .catchError((error) { | 232 .catchError((error) { |
| 232 checkOpenNonExistentFileException(error); | 233 checkOpenNonExistentFileException(error); |
| 233 p.toSendPort().send(null); | 234 p.toSendPort().send(null); |
| 234 }); | 235 }); |
| 235 } | 236 } |
| 236 | 237 |
| 237 bool checkWriteReadOnlyFileException(e) { | 238 bool checkWriteReadOnlyFileException(e) { |
| 238 Expect.isTrue(e is FileException); | 239 Expect.isTrue(e is FileException); |
| 239 Expect.isTrue(e.osError != null); | 240 Expect.isTrue(e.osError != null); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 testReadAsLinesNonExistent(); | 455 testReadAsLinesNonExistent(); |
| 455 testWriteByteToReadOnlyFile(); | 456 testWriteByteToReadOnlyFile(); |
| 456 testWriteFromToReadOnlyFile(); | 457 testWriteFromToReadOnlyFile(); |
| 457 testTruncateReadOnlyFile(); | 458 testTruncateReadOnlyFile(); |
| 458 testOperateOnClosedFile(); | 459 testOperateOnClosedFile(); |
| 459 testRepeatedlyCloseFile(); | 460 testRepeatedlyCloseFile(); |
| 460 testRepeatedlyCloseFileSync(); | 461 testRepeatedlyCloseFileSync(); |
| 461 testReadSyncBigInt(); | 462 testReadSyncBigInt(); |
| 462 testReadSyncClosedFile(); | 463 testReadSyncClosedFile(); |
| 463 } | 464 } |
| OLD | NEW |