| 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 // Testing file input stream, VM-only, standalone test. | 4 // Testing file input stream, VM-only, standalone test. |
| 5 | 5 |
| 6 import "dart:convert"; | 6 import "dart:convert"; |
| 7 import "dart:io"; | 7 import "dart:io"; |
| 8 | 8 |
| 9 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
| 10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 202 } |
| 203 | 203 |
| 204 | 204 |
| 205 void testInputStreamBadOffset() { | 205 void testInputStreamBadOffset() { |
| 206 void test(int start, int end) { | 206 void test(int start, int end) { |
| 207 asyncStart(); | 207 asyncStart(); |
| 208 var temp = Directory.systemTemp.createTempSync('file_input_stream_test'); | 208 var temp = Directory.systemTemp.createTempSync('file_input_stream_test'); |
| 209 var file = new File('${temp.path}/input_stream_bad_offset.txt'); | 209 var file = new File('${temp.path}/input_stream_bad_offset.txt'); |
| 210 var originalLength = writeLongFileSync(file); | 210 var originalLength = writeLongFileSync(file); |
| 211 var streamedBytes = 0; | 211 var streamedBytes = 0; |
| 212 bool error = false; |
| 212 file.openRead(start, end).listen( | 213 file.openRead(start, end).listen( |
| 213 (d) { | 214 (d) { |
| 214 streamedBytes += d.length; | 215 streamedBytes += d.length; |
| 215 }, | 216 }, |
| 216 onDone: () { | 217 onDone: () { |
| 217 if (temp.existsSync()) { | 218 Expect.isTrue(error); |
| 218 temp.deleteSync(recursive: true); | 219 temp.deleteSync(recursive: true); |
| 219 } | 220 asyncEnd(); |
| 220 }, | 221 }, |
| 221 onError: (e) { | 222 onError: (e) { |
| 222 if (temp.existsSync()) { | 223 error = true; |
| 223 temp.deleteSync(recursive: true); | |
| 224 } | |
| 225 asyncEnd(); | |
| 226 }); | 224 }); |
| 227 } | 225 } |
| 228 test(-1, null); | 226 test(-1, null); |
| 229 test(100, 99); | 227 test(100, 99); |
| 230 test(null, -1); | 228 test(null, -1); |
| 231 } | 229 } |
| 232 | 230 |
| 233 | 231 |
| 234 void testStringLineSplitterEnding(String name, int length) { | 232 void testStringLineSplitterEnding(String name, int length) { |
| 235 String fileName = getFilename("tests/standalone/io/$name"); | 233 String fileName = getFilename("tests/standalone/io/$name"); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 261 testInputStreamDelete(); | 259 testInputStreamDelete(); |
| 262 testInputStreamAppend(); | 260 testInputStreamAppend(); |
| 263 testInputStreamOffset(); | 261 testInputStreamOffset(); |
| 264 testInputStreamBadOffset(); | 262 testInputStreamBadOffset(); |
| 265 // Check the length of these files as both are text files where one | 263 // Check the length of these files as both are text files where one |
| 266 // is without a terminating line separator which can easily be added | 264 // is without a terminating line separator which can easily be added |
| 267 // back if accidentally opened in a text editor. | 265 // back if accidentally opened in a text editor. |
| 268 testStringLineSplitterEnding("readline_test1.dat", 111); | 266 testStringLineSplitterEnding("readline_test1.dat", 111); |
| 269 testStringLineSplitterEnding("readline_test2.dat", 114); | 267 testStringLineSplitterEnding("readline_test2.dat", 114); |
| 270 } | 268 } |
| OLD | NEW |