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 27 matching lines...) Expand all Loading... |
38 | 38 |
39 static void deleteTempDirectory() { | 39 static void deleteTempDirectory() { |
40 tempDirectory.deleteSync(recursive: true); | 40 tempDirectory.deleteSync(recursive: true); |
41 } | 41 } |
42 | 42 |
43 // Test for file read functionality. | 43 // Test for file read functionality. |
44 static void testReadStream() { | 44 static void testReadStream() { |
45 // Read a file and check part of it's contents. | 45 // Read a file and check part of it's contents. |
46 String filename = getFilename("bin/file_test.cc"); | 46 String filename = getFilename("bin/file_test.cc"); |
47 File file = new File(filename); | 47 File file = new File(filename); |
48 Expect.isTrue('$file'.contains(file.name)); | 48 Expect.isTrue('$file'.contains(file.path)); |
49 var subscription; | 49 var subscription; |
50 List<int> buffer = new List<int>(); | 50 List<int> buffer = new List<int>(); |
51 subscription = file.openRead().listen( | 51 subscription = file.openRead().listen( |
52 (d) { | 52 (d) { |
53 buffer.addAll(d); | 53 buffer.addAll(d); |
54 if (buffer.length >= 12) { | 54 if (buffer.length >= 12) { |
55 subscription.cancel(); | 55 subscription.cancel(); |
56 Expect.equals(47, buffer[0]); // represents '/' in the file. | 56 Expect.equals(47, buffer[0]); // represents '/' in the file. |
57 Expect.equals(47, buffer[1]); // represents '/' in the file. | 57 Expect.equals(47, buffer[1]); // represents '/' in the file. |
58 Expect.equals(32, buffer[2]); // represents ' ' in the file. | 58 Expect.equals(32, buffer[2]); // represents ' ' in the file. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 }) | 165 }) |
166 .catchError((e) { | 166 .catchError((e) { |
167 print('Exception while deleting ReadWriteStreamLargeFile file'); | 167 print('Exception while deleting ReadWriteStreamLargeFile file'); |
168 print('Exception $e'); | 168 print('Exception $e'); |
169 }); | 169 }); |
170 }); | 170 }); |
171 }); | 171 }); |
172 } | 172 } |
173 | 173 |
174 static Future testPipe(File file, buffer) { | 174 static Future testPipe(File file, buffer) { |
175 String outputFilename = '${file.name}_copy'; | 175 String outputFilename = '${file.path}_copy'; |
176 File outputFile = new File(outputFilename); | 176 File outputFile = new File(outputFilename); |
177 var input = file.openRead(); | 177 var input = file.openRead(); |
178 var output = outputFile.openWrite(); | 178 var output = outputFile.openWrite(); |
179 Completer done = new Completer(); | 179 Completer done = new Completer(); |
180 input.pipe(output).then((_) { | 180 input.pipe(output).then((_) { |
181 var copy = outputFile.openRead(); | 181 var copy = outputFile.openRead(); |
182 int position = 0; | 182 int position = 0; |
183 copy.listen( | 183 copy.listen( |
184 (d) { | 184 (d) { |
185 for (int i = 0; i < d.length; i++) { | 185 for (int i = 0; i < d.length; i++) { |
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 testDirectorySync(); | 1221 testDirectorySync(); |
1222 testWriteStringUtf8(); | 1222 testWriteStringUtf8(); |
1223 testWriteStringUtf8Sync(); | 1223 testWriteStringUtf8Sync(); |
1224 }); | 1224 }); |
1225 } | 1225 } |
1226 } | 1226 } |
1227 | 1227 |
1228 main() { | 1228 main() { |
1229 FileTest.testMain(); | 1229 FileTest.testMain(); |
1230 } | 1230 } |
OLD | NEW |