| 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 // 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. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 Expect.fail("More or less than 2 lines read ($linesRead lines read)."); | 29 Expect.fail("More or less than 2 lines read ($linesRead lines read)."); |
| 30 } | 30 } |
| 31 }); | 31 }); |
| 32 } | 32 } |
| 33 | 33 |
| 34 | 34 |
| 35 void testOpenStreamAsync() { | 35 void testOpenStreamAsync() { |
| 36 var keepAlive = new ReceivePort(); | 36 var keepAlive = new ReceivePort(); |
| 37 String fileName = getFilename("tests/standalone/io/readuntil_test.dat"); | 37 String fileName = getFilename("tests/standalone/io/readuntil_test.dat"); |
| 38 // File contains "Hello Dart\nwassup!\n" | 38 // File contains "Hello Dart\nwassup!\n" |
| 39 var expected = "Hello Dart\nwassup!\n".charCodes; | 39 var expected = "Hello Dart\nwassup!\n".codeUnits; |
| 40 var byteCount = 0; | 40 var byteCount = 0; |
| 41 (new File(fileName)).openRead().listen( | 41 (new File(fileName)).openRead().listen( |
| 42 (d) => byteCount += d.length, | 42 (d) => byteCount += d.length, |
| 43 onDone: () { | 43 onDone: () { |
| 44 Expect.equals(expected.length, byteCount); | 44 Expect.equals(expected.length, byteCount); |
| 45 keepAlive.close(); | 45 keepAlive.close(); |
| 46 }); | 46 }); |
| 47 } | 47 } |
| 48 | 48 |
| 49 | 49 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 }, | 88 }, |
| 89 onDone: () { | 89 onDone: () { |
| 90 Expect.isTrue(streamedBytes > 0 && streamedBytes <= originalLength); | 90 Expect.isTrue(streamedBytes > 0 && streamedBytes <= originalLength); |
| 91 temp.delete(recursive: true).then((_) => keepAlive.close()); | 91 temp.delete(recursive: true).then((_) => keepAlive.close()); |
| 92 }, | 92 }, |
| 93 onError: (e) { | 93 onError: (e) { |
| 94 Expect.fail("Unexpected error"); | 94 Expect.fail("Unexpected error"); |
| 95 }); | 95 }); |
| 96 } | 96 } |
| 97 | 97 |
| 98 | |
| 99 void testInputStreamDelete() { | 98 void testInputStreamDelete() { |
| 100 var keepAlive = new ReceivePort(); | 99 var keepAlive = new ReceivePort(); |
| 101 var temp = new Directory('').createTempSync(); | 100 var temp = new Directory('').createTempSync(); |
| 102 var file = new File('${temp.path}/input_stream_delete.txt'); | 101 var file = new File('${temp.path}/input_stream_delete.txt'); |
| 103 var originalLength = writeLongFileSync(file); | 102 var originalLength = writeLongFileSync(file); |
| 104 // Start streaming the file. Pause after first chunk. Truncate | 103 // Start streaming the file. Pause after first chunk. Truncate |
| 105 // underlying file and check that the streaming stops with or | 104 // underlying file and check that the streaming stops with or |
| 106 // without getting all data. | 105 // without getting all data. |
| 107 var streamedBytes = 0; | 106 var streamedBytes = 0; |
| 108 var subscription; | 107 var subscription; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 testOpenStreamAsync(); | 196 testOpenStreamAsync(); |
| 198 testInputStreamTruncate(); | 197 testInputStreamTruncate(); |
| 199 testInputStreamDelete(); | 198 testInputStreamDelete(); |
| 200 testInputStreamAppend(); | 199 testInputStreamAppend(); |
| 201 // 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 |
| 202 // is without a terminating line separator which can easily be added | 201 // is without a terminating line separator which can easily be added |
| 203 // back if accidentally opened in a text editor. | 202 // back if accidentally opened in a text editor. |
| 204 testStringLineTransformerEnding("readline_test1.dat", 111); | 203 testStringLineTransformerEnding("readline_test1.dat", 111); |
| 205 testStringLineTransformerEnding("readline_test2.dat", 114); | 204 testStringLineTransformerEnding("readline_test2.dat", 114); |
| 206 } | 205 } |
| OLD | NEW |