| OLD | NEW |
| 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 // 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:io"); | 7 #import("dart:io"); |
| 8 #import("dart:isolate"); | 8 #import("dart:isolate"); |
| 9 | 9 |
| 10 Directory tempDir() { | 10 Directory tempDir() { |
| 11 var d = new Directory(''); | 11 var d = new Directory(''); |
| 12 d.createTempSync(); | 12 d.createTempSync(); |
| 13 return d; | 13 return d; |
| 14 } | 14 } |
| 15 | 15 |
| 16 | 16 |
| 17 bool checkNonExistentFileException(e, str) { | 17 bool checkNonExistentFileException(e, str) { |
| 18 Expect.isTrue(e is FileIOException); | 18 Expect.isTrue(e is FileIOException); |
| 19 Expect.isTrue(e.osError != null); | 19 Expect.isTrue(e.osError != null); |
| 20 Expect.isTrue(e.toString().indexOf(str) != -1); | 20 Expect.isTrue(e.toString().indexOf(str) != -1); |
| 21 Platform platform = new Platform(); | 21 if (Platform.operatingSystem() == "linux") { |
| 22 if (platform.operatingSystem() == "linux") { | |
| 23 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 22 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 24 } else if (platform.operatingSystem() == "macos") { | 23 } else if (Platform.operatingSystem() == "macos") { |
| 25 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 24 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 26 } else if (platform.operatingSystem() == "windows") { | 25 } else if (Platform.operatingSystem() == "windows") { |
| 27 Expect.isTrue( | 26 Expect.isTrue( |
| 28 e.toString().indexOf( | 27 e.toString().indexOf( |
| 29 "The system cannot find the file specified") != -1); | 28 "The system cannot find the file specified") != -1); |
| 30 } | 29 } |
| 31 // File not not found has error code 2 on all supported platforms. | 30 // File not not found has error code 2 on all supported platforms. |
| 32 Expect.equals(2, e.osError.errorCode); | 31 Expect.equals(2, e.osError.errorCode); |
| 33 | 32 |
| 34 return true; | 33 return true; |
| 35 } | 34 } |
| 36 | 35 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 checkLengthNonExistentFileException(e); | 109 checkLengthNonExistentFileException(e); |
| 111 p.toSendPort().send(null); | 110 p.toSendPort().send(null); |
| 112 }; | 111 }; |
| 113 } | 112 } |
| 114 | 113 |
| 115 | 114 |
| 116 bool checkCreateInNonExistentDirectoryException(e) { | 115 bool checkCreateInNonExistentDirectoryException(e) { |
| 117 Expect.isTrue(e is FileIOException); | 116 Expect.isTrue(e is FileIOException); |
| 118 Expect.isTrue(e.osError != null); | 117 Expect.isTrue(e.osError != null); |
| 119 Expect.isTrue(e.toString().indexOf("Cannot create file") != -1); | 118 Expect.isTrue(e.toString().indexOf("Cannot create file") != -1); |
| 120 Platform platform = new Platform(); | 119 if (Platform.operatingSystem() == "linux") { |
| 121 if (platform.operatingSystem() == "linux") { | |
| 122 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 120 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 123 Expect.equals(2, e.osError.errorCode); | 121 Expect.equals(2, e.osError.errorCode); |
| 124 } else if (platform.operatingSystem() == "macos") { | 122 } else if (Platform.operatingSystem() == "macos") { |
| 125 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 123 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 126 Expect.equals(2, e.osError.errorCode); | 124 Expect.equals(2, e.osError.errorCode); |
| 127 } else if (platform.operatingSystem() == "windows") { | 125 } else if (Platform.operatingSystem() == "windows") { |
| 128 Expect.isTrue( | 126 Expect.isTrue( |
| 129 e.toString().indexOf( | 127 e.toString().indexOf( |
| 130 "The system cannot find the path specified") != -1); | 128 "The system cannot find the path specified") != -1); |
| 131 Expect.equals(3, e.osError.errorCode); | 129 Expect.equals(3, e.osError.errorCode); |
| 132 } | 130 } |
| 133 | 131 |
| 134 return true; | 132 return true; |
| 135 } | 133 } |
| 136 | 134 |
| 137 void testCreateInNonExistentDirectory() { | 135 void testCreateInNonExistentDirectory() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 151 file.onError = (e) { | 149 file.onError = (e) { |
| 152 checkCreateInNonExistentDirectoryException(e); | 150 checkCreateInNonExistentDirectoryException(e); |
| 153 p.toSendPort().send(null); | 151 p.toSendPort().send(null); |
| 154 }; | 152 }; |
| 155 } | 153 } |
| 156 | 154 |
| 157 bool checkFullPathOnNonExistentDirectoryException(e) { | 155 bool checkFullPathOnNonExistentDirectoryException(e) { |
| 158 Expect.isTrue(e is FileIOException); | 156 Expect.isTrue(e is FileIOException); |
| 159 Expect.isTrue(e.osError != null); | 157 Expect.isTrue(e.osError != null); |
| 160 Expect.isTrue(e.toString().indexOf("Cannot retrieve full path") != -1); | 158 Expect.isTrue(e.toString().indexOf("Cannot retrieve full path") != -1); |
| 161 Platform platform = new Platform(); | 159 if (Platform.operatingSystem() == "linux") { |
| 162 if (platform.operatingSystem() == "linux") { | |
| 163 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 160 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 164 } else if (platform.operatingSystem() == "macos") { | 161 } else if (Platform.operatingSystem() == "macos") { |
| 165 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 162 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 166 } else if (platform.operatingSystem() == "windows") { | 163 } else if (Platform.operatingSystem() == "windows") { |
| 167 Expect.isTrue( | 164 Expect.isTrue( |
| 168 e.toString().indexOf( | 165 e.toString().indexOf( |
| 169 "The system cannot find the file specified") != -1); | 166 "The system cannot find the file specified") != -1); |
| 170 } | 167 } |
| 171 // File not not found has error code 2 on all supported platforms. | 168 // File not not found has error code 2 on all supported platforms. |
| 172 Expect.equals(2, e.osError.errorCode); | 169 Expect.equals(2, e.osError.errorCode); |
| 173 | 170 |
| 174 return true; | 171 return true; |
| 175 } | 172 } |
| 176 | 173 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 192 checkFullPathOnNonExistentDirectoryException(e); | 189 checkFullPathOnNonExistentDirectoryException(e); |
| 193 p.toSendPort().send(null); | 190 p.toSendPort().send(null); |
| 194 }; | 191 }; |
| 195 } | 192 } |
| 196 | 193 |
| 197 bool checkDirectoryInNonExistentDirectoryException(e) { | 194 bool checkDirectoryInNonExistentDirectoryException(e) { |
| 198 Expect.isTrue(e is FileIOException); | 195 Expect.isTrue(e is FileIOException); |
| 199 Expect.isTrue(e.osError != null); | 196 Expect.isTrue(e.osError != null); |
| 200 Expect.isTrue( | 197 Expect.isTrue( |
| 201 e.toString().indexOf("Cannot retrieve directory for file") != -1); | 198 e.toString().indexOf("Cannot retrieve directory for file") != -1); |
| 202 Platform platform = new Platform(); | 199 if (Platform.operatingSystem() == "linux") { |
| 203 if (platform.operatingSystem() == "linux") { | |
| 204 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 200 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 205 } else if (platform.operatingSystem() == "macos") { | 201 } else if (Platform.operatingSystem() == "macos") { |
| 206 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); | 202 Expect.isTrue(e.toString().indexOf("No such file or directory") != -1); |
| 207 } else if (platform.operatingSystem() == "windows") { | 203 } else if (Platform.operatingSystem() == "windows") { |
| 208 Expect.isTrue( | 204 Expect.isTrue( |
| 209 e.toString().indexOf( | 205 e.toString().indexOf( |
| 210 "The system cannot find the file specified") != -1); | 206 "The system cannot find the file specified") != -1); |
| 211 } | 207 } |
| 212 // File not not found has error code 2 on all supported platforms. | 208 // File not not found has error code 2 on all supported platforms. |
| 213 Expect.equals(2, e.osError.errorCode); | 209 Expect.equals(2, e.osError.errorCode); |
| 214 | 210 |
| 215 return true; | 211 return true; |
| 216 } | 212 } |
| 217 | 213 |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 testDirectoryInNonExistentDirectory(); | 456 testDirectoryInNonExistentDirectory(); |
| 461 testReadAsBytesNonExistent(); | 457 testReadAsBytesNonExistent(); |
| 462 testReadAsTextNonExistent(); | 458 testReadAsTextNonExistent(); |
| 463 testReadAsLinesNonExistent(); | 459 testReadAsLinesNonExistent(); |
| 464 testWriteByteToReadOnlyFile(); | 460 testWriteByteToReadOnlyFile(); |
| 465 testWriteListToReadOnlyFile(); | 461 testWriteListToReadOnlyFile(); |
| 466 testTruncateReadOnlyFile(); | 462 testTruncateReadOnlyFile(); |
| 467 testOperateOnClosedFile(); | 463 testOperateOnClosedFile(); |
| 468 testRepeatedlyCloseFile(); | 464 testRepeatedlyCloseFile(); |
| 469 } | 465 } |
| OLD | NEW |