OLD | NEW |
1 // Copyright (c) 2012, 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 // Testing file input stream, VM-only, standalone test. | 4 // Testing file input stream, VM-only, standalone test. |
5 | 5 |
6 import "dart:io"; | 6 import "dart:io"; |
7 import "dart:isolate"; | 7 import "dart:isolate"; |
8 | 8 |
9 // Helper method to be able to run the test from the runtime | 9 // Helper method to be able to run the test from the runtime |
10 // directory, or the top directory. | 10 // directory, or the top directory. |
11 String getFilename(String path) => | 11 String getFilename(String path) => |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // Start streaming the file. Pause after first chunk. Truncate | 70 // Start streaming the file. Pause after first chunk. Truncate |
71 // underlying file and check that the streaming stops with or | 71 // underlying file and check that the streaming stops with or |
72 // without getting all data. | 72 // without getting all data. |
73 var streamedBytes = 0; | 73 var streamedBytes = 0; |
74 var subscription; | 74 var subscription; |
75 subscription = file.openRead().listen( | 75 subscription = file.openRead().listen( |
76 (d) { | 76 (d) { |
77 if (streamedBytes == 0) { | 77 if (streamedBytes == 0) { |
78 subscription.pause(); | 78 subscription.pause(); |
79 // Truncate the file by opening it for writing. | 79 // Truncate the file by opening it for writing. |
80 file.open(FileMode.WRITE).then((opened) { | 80 file.open(mode: FileMode.WRITE).then((opened) { |
81 opened.close().then((_) { | 81 opened.close().then((_) { |
82 Expect.equals(0, file.lengthSync()); | 82 Expect.equals(0, file.lengthSync()); |
83 subscription.resume(); | 83 subscription.resume(); |
84 }); | 84 }); |
85 }); | 85 }); |
86 } | 86 } |
87 streamedBytes += d.length; | 87 streamedBytes += d.length; |
88 }, | 88 }, |
89 onDone: () { | 89 onDone: () { |
90 Expect.isTrue(streamedBytes > 0 && streamedBytes <= originalLength); | 90 Expect.isTrue(streamedBytes > 0 && streamedBytes <= originalLength); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // Start streaming the file. Pause after first chunk. Append to | 143 // Start streaming the file. Pause after first chunk. Append to |
144 // underlying file and check that the stream gets all the data. | 144 // underlying file and check that the stream gets all the data. |
145 var streamedBytes = 0; | 145 var streamedBytes = 0; |
146 var subscription; | 146 var subscription; |
147 subscription = file.openRead().listen( | 147 subscription = file.openRead().listen( |
148 (d) { | 148 (d) { |
149 if (streamedBytes == 0) { | 149 if (streamedBytes == 0) { |
150 subscription.pause(); | 150 subscription.pause(); |
151 // Double the length of the underlying file. | 151 // Double the length of the underlying file. |
152 file.readAsBytes().then((bytes) { | 152 file.readAsBytes().then((bytes) { |
153 file.writeAsBytes(bytes, FileMode.APPEND).then((_) { | 153 file.writeAsBytes(bytes, mode: FileMode.APPEND).then((_) { |
154 Expect.equals(2 * originalLength, file.lengthSync()); | 154 Expect.equals(2 * originalLength, file.lengthSync()); |
155 subscription.resume(); | 155 subscription.resume(); |
156 }); | 156 }); |
157 }); | 157 }); |
158 } | 158 } |
159 streamedBytes += d.length; | 159 streamedBytes += d.length; |
160 }, | 160 }, |
161 onDone: () { | 161 onDone: () { |
162 Expect.equals(2 * originalLength, streamedBytes); | 162 Expect.equals(2 * originalLength, streamedBytes); |
163 temp.delete(recursive: true).then((_) => keepAlive.close()); | 163 temp.delete(recursive: true).then((_) => keepAlive.close()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 testOpenStreamAsync(); | 196 testOpenStreamAsync(); |
197 testInputStreamTruncate(); | 197 testInputStreamTruncate(); |
198 testInputStreamDelete(); | 198 testInputStreamDelete(); |
199 testInputStreamAppend(); | 199 testInputStreamAppend(); |
200 // Check the length of these files as both are text files where one | 200 // Check the length of these files as both are text files where one |
201 // is without a terminating line separator which can easily be added | 201 // is without a terminating line separator which can easily be added |
202 // back if accidentally opened in a text editor. | 202 // back if accidentally opened in a text editor. |
203 testStringLineTransformerEnding("readline_test1.dat", 111); | 203 testStringLineTransformerEnding("readline_test1.dat", 111); |
204 testStringLineTransformerEnding("readline_test2.dat", 114); | 204 testStringLineTransformerEnding("readline_test2.dat", 114); |
205 } | 205 } |
OLD | NEW |