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

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

Issue 8437056: Implemented File create API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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/process_script.cc ('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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 file.readListHandler = (bytes_read) { 136 file.readListHandler = (bytes_read) {
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.openHandler = () { 146 file.createHandler = () {
147 file.noPendingWriteHandler = () { 147 file.openHandler = () {
148 file.closeHandler = () { 148 file.noPendingWriteHandler = () {
149 // Now read the contents of the file just written. 149 file.closeHandler = () {
150 List<int> buffer2 = new List<int>(bytes_read); 150 // Now read the contents of the file just written.
151 file = new File(getFilename(outFilenameBase)); 151 List<int> buffer2 = new List<int>(bytes_read);
152 file.errorHandler = (s) { 152 file = new File(getFilename(outFilenameBase));
153 Expect.fail("No errors expected"); 153 file.errorHandler = (s) {
154 Expect.fail("No errors expected");
155 };
156 file.openHandler = () {
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();
154 }; 172 };
155 file.openHandler = () { 173 file.close();
156 file.readListHandler = (bytes_read) {
157 Expect.equals(42, bytes_read);
158 file.closeHandler = () {
159 // Now compare the two buffers to check if they
160 // are identical.
161 Expect.equals(buffer1.length, buffer2.length);
162 for (int i = 0; i < buffer1.length; i++) {
163 Expect.equals(buffer1[i], buffer2[i]);
164 }
165 };
166 file.close();
167 };
168 file.readList(buffer2, 0, 42);
169 };
170 file.open();
171 }; 174 };
172 file.close(); 175 file.writeList(buffer1, 0, bytes_read);
173 }; 176 };
174 file.writeList(buffer1, 0, bytes_read); 177 file.open(true);
175 }; 178 };
176 file.open(true); 179 file.create();
177 }; 180 };
178 file.close(); 181 file.close();
179 }; 182 };
180 file.readList(buffer1, 0, 42); 183 file.readList(buffer1, 0, 42);
181 }; 184 };
182 file.open(); 185 file.open();
183 return 1; 186 return 1;
184 187
185 } 188 }
186 189
187 static int testReadWriteSync() { 190 static int testReadWriteSync() {
188 // Read a file. 191 // Read a file.
189 String inFilename = getFilename("tests/vm/data/fixed_length_file"); 192 String inFilename = getFilename("tests/vm/data/fixed_length_file");
190 File file = new File(inFilename); 193 File file = new File(inFilename);
191 file.openSync(); 194 file.openSync();
192 List<int> buffer1 = new List<int>(42); 195 List<int> buffer1 = new List<int>(42);
193 int bytes_read = 0; 196 int bytes_read = 0;
194 int bytes_written = 0; 197 int bytes_written = 0;
195 bytes_read = file.readListSync(buffer1, 0, 42); 198 bytes_read = file.readListSync(buffer1, 0, 42);
196 Expect.equals(42, bytes_read); 199 Expect.equals(42, bytes_read);
197 file.closeSync(); 200 file.closeSync();
198 // Write the contents of the file just read into another file. 201 // Write the contents of the file just read into another file.
199 String outFilenameBase = getFilename("tests/vm/data/fixed_length_file"); 202 String outFilenameBase = getFilename("tests/vm/data/fixed_length_file");
200 file = new File(outFilenameBase + "_out"); 203 file = new File(outFilenameBase + "_out");
204 file.createSync();
201 file.openSync(true); 205 file.openSync(true);
202 file.writeListSync(buffer1, 0, bytes_read); 206 file.writeListSync(buffer1, 0, bytes_read);
203 file.closeSync(); 207 file.closeSync();
204 // Now read the contents of the file just written. 208 // Now read the contents of the file just written.
205 List<int> buffer2 = new List<int>(bytes_read); 209 List<int> buffer2 = new List<int>(bytes_read);
206 file = new File(getFilename(outFilenameBase)); 210 file = new File(getFilename(outFilenameBase));
207 file.openSync(); 211 file.openSync();
208 bytes_read = file.readListSync(buffer2, 0, 42); 212 bytes_read = file.readListSync(buffer2, 0, 42);
209 Expect.equals(42, bytes_read); 213 Expect.equals(42, bytes_read);
210 file.closeSync(); 214 file.closeSync();
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 Expect.equals(1, testCloseException()); 551 Expect.equals(1, testCloseException());
548 Expect.equals(1, testCloseExceptionStream()); 552 Expect.equals(1, testCloseExceptionStream());
549 Expect.equals(1, testBufferOutOfBoundsException()); 553 Expect.equals(1, testBufferOutOfBoundsException());
550 Expect.equals(1, testMixedSyncAndAsync()); 554 Expect.equals(1, testMixedSyncAndAsync());
551 } 555 }
552 } 556 }
553 557
554 main() { 558 main() {
555 FileTest.testMain(); 559 FileTest.testMain();
556 } 560 }
OLDNEW
« no previous file with comments | « runtime/bin/process_script.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698