| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import "package:path/path.dart"; | 8 import "package:path/path.dart"; |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 buffer.addAll(d); | 97 buffer.addAll(d); |
| 98 }, | 98 }, |
| 99 onDone: () { | 99 onDone: () { |
| 100 Expect.equals(42, buffer.length); | 100 Expect.equals(42, buffer.length); |
| 101 // Write the contents of the file just read into another file. | 101 // Write the contents of the file just read into another file. |
| 102 String outFilename = | 102 String outFilename = |
| 103 tempDirectory.path + "/out_read_write_stream"; | 103 tempDirectory.path + "/out_read_write_stream"; |
| 104 var file2 = new File(outFilename); | 104 var file2 = new File(outFilename); |
| 105 var output = file2.openWrite(); | 105 var output = file2.openWrite(); |
| 106 output.add(buffer); | 106 output.add(buffer); |
| 107 output.close(); | 107 output.flush().then((_) => output.close()); |
| 108 output.done.then((_) { | 108 output.done.then((_) { |
| 109 // Now read the contents of the file just written. | 109 // Now read the contents of the file just written. |
| 110 List<int> buffer2 = new List<int>(); | 110 List<int> buffer2 = new List<int>(); |
| 111 new File(outFilename).openRead().listen( | 111 new File(outFilename).openRead().listen( |
| 112 (d) { | 112 (d) { |
| 113 buffer2.addAll(d); | 113 buffer2.addAll(d); |
| 114 }, | 114 }, |
| 115 onDone: () { | 115 onDone: () { |
| 116 Expect.equals(42, buffer2.length); | 116 Expect.equals(42, buffer2.length); |
| 117 // Now compare the two buffers to check if they are | 117 // Now compare the two buffers to check if they are |
| (...skipping 18 matching lines...) Expand all Loading... |
| 136 List<int> buffer = new List<int>(100000); | 136 List<int> buffer = new List<int>(100000); |
| 137 for (var i = 0; i < buffer.length; ++i) { | 137 for (var i = 0; i < buffer.length; ++i) { |
| 138 buffer[i] = i % 256; | 138 buffer[i] = i % 256; |
| 139 } | 139 } |
| 140 String filename = | 140 String filename = |
| 141 tempDirectory.path + "/out_read_write_stream_large_file"; | 141 tempDirectory.path + "/out_read_write_stream_large_file"; |
| 142 File file = new File(filename); | 142 File file = new File(filename); |
| 143 IOSink output = file.openWrite(); | 143 IOSink output = file.openWrite(); |
| 144 output.add(buffer); | 144 output.add(buffer); |
| 145 output.add(buffer); | 145 output.add(buffer); |
| 146 output.close(); | 146 output.flush().then((_) => output.close()); |
| 147 output.done.then((_) { | 147 output.done.then((_) { |
| 148 Stream input = file.openRead(); | 148 Stream input = file.openRead(); |
| 149 int position = 0; | 149 int position = 0; |
| 150 final int expectedLength = 200000; | 150 final int expectedLength = 200000; |
| 151 // Start an independent asynchronous check on the length. | 151 // Start an independent asynchronous check on the length. |
| 152 asyncTestStarted(); | 152 asyncTestStarted(); |
| 153 file.length().then((len) { | 153 file.length().then((len) { |
| 154 Expect.equals(expectedLength, len); | 154 Expect.equals(expectedLength, len); |
| 155 asyncTestDone('testReadWriteStreamLargeFile: length check'); | 155 asyncTestDone('testReadWriteStreamLargeFile: length check'); |
| 156 }); | 156 }); |
| (...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 testWriteStringUtf8Sync(); | 1330 testWriteStringUtf8Sync(); |
| 1331 testRename(); | 1331 testRename(); |
| 1332 testRenameSync(); | 1332 testRenameSync(); |
| 1333 }); | 1333 }); |
| 1334 } | 1334 } |
| 1335 } | 1335 } |
| 1336 | 1336 |
| 1337 main() { | 1337 main() { |
| 1338 FileTest.testMain(); | 1338 FileTest.testMain(); |
| 1339 } | 1339 } |
| OLD | NEW |