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

Unified Diff: tests/standalone/io/file_input_stream_test.dart

Issue 15547003: Add 'start' and 'end' optional arguments to File.openRead(). This makes it possible to stream a sub… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: aFix comments. Created 7 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/file_input_stream_test.dart
diff --git a/tests/standalone/io/file_input_stream_test.dart b/tests/standalone/io/file_input_stream_test.dart
index 93c9deb634ecb261a12a58299bfeab2c5cdb7bb4..5a4adf1911de4a73c25c1a0616c384a07e53e67f 100644
--- a/tests/standalone/io/file_input_stream_test.dart
+++ b/tests/standalone/io/file_input_stream_test.dart
@@ -169,6 +169,60 @@ void testInputStreamAppend() {
}
+void testInputStreamOffset() {
+ void test(int start, int end, int expectedBytes) {
+ var keepAlive = new ReceivePort();
+ var temp = new Directory('').createTempSync();
+ var file = new File('${temp.path}/input_stream_offset.txt');
+ var originalLength = writeLongFileSync(file);
+ var streamedBytes = 0;
+ if (expectedBytes < 0) expectedBytes = originalLength + expectedBytes;
+ file.openRead(start, end).listen(
+ (d) {
+ streamedBytes += d.length;
+ },
+ onDone: () {
+ Expect.equals(expectedBytes, streamedBytes);
+ temp.delete(recursive: true).then((_) => keepAlive.close());
+ },
+ onError: (e) {
+ Expect.fail("Unexpected error");
+ });
+ }
+ test(10, 20, 10);
+ test(10, 11, 1);
+ test(10, 10, 0);
+ test(100000000, null, 0);
+ test(null, 0, 0);
+ test(null, 1, 1);
+ test(1, null, -1);
+ test(20, null, -20);
+}
+
+
+void testInputStreamBadOffset() {
+ void test(int start, int end) {
+ var keepAlive = new ReceivePort();
+ var temp = new Directory('').createTempSync();
+ var file = new File('${temp.path}/input_stream_bad_offset.txt');
+ var originalLength = writeLongFileSync(file);
+ var streamedBytes = 0;
+ file.openRead(start, end).listen(
+ (d) {
+ streamedBytes += d.length;
+ },
+ onDone: () {
+ },
+ onError: (e) {
+ temp.delete(recursive: true).then((_) => keepAlive.close());
+ });
+ }
+ test(-1, null);
+ test(100, 99);
+ test(null, -1);
+}
+
+
void testStringLineTransformerEnding(String name, int length) {
String fileName = getFilename("tests/standalone/io/$name");
// File contains 10 lines.
@@ -198,6 +252,8 @@ main() {
testInputStreamTruncate();
testInputStreamDelete();
testInputStreamAppend();
+ testInputStreamOffset();
+ testInputStreamBadOffset();
// Check the length of these files as both are text files where one
// is without a terminating line separator which can easily be added
// back if accidentally opened in a text editor.
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698