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

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

Issue 10392023: Change dart:io to use Future for one-shot operations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adding stable test binaries Created 8 years, 7 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 | « tests/standalone/io/file_output_stream_test.dart ('k') | tests/standalone/io/file_test.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) 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 #import('dart:io'); 5 #import('dart:io');
6 6
7 7
8 createLink(String dst, String link, bool symbolic, void callback()) { 8 createLink(String dst, String link, bool symbolic, void callback()) {
9 var args = [ symbolic ? '-s' : '', dst, link ]; 9 var args = [ symbolic ? '-s' : '', dst, link ];
10 var script = 'tests/standalone/io/ln.sh'; 10 var script = 'tests/standalone/io/ln.sh';
11 if (!new File(script).existsSync()) { 11 if (!new File(script).existsSync()) {
12 script = '../$script'; 12 script = '../$script';
13 } 13 }
14 new Process.run(script, args, null, (exit, out, err) { 14 Process.run(script, args).then((result) {
15 if (exit == 0) { 15 if (result.exitCode == 0) {
16 callback(); 16 callback();
17 } else { 17 } else {
18 throw new Exception('link creation failed'); 18 throw new Exception('link creation failed');
19 } 19 }
20 }); 20 });
21 } 21 }
22 22
23 23
24 testFileExistsCreate() { 24 testFileExistsCreate() {
25 var temp = new Directory(''); 25 var temp = new Directory('').createTempSync();
26 temp.createTempSync();
27 var x = '${temp.path}${Platform.pathSeparator}x'; 26 var x = '${temp.path}${Platform.pathSeparator}x';
28 var y = '${temp.path}${Platform.pathSeparator}y'; 27 var y = '${temp.path}${Platform.pathSeparator}y';
29 createLink(x, y, true, () { 28 createLink(x, y, true, () {
30 Expect.isFalse(new File(x).existsSync()); 29 Expect.isFalse(new File(x).existsSync());
31 Expect.isFalse(new File(y).existsSync()); 30 Expect.isFalse(new File(y).existsSync());
32 new File(y).createSync(); 31 new File(y).createSync();
33 Expect.isTrue(new File(x).existsSync()); 32 Expect.isTrue(new File(x).existsSync());
34 Expect.isTrue(new File(y).existsSync()); 33 Expect.isTrue(new File(y).existsSync());
35 temp.deleteRecursivelySync(); 34 temp.deleteRecursivelySync();
36 }); 35 });
37 } 36 }
38 37
39 38
40 testFileDelete() { 39 testFileDelete() {
41 var temp = new Directory(''); 40 var temp = new Directory('').createTempSync();
42 temp.createTempSync();
43 var x = '${temp.path}${Platform.pathSeparator}x'; 41 var x = '${temp.path}${Platform.pathSeparator}x';
44 var y = '${temp.path}${Platform.pathSeparator}y'; 42 var y = '${temp.path}${Platform.pathSeparator}y';
45 new File(x).createSync(); 43 new File(x).createSync();
46 createLink(x, y, true, () { 44 createLink(x, y, true, () {
47 Expect.isTrue(new File(x).existsSync()); 45 Expect.isTrue(new File(x).existsSync());
48 Expect.isTrue(new File(y).existsSync()); 46 Expect.isTrue(new File(y).existsSync());
49 new File(y).deleteSync(); 47 new File(y).deleteSync();
50 Expect.isTrue(new File(x).existsSync()); 48 Expect.isTrue(new File(x).existsSync());
51 Expect.isFalse(new File(y).existsSync()); 49 Expect.isFalse(new File(y).existsSync());
52 createLink(x, y, false, () { 50 createLink(x, y, false, () {
53 Expect.isTrue(new File(x).existsSync()); 51 Expect.isTrue(new File(x).existsSync());
54 Expect.isTrue(new File(y).existsSync()); 52 Expect.isTrue(new File(y).existsSync());
55 new File(y).deleteSync(); 53 new File(y).deleteSync();
56 Expect.isTrue(new File(x).existsSync()); 54 Expect.isTrue(new File(x).existsSync());
57 Expect.isFalse(new File(y).existsSync()); 55 Expect.isFalse(new File(y).existsSync());
58 temp.deleteRecursivelySync(); 56 temp.deleteRecursivelySync();
59 }); 57 });
60 }); 58 });
61 } 59 }
62 60
63 61
64 testFileWriteRead() { 62 testFileWriteRead() {
65 var temp = new Directory(''); 63 var temp = new Directory('').createTempSync();
66 temp.createTempSync();
67 var x = '${temp.path}${Platform.pathSeparator}x'; 64 var x = '${temp.path}${Platform.pathSeparator}x';
68 var y = '${temp.path}${Platform.pathSeparator}y'; 65 var y = '${temp.path}${Platform.pathSeparator}y';
69 new File(x).createSync(); 66 new File(x).createSync();
70 createLink(x, y, true, () { 67 createLink(x, y, true, () {
71 var data = "asdf".charCodes(); 68 var data = "asdf".charCodes();
72 var output = new File(y).openOutputStream(FileMode.WRITE); 69 var output = new File(y).openOutputStream(FileMode.WRITE);
73 output.write(data); 70 output.write(data);
74 output.onNoPendingWrites = () { 71 output.onNoPendingWrites = () {
75 output.close(); 72 output.close();
76 var read = new File(y).readAsBytesSync(); 73 var read = new File(y).readAsBytesSync();
77 Expect.listEquals(data, read); 74 Expect.listEquals(data, read);
78 var read2 = new File(x).readAsBytesSync(); 75 var read2 = new File(x).readAsBytesSync();
79 Expect.listEquals(data, read2); 76 Expect.listEquals(data, read2);
80 temp.deleteRecursivelySync(); 77 temp.deleteRecursivelySync();
81 }; 78 };
82 }); 79 });
83 } 80 }
84 81
85 82
86 testDirectoryExistsCreate() { 83 testDirectoryExistsCreate() {
87 var temp = new Directory(''); 84 var temp = new Directory('').createTempSync();
88 temp.createTempSync();
89 var x = '${temp.path}${Platform.pathSeparator}x'; 85 var x = '${temp.path}${Platform.pathSeparator}x';
90 var y = '${temp.path}${Platform.pathSeparator}y'; 86 var y = '${temp.path}${Platform.pathSeparator}y';
91 createLink(x, y, true, () { 87 createLink(x, y, true, () {
92 Expect.isFalse(new Directory(x).existsSync()); 88 Expect.isFalse(new Directory(x).existsSync());
93 Expect.isFalse(new Directory(y).existsSync()); 89 Expect.isFalse(new Directory(y).existsSync());
94 Expect.throws(new Directory(y).createSync); 90 Expect.throws(new Directory(y).createSync);
95 temp.deleteRecursivelySync(); 91 temp.deleteRecursivelySync();
96 }); 92 });
97 } 93 }
98 94
99 95
100 testDirectoryDelete() { 96 testDirectoryDelete() {
101 var temp = new Directory(''); 97 var temp = new Directory('').createTempSync();
102 temp.createTempSync(); 98 var temp2 = new Directory('').createTempSync();
103 var temp2 = new Directory('');
104 temp2.createTempSync();
105 var y = '${temp.path}${Platform.pathSeparator}y'; 99 var y = '${temp.path}${Platform.pathSeparator}y';
106 var x = '${temp2.path}${Platform.pathSeparator}x'; 100 var x = '${temp2.path}${Platform.pathSeparator}x';
107 new File(x).createSync(); 101 new File(x).createSync();
108 createLink(temp2.path, y, true, () { 102 createLink(temp2.path, y, true, () {
109 var link = new Directory(y); 103 var link = new Directory(y);
110 Expect.isTrue(link.existsSync()); 104 Expect.isTrue(link.existsSync());
111 Expect.isTrue(temp2.existsSync()); 105 Expect.isTrue(temp2.existsSync());
112 link.deleteSync(); 106 link.deleteSync();
113 Expect.isFalse(link.existsSync()); 107 Expect.isFalse(link.existsSync());
114 Expect.isTrue(temp2.existsSync()); 108 Expect.isTrue(temp2.existsSync());
115 createLink(temp2.path, y, true, () { 109 createLink(temp2.path, y, true, () {
116 Expect.isTrue(link.existsSync()); 110 Expect.isTrue(link.existsSync());
117 temp.deleteRecursivelySync(); 111 temp.deleteRecursivelySync();
118 Expect.isFalse(link.existsSync()); 112 Expect.isFalse(link.existsSync());
119 Expect.isTrue(temp2.existsSync()); 113 Expect.isTrue(temp2.existsSync());
120 Expect.isTrue(new File(x).existsSync()); 114 Expect.isTrue(new File(x).existsSync());
121 temp2.deleteRecursivelySync(); 115 temp2.deleteRecursivelySync();
122 }); 116 });
123 }); 117 });
124 } 118 }
125 119
126 120
127 testDirectoryListing() { 121 testDirectoryListing() {
128 var temp = new Directory(''); 122 var temp = new Directory('').createTempSync();
129 temp.createTempSync(); 123 var temp2 = new Directory('').createTempSync();
130 var temp2 = new Directory('');
131 temp2.createTempSync();
132 var y = '${temp.path}${Platform.pathSeparator}y'; 124 var y = '${temp.path}${Platform.pathSeparator}y';
133 var x = '${temp2.path}${Platform.pathSeparator}x'; 125 var x = '${temp2.path}${Platform.pathSeparator}x';
134 new File(x).createSync(); 126 new File(x).createSync();
135 createLink(temp2.path, y, true, () { 127 createLink(temp2.path, y, true, () {
136 var files = []; 128 var files = [];
137 var dirs = []; 129 var dirs = [];
138 temp.list(recursive: true); 130 var lister = temp.list(recursive: true);
139 temp.onFile = (f) => files.add(f); 131 lister.onFile = (f) => files.add(f);
140 temp.onDir = (d) => dirs.add(d); 132 lister.onDir = (d) => dirs.add(d);
141 temp.onDone = (success) { 133 lister.onDone = (success) {
142 Expect.isTrue(success); 134 Expect.isTrue(success);
143 Expect.equals(1, files.length); 135 Expect.equals(1, files.length);
144 Expect.isTrue(files[0].endsWith(x)); 136 Expect.isTrue(files[0].endsWith(x));
145 Expect.equals(1, dirs.length); 137 Expect.equals(1, dirs.length);
146 Expect.isTrue(dirs[0].endsWith(y)); 138 Expect.isTrue(dirs[0].endsWith(y));
147 temp.deleteRecursivelySync(); 139 temp.deleteRecursivelySync();
148 temp2.deleteRecursivelySync(); 140 temp2.deleteRecursivelySync();
149 }; 141 };
150 }); 142 });
151 } 143 }
152 144
153 145
154 main() { 146 main() {
155 testFileExistsCreate(); 147 testFileExistsCreate();
156 testFileDelete(); 148 testFileDelete();
157 testFileWriteRead(); 149 testFileWriteRead();
158 testDirectoryExistsCreate(); 150 testDirectoryExistsCreate();
159 testDirectoryDelete(); 151 testDirectoryDelete();
160 testDirectoryListing(); 152 testDirectoryListing();
161 } 153 }
OLDNEW
« no previous file with comments | « tests/standalone/io/file_output_stream_test.dart ('k') | tests/standalone/io/file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698