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

Side by Side Diff: tests/standalone/src/FileTest.dart

Issue 8439067: Implement fullPath method on File objects. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 9 years, 1 month 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 | « runtime/bin/file_impl.dart ('k') | no next file » | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 file I/O. 5 // Dart test program for testing file I/O.
6 6
7 7
8 class FileTest { 8 class FileTest {
9 // Test for file read functionality. 9 // Test for file read functionality.
10 static int testReadStream() { 10 static int testReadStream() {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 Expect.equals(42, bytes_read); 137 Expect.equals(42, bytes_read);
138 file.closeHandler = () { 138 file.closeHandler = () {
139 // Write the contents of the file just read into another file. 139 // Write the contents of the file just read into another file.
140 String outFilenameBase = 140 String outFilenameBase =
141 getFilename("tests/vm/data/fixed_length_file"); 141 getFilename("tests/vm/data/fixed_length_file");
142 file = new File(outFilenameBase + "_out"); 142 file = new File(outFilenameBase + "_out");
143 file.errorHandler = (s) { 143 file.errorHandler = (s) {
144 Expect.fail("No errors expected"); 144 Expect.fail("No errors expected");
145 }; 145 };
146 file.createHandler = () { 146 file.createHandler = () {
147 file.openHandler = () { 147 file.fullPathHandler = (s) {
148 file.noPendingWriteHandler = () { 148 Expect.isTrue(new File(s).existsSync());
149 file.closeHandler = () { 149 if (s[0] != '/' && s[0] != '\\' && s[1] != ':') {
150 // Now read the contents of the file just written. 150 Expect.fail("Not a full path");
151 List<int> buffer2 = new List<int>(bytes_read); 151 }
152 file = new File(getFilename(outFilenameBase)); 152 file.openHandler = () {
153 file.errorHandler = (s) { 153 file.noPendingWriteHandler = () {
154 Expect.fail("No errors expected"); 154 file.closeHandler = () {
155 // Now read the contents of the file just written.
156 List<int> buffer2 = new List<int>(bytes_read);
157 file = new File(getFilename(outFilenameBase));
158 file.errorHandler = (s) {
159 Expect.fail("No errors expected");
160 };
161 file.openHandler = () {
162 file.readListHandler = (bytes_read) {
163 Expect.equals(42, bytes_read);
164 file.closeHandler = () {
165 // Now compare the two buffers to check if they
166 // are identical.
167 Expect.equals(buffer1.length, buffer2.length);
168 for (int i = 0; i < buffer1.length; i++) {
169 Expect.equals(buffer1[i], buffer2[i]);
170 }
171 };
172 file.close();
173 };
174 file.readList(buffer2, 0, 42);
175 };
176 file.open();
155 }; 177 };
156 file.openHandler = () { 178 file.close();
157 file.readListHandler = (bytes_read) {
158 Expect.equals(42, bytes_read);
159 file.closeHandler = () {
160 // Now compare the two buffers to check if they
161 // are identical.
162 Expect.equals(buffer1.length, buffer2.length);
163 for (int i = 0; i < buffer1.length; i++) {
164 Expect.equals(buffer1[i], buffer2[i]);
165 }
166 };
167 file.close();
168 };
169 file.readList(buffer2, 0, 42);
170 };
171 file.open();
172 }; 179 };
173 file.close(); 180 file.writeList(buffer1, 0, bytes_read);
174 }; 181 };
175 file.writeList(buffer1, 0, bytes_read); 182 file.open(true);
176 }; 183 };
177 file.open(true); 184 file.fullPath();
178 }; 185 };
179 file.create(); 186 file.create();
180 }; 187 };
181 file.close(); 188 file.close();
182 }; 189 };
183 file.readList(buffer1, 0, 42); 190 file.readList(buffer1, 0, 42);
184 }; 191 };
185 file.open(); 192 file.open();
186 return 1; 193 return 1;
187 194
188 } 195 }
189 196
190 static int testReadWriteSync() { 197 static int testReadWriteSync() {
191 // Read a file. 198 // Read a file.
192 String inFilename = getFilename("tests/vm/data/fixed_length_file"); 199 String inFilename = getFilename("tests/vm/data/fixed_length_file");
193 File file = new File(inFilename); 200 File file = new File(inFilename);
194 file.openSync(); 201 file.openSync();
195 List<int> buffer1 = new List<int>(42); 202 List<int> buffer1 = new List<int>(42);
196 int bytes_read = 0; 203 int bytes_read = 0;
197 int bytes_written = 0; 204 int bytes_written = 0;
198 bytes_read = file.readListSync(buffer1, 0, 42); 205 bytes_read = file.readListSync(buffer1, 0, 42);
199 Expect.equals(42, bytes_read); 206 Expect.equals(42, bytes_read);
200 file.closeSync(); 207 file.closeSync();
201 // Write the contents of the file just read into another file. 208 // Write the contents of the file just read into another file.
202 String outFilenameBase = getFilename("tests/vm/data/fixed_length_file"); 209 String outFilenameBase = getFilename("tests/vm/data/fixed_length_file");
203 file = new File(outFilenameBase + "_out"); 210 file = new File(outFilenameBase + "_out");
204 file.createSync(); 211 file.createSync();
212 String path = file.fullPathSync();
213 if (path[0] != '/' && path[0] != '\\' && path[1] != ':') {
214 Expect.fail("Not a full path");
215 }
216 Expect.isTrue(new File(path).existsSync());
205 file.openSync(true); 217 file.openSync(true);
206 file.writeListSync(buffer1, 0, bytes_read); 218 file.writeListSync(buffer1, 0, bytes_read);
207 file.closeSync(); 219 file.closeSync();
208 // Now read the contents of the file just written. 220 // Now read the contents of the file just written.
209 List<int> buffer2 = new List<int>(bytes_read); 221 List<int> buffer2 = new List<int>(bytes_read);
210 file = new File(getFilename(outFilenameBase)); 222 file = new File(getFilename(outFilenameBase));
211 file.openSync(); 223 file.openSync();
212 bytes_read = file.readListSync(buffer2, 0, 42); 224 bytes_read = file.readListSync(buffer2, 0, 42);
213 Expect.equals(42, bytes_read); 225 Expect.equals(42, bytes_read);
214 file.closeSync(); 226 file.closeSync();
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 Expect.equals(1, testCloseException()); 563 Expect.equals(1, testCloseException());
552 Expect.equals(1, testCloseExceptionStream()); 564 Expect.equals(1, testCloseExceptionStream());
553 Expect.equals(1, testBufferOutOfBoundsException()); 565 Expect.equals(1, testBufferOutOfBoundsException());
554 Expect.equals(1, testMixedSyncAndAsync()); 566 Expect.equals(1, testMixedSyncAndAsync());
555 } 567 }
556 } 568 }
557 569
558 main() { 570 main() {
559 FileTest.testMain(); 571 FileTest.testMain();
560 } 572 }
OLDNEW
« no previous file with comments | « runtime/bin/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698