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

Side by Side Diff: tests/standalone/io/directory_error_test.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
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 // Dart test program for testing error handling in directory I/O. 5 // Dart test program for testing error handling in directory 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() {
(...skipping 15 matching lines...) Expand all
26 26
27 return true; 27 return true;
28 } 28 }
29 29
30 30
31 void testCreateInNonExistent(Directory temp, Function done) { 31 void testCreateInNonExistent(Directory temp, Function done) {
32 Directory inNonExistent = new Directory("${temp.path}/nonExistent/xxx"); 32 Directory inNonExistent = new Directory("${temp.path}/nonExistent/xxx");
33 Expect.throws(() => inNonExistent.createSync(), 33 Expect.throws(() => inNonExistent.createSync(),
34 (e) => checkCreateInNonExistentFileException(e)); 34 (e) => checkCreateInNonExistentFileException(e));
35 35
36 inNonExistent.create().handleException((e) { 36 inNonExistent.create().catchError((e) {
37 checkCreateInNonExistentFileException(e); 37 checkCreateInNonExistentFileException(e.error);
38 done(); 38 done();
39 return true;
40 }); 39 });
41 } 40 }
42 41
43 42
44 bool checkCreateTempInNonExistentFileException(e) { 43 bool checkCreateTempInNonExistentFileException(e) {
45 Expect.isTrue(e is DirectoryIOException); 44 Expect.isTrue(e is DirectoryIOException);
46 Expect.isTrue(e.osError != null); 45 Expect.isTrue(e.osError != null);
47 if (Platform.operatingSystem == "linux") { 46 if (Platform.operatingSystem == "linux") {
48 Expect.equals(2, e.osError.errorCode); 47 Expect.equals(2, e.osError.errorCode);
49 } else if (Platform.operatingSystem == "macos") { 48 } else if (Platform.operatingSystem == "macos") {
50 Expect.equals(2, e.osError.errorCode); 49 Expect.equals(2, e.osError.errorCode);
51 } else if (Platform.operatingSystem == "windows") { 50 } else if (Platform.operatingSystem == "windows") {
52 Expect.equals(3, e.osError.errorCode); 51 Expect.equals(3, e.osError.errorCode);
53 } 52 }
54 53
55 return true; 54 return true;
56 } 55 }
57 56
58 57
59 void testCreateTempInNonExistent(Directory temp, Function done) { 58 void testCreateTempInNonExistent(Directory temp, Function done) {
60 Directory nonExistent = new Directory("${temp.path}/nonExistent/xxx"); 59 Directory nonExistent = new Directory("${temp.path}/nonExistent/xxx");
61 Expect.throws(() => nonExistent.createTempSync(), 60 Expect.throws(() => nonExistent.createTempSync(),
62 (e) => checkCreateTempInNonExistentFileException(e)); 61 (e) => checkCreateTempInNonExistentFileException(e));
63 62
64 nonExistent.createTemp().handleException((e) { 63 nonExistent.createTemp().catchError((e) {
65 checkCreateTempInNonExistentFileException(e); 64 checkCreateTempInNonExistentFileException(e.error);
66 done(); 65 done();
67 return true;
68 }); 66 });
69 } 67 }
70 68
71 69
72 bool checkDeleteNonExistentFileException(e) { 70 bool checkDeleteNonExistentFileException(e) {
73 Expect.isTrue(e is DirectoryIOException); 71 Expect.isTrue(e is DirectoryIOException);
74 Expect.isTrue(e.osError != null); 72 Expect.isTrue(e.osError != null);
75 // File not not found has error code 2 on all supported platforms. 73 // File not not found has error code 2 on all supported platforms.
76 Expect.equals(2, e.osError.errorCode); 74 Expect.equals(2, e.osError.errorCode);
77 75
78 return true; 76 return true;
79 } 77 }
80 78
81 79
82 void testDeleteNonExistent(Directory temp, Function done) { 80 void testDeleteNonExistent(Directory temp, Function done) {
83 Directory nonExistent = new Directory("${temp.path}/nonExistent"); 81 Directory nonExistent = new Directory("${temp.path}/nonExistent");
84 Expect.throws(() => nonExistent.deleteSync(), 82 Expect.throws(() => nonExistent.deleteSync(),
85 (e) => checkDeleteNonExistentFileException(e)); 83 (e) => checkDeleteNonExistentFileException(e));
86 84
87 nonExistent.delete().handleException((e) { 85 nonExistent.delete().catchError((e) {
88 checkDeleteNonExistentFileException(e); 86 checkDeleteNonExistentFileException(e.error);
89 done(); 87 done();
90 return true;
91 }); 88 });
92 } 89 }
93 90
94 91
95 bool checkDeleteRecursivelyNonExistentFileException(e) { 92 bool checkDeleteRecursivelyNonExistentFileException(e) {
96 Expect.isTrue(e is DirectoryIOException); 93 Expect.isTrue(e is DirectoryIOException);
97 Expect.isTrue(e.osError != null); 94 Expect.isTrue(e.osError != null);
98 Expect.isTrue(e.toString().indexOf("Deletion failed") != -1); 95 Expect.isTrue(e.toString().indexOf("Deletion failed") != -1);
99 if (Platform.operatingSystem == "linux") { 96 if (Platform.operatingSystem == "linux") {
100 Expect.equals(2, e.osError.errorCode); 97 Expect.equals(2, e.osError.errorCode);
101 } else if (Platform.operatingSystem == "macos") { 98 } else if (Platform.operatingSystem == "macos") {
102 Expect.equals(2, e.osError.errorCode); 99 Expect.equals(2, e.osError.errorCode);
103 } else if (Platform.operatingSystem == "windows") { 100 } else if (Platform.operatingSystem == "windows") {
104 Expect.equals(3, e.osError.errorCode); 101 Expect.equals(3, e.osError.errorCode);
105 } 102 }
106 103
107 return true; 104 return true;
108 } 105 }
109 106
110 107
111 void testDeleteRecursivelyNonExistent(Directory temp, Function done) { 108 void testDeleteRecursivelyNonExistent(Directory temp, Function done) {
112 Directory nonExistent = new Directory("${temp.path}/nonExistent"); 109 Directory nonExistent = new Directory("${temp.path}/nonExistent");
113 Expect.throws(() => nonExistent.deleteSync(recursive: true), 110 Expect.throws(() => nonExistent.deleteSync(recursive: true),
114 (e) => checkDeleteRecursivelyNonExistentFileException(e)); 111 (e) => checkDeleteRecursivelyNonExistentFileException(e));
115 112
116 nonExistent.delete(recursive: true).handleException((e) { 113 nonExistent.delete(recursive: true).catchError((e) {
117 checkDeleteRecursivelyNonExistentFileException(e); 114 checkDeleteRecursivelyNonExistentFileException(e.error);
118 done(); 115 done();
119 return true;
120 }); 116 });
121 } 117 }
122 118
123 119
124 bool checkListNonExistentFileException(e) { 120 bool checkListNonExistentFileException(e) {
125 Expect.isTrue(e is DirectoryIOException); 121 Expect.isTrue(e is DirectoryIOException);
126 Expect.isTrue(e.osError != null); 122 Expect.isTrue(e.osError != null);
127 Expect.isTrue(e.toString().indexOf("Directory listing failed") != -1); 123 Expect.isTrue(e.toString().indexOf("Directory listing failed") != -1);
128 if (Platform.operatingSystem == "linux") { 124 if (Platform.operatingSystem == "linux") {
129 Expect.equals(2, e.osError.errorCode); 125 Expect.equals(2, e.osError.errorCode);
(...skipping 17 matching lines...) Expand all
147 }; 143 };
148 } 144 }
149 145
150 146
151 void testRenameNonExistent(Directory temp, Function done) { 147 void testRenameNonExistent(Directory temp, Function done) {
152 Directory nonExistent = new Directory("${temp.path}/nonExistent"); 148 Directory nonExistent = new Directory("${temp.path}/nonExistent");
153 var newPath = "${temp.path}/nonExistent2"; 149 var newPath = "${temp.path}/nonExistent2";
154 Expect.throws(() => nonExistent.renameSync(newPath), 150 Expect.throws(() => nonExistent.renameSync(newPath),
155 (e) => e is DirectoryIOException); 151 (e) => e is DirectoryIOException);
156 var renameDone = nonExistent.rename(newPath); 152 var renameDone = nonExistent.rename(newPath);
157 renameDone.then((ignore) => Expect.fail('rename non existent')); 153 renameDone.then((ignore) => Expect.fail('rename non existent'))
158 renameDone.handleException((e) { 154 .catchError((e) {
159 Expect.isTrue(e is DirectoryIOException); 155 Expect.isTrue(e.error is DirectoryIOException);
160 done(); 156 done();
161 return true;
162 }); 157 });
163 } 158 }
164 159
165 160
166 void testRenameFileAsDirectory(Directory temp, Function done) { 161 void testRenameFileAsDirectory(Directory temp, Function done) {
167 File f = new File("${temp.path}/file"); 162 File f = new File("${temp.path}/file");
168 var newPath = "${temp.path}/file2"; 163 var newPath = "${temp.path}/file2";
169 f.createSync(); 164 f.createSync();
170 var d = new Directory(f.name); 165 var d = new Directory(f.name);
171 Expect.throws(() => d.renameSync(newPath), 166 Expect.throws(() => d.renameSync(newPath),
172 (e) => e is DirectoryIOException); 167 (e) => e is DirectoryIOException);
173 var renameDone = d.rename(newPath); 168 var renameDone = d.rename(newPath);
174 renameDone.then((ignore) => Expect.fail('rename file as directory')); 169 renameDone.then((ignore) => Expect.fail('rename file as directory'))
175 renameDone.handleException((e) { 170 .catchError((e) {
176 Expect.isTrue(e is DirectoryIOException); 171 Expect.isTrue(e.error is DirectoryIOException);
177 done(); 172 done();
178 return true; 173 });
179 });
180 } 174 }
181 175
182 176
183 testRenameOverwriteFile(Directory temp, Function done) { 177 testRenameOverwriteFile(Directory temp, Function done) {
184 var d = new Directory(''); 178 var d = new Directory('');
185 var temp1 = d.createTempSync(); 179 var temp1 = d.createTempSync();
186 var fileName = '${temp.path}/x'; 180 var fileName = '${temp.path}/x';
187 new File(fileName).createSync(); 181 new File(fileName).createSync();
188 Expect.throws(() => temp1.renameSync(fileName), 182 Expect.throws(() => temp1.renameSync(fileName),
189 (e) => e is DirectoryIOException); 183 (e) => e is DirectoryIOException);
190 var renameDone = temp1.rename(fileName); 184 var renameDone = temp1.rename(fileName);
191 renameDone.then((ignore) => Expect.fail('rename dir overwrite file')); 185 renameDone.then((ignore) => Expect.fail('rename dir overwrite file'))
192 renameDone.handleException((e) { 186 .catchError((e) {
193 Expect.isTrue(e is DirectoryIOException); 187 Expect.isTrue(e.error is DirectoryIOException);
194 temp1.deleteSync(recursive: true); 188 temp1.deleteSync(recursive: true);
195 done(); 189 done();
196 return true; 190 });
197 });
198 } 191 }
199 192
200 193
201 void runTest(Function test) { 194 void runTest(Function test) {
202 // Create a temporary directory for the test. 195 // Create a temporary directory for the test.
203 var temp = new Directory('').createTempSync(); 196 var temp = new Directory('').createTempSync();
204 197
205 // Wait for the test to finish and delete the temporary directory. 198 // Wait for the test to finish and delete the temporary directory.
206 ReceivePort p = new ReceivePort(); 199 ReceivePort p = new ReceivePort();
207 p.receive((x,y) { 200 p.receive((x,y) {
208 p.close(); 201 p.close();
209 temp.deleteSync(recursive: true); 202 temp.deleteSync(recursive: true);
210 }); 203 });
211 204
212 // Run the test. 205 // Run the test.
213 test(temp, () => p.toSendPort().send(null)); 206 test(temp, () => p.toSendPort().send(null));
214 } 207 }
215 208
216 209
217 main() { 210 main() {
218 runTest(testCreateInNonExistent); 211 runTest(testCreateInNonExistent);
219 runTest(testCreateTempInNonExistent); 212 runTest(testCreateTempInNonExistent);
220 runTest(testDeleteNonExistent); 213 runTest(testDeleteNonExistent);
221 runTest(testDeleteRecursivelyNonExistent); 214 runTest(testDeleteRecursivelyNonExistent);
222 runTest(testListNonExistent); 215 runTest(testListNonExistent);
223 runTest(testRenameNonExistent); 216 runTest(testRenameNonExistent);
224 runTest(testRenameFileAsDirectory); 217 runTest(testRenameFileAsDirectory);
225 runTest(testRenameOverwriteFile); 218 runTest(testRenameOverwriteFile);
226 } 219 }
OLDNEW
« no previous file with comments | « tests/standalone/io/dart_std_io_pipe_test.dart ('k') | tests/standalone/io/directory_fuzz_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698