| 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 file I/O. | 5 // Dart test program for testing file I/O. |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 | 10 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 Expect.equals(103, buffer[9]); // represents 'g' in the file. | 218 Expect.equals(103, buffer[9]); // represents 'g' in the file. |
| 219 file.close().then((ignore) => port.close()); | 219 file.close().then((ignore) => port.close()); |
| 220 }); | 220 }); |
| 221 }); | 221 }); |
| 222 }); | 222 }); |
| 223 } | 223 } |
| 224 | 224 |
| 225 static void testReadSync() { | 225 static void testReadSync() { |
| 226 // Read a file and check part of it's contents. | 226 // Read a file and check part of it's contents. |
| 227 String filename = getFilename("bin/file_test.cc"); | 227 String filename = getFilename("bin/file_test.cc"); |
| 228 RandomAccessFile file = (new File(filename)).openSync(); | 228 RandomAccessFile raf = (new File(filename)).openSync(); |
| 229 List<int> buffer = new List<int>(42); | 229 List<int> buffer = new List<int>(42); |
| 230 int bytes_read = 0; | 230 int bytes_read = 0; |
| 231 bytes_read = file.readListSync(buffer, 0, 12); | 231 bytes_read = raf.readListSync(buffer, 0, 12); |
| 232 Expect.equals(12, bytes_read); | 232 Expect.equals(12, bytes_read); |
| 233 bytes_read = file.readListSync(buffer, 12, 30); | 233 bytes_read = raf.readListSync(buffer, 12, 30); |
| 234 Expect.equals(30, bytes_read); | 234 Expect.equals(30, bytes_read); |
| 235 Expect.equals(47, buffer[0]); // represents '/' in the file. | 235 Expect.equals(47, buffer[0]); // represents '/' in the file. |
| 236 Expect.equals(47, buffer[1]); // represents '/' in the file. | 236 Expect.equals(47, buffer[1]); // represents '/' in the file. |
| 237 Expect.equals(32, buffer[2]); // represents ' ' in the file. | 237 Expect.equals(32, buffer[2]); // represents ' ' in the file. |
| 238 Expect.equals(67, buffer[3]); // represents 'C' in the file. | 238 Expect.equals(67, buffer[3]); // represents 'C' in the file. |
| 239 Expect.equals(111, buffer[4]); // represents 'o' in the file. | 239 Expect.equals(111, buffer[4]); // represents 'o' in the file. |
| 240 Expect.equals(112, buffer[5]); // represents 'p' in the file. | 240 Expect.equals(112, buffer[5]); // represents 'p' in the file. |
| 241 Expect.equals(121, buffer[6]); // represents 'y' in the file. | 241 Expect.equals(121, buffer[6]); // represents 'y' in the file. |
| 242 Expect.equals(114, buffer[7]); // represents 'r' in the file. | 242 Expect.equals(114, buffer[7]); // represents 'r' in the file. |
| 243 Expect.equals(105, buffer[8]); // represents 'i' in the file. | 243 Expect.equals(105, buffer[8]); // represents 'i' in the file. |
| 244 Expect.equals(103, buffer[9]); // represents 'g' in the file. | 244 Expect.equals(103, buffer[9]); // represents 'g' in the file. |
| 245 Expect.equals(104, buffer[10]); // represents 'h' in the file. | 245 Expect.equals(104, buffer[10]); // represents 'h' in the file. |
| 246 Expect.equals(116, buffer[11]); // represents 't' in the file. | 246 Expect.equals(116, buffer[11]); // represents 't' in the file. |
| 247 | 247 |
| 248 filename = getFilename("tests/vm/data/fixed_length_file"); | 248 filename = getFilename("tests/vm/data/fixed_length_file"); |
| 249 file = new File(filename); | 249 File file = new File(filename); |
| 250 int len = file.lengthSync(); | 250 int len = file.lengthSync(); |
| 251 Expect.equals(0, file.openSync().readSync(0).length); | 251 Expect.equals(0, file.openSync().readSync(0).length); |
| 252 Expect.equals(1, file.openSync().readSync(1).length); | 252 Expect.equals(1, file.openSync().readSync(1).length); |
| 253 Expect.equals(len - 1, file.openSync().readSync(len - 1).length); | 253 Expect.equals(len - 1, file.openSync().readSync(len - 1).length); |
| 254 Expect.equals(len, file.openSync().readSync(len).length); | 254 Expect.equals(len, file.openSync().readSync(len).length); |
| 255 Expect.equals(len, file.openSync().readSync(len + 1).length); | 255 Expect.equals(len, file.openSync().readSync(len + 1).length); |
| 256 Expect.equals(len, file.openSync().readSync(len * 2).length); | 256 Expect.equals(len, file.openSync().readSync(len * 2).length); |
| 257 Expect.equals(len, file.openSync().readSync(len * 10).length); | 257 Expect.equals(len, file.openSync().readSync(len * 10).length); |
| 258 } | 258 } |
| 259 | 259 |
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1232 testDirectorySync(); | 1232 testDirectorySync(); |
| 1233 testWriteStringUtf8(); | 1233 testWriteStringUtf8(); |
| 1234 testWriteStringUtf8Sync(); | 1234 testWriteStringUtf8Sync(); |
| 1235 }); | 1235 }); |
| 1236 } | 1236 } |
| 1237 } | 1237 } |
| 1238 | 1238 |
| 1239 main() { | 1239 main() { |
| 1240 FileTest.testMain(); | 1240 FileTest.testMain(); |
| 1241 } | 1241 } |
| OLD | NEW |