| 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 import "dart:async"; | 5 import "dart:async"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 | 7 |
| 8 import "package:async_helper/async_helper.dart"; | 8 import "package:async_helper/async_helper.dart"; |
| 9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
| 10 | 10 |
| 11 void testReadInvalidArgs(arg) { | 11 void testReadInvalidArgs(arg) { |
| 12 String filename = getFilename("tests/vm/data/fixed_length_file"); | 12 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 13 var file = (new File(filename)).openSync(); | 13 var file = (new File(filename)).openSync(); |
| 14 Expect.throws(() => file.readSync(arg), | 14 Expect.throws(() => file.readSync(arg), |
| 15 (e) => e is ArgumentError); | 15 (e) => e is ArgumentError); |
| 16 | 16 |
| 17 Expect.throws(() => file.read(arg), | 17 Expect.throws(() => file.read(arg), |
| 18 (e) => e is ArgumentError); | 18 (e) => e is ArgumentError); |
| 19 file.closeSync(); |
| 19 } | 20 } |
| 20 | 21 |
| 21 void testReadIntoInvalidArgs(buffer, start, end) { | 22 void testReadIntoInvalidArgs(buffer, start, end) { |
| 22 String filename = getFilename("tests/vm/data/fixed_length_file"); | 23 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 23 var file = (new File(filename)).openSync(); | 24 var file = (new File(filename)).openSync(); |
| 24 Expect.throws(() => file.readIntoSync(buffer, start, end), | 25 Expect.throws(() => file.readIntoSync(buffer, start, end), |
| 25 (e) => e is ArgumentError); | 26 (e) => e is ArgumentError); |
| 26 | 27 |
| 27 Expect.throws(() => file.readInto(buffer, start, end), | 28 Expect.throws(() => file.readInto(buffer, start, end), |
| 28 (e) => e is ArgumentError); | 29 (e) => e is ArgumentError); |
| 30 file.closeSync(); |
| 29 } | 31 } |
| 30 | 32 |
| 31 void testWriteByteInvalidArgs(value) { | 33 void testWriteByteInvalidArgs(value) { |
| 32 String filename = getFilename("tests/vm/data/fixed_length_file"); | 34 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 33 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); | 35 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); |
| 34 Expect.throws(() => file.writeByteSync(value), | 36 Expect.throws(() => file.writeByteSync(value), |
| 35 (e) => e is ArgumentError); | 37 (e) => e is ArgumentError); |
| 36 | 38 |
| 37 Expect.throws(() => file.writeByte(value), | 39 Expect.throws(() => file.writeByte(value), |
| 38 (e) => e is ArgumentError); | 40 (e) => e is ArgumentError); |
| 41 file.closeSync(); |
| 39 } | 42 } |
| 40 | 43 |
| 41 void testWriteFromInvalidArgs(buffer, start, end) { | 44 void testWriteFromInvalidArgs(buffer, start, end) { |
| 42 String filename = getFilename("tests/vm/data/fixed_length_file"); | 45 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 43 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); | 46 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); |
| 44 Expect.throws(() => file.writeFromSync(buffer, start, end), | 47 Expect.throws(() => file.writeFromSync(buffer, start, end), |
| 45 (e) => e is ArgumentError); | 48 (e) => e is ArgumentError); |
| 46 | 49 |
| 47 Expect.throws(() => file.writeFrom(buffer, start, end), | 50 Expect.throws(() => file.writeFrom(buffer, start, end), |
| 48 (e) => e is ArgumentError); | 51 (e) => e is ArgumentError); |
| 52 file.closeSync(); |
| 49 } | 53 } |
| 50 | 54 |
| 51 void testWriteStringInvalidArgs(string, encoding) { | 55 void testWriteStringInvalidArgs(string, encoding) { |
| 52 String filename = getFilename("tests/vm/data/fixed_length_file"); | 56 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 53 var file = new File("${filename}_out").openSync(mode: FileMode.WRITE); | 57 var file = new File("${filename}_out").openSync(mode: FileMode.WRITE); |
| 54 Expect.throws(() => file.writeStringSync(string, encoding: encoding), | 58 Expect.throws(() => file.writeStringSync(string, encoding: encoding), |
| 55 (e) => e is ArgumentError); | 59 (e) => e is ArgumentError); |
| 56 | 60 |
| 57 Expect.throws(() => file.writeString(string, encoding: encoding), | 61 Expect.throws(() => file.writeString(string, encoding: encoding), |
| 58 (e) => e is ArgumentError); | 62 (e) => e is ArgumentError); |
| 63 file.closeSync(); |
| 59 } | 64 } |
| 60 | 65 |
| 61 Future futureThrows(Future result) { | 66 Future futureThrows(Future result) { |
| 62 return result.then((value) { | 67 return result.then((value) { |
| 63 throw new ExpectException( | 68 throw new ExpectException( |
| 64 "futureThrows received $value instead of an exception"); | 69 "futureThrows received $value instead of an exception"); |
| 65 }, | 70 }, |
| 66 onError: (_) => null | 71 onError: (_) => null |
| 67 ); | 72 ); |
| 68 } | 73 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 testReadIntoInvalidArgs(12, 0, 1); | 107 testReadIntoInvalidArgs(12, 0, 1); |
| 103 testReadIntoInvalidArgs(new List(10), '0', 1); | 108 testReadIntoInvalidArgs(new List(10), '0', 1); |
| 104 testReadIntoInvalidArgs(new List(10), 0, '1'); | 109 testReadIntoInvalidArgs(new List(10), 0, '1'); |
| 105 testWriteByteInvalidArgs('asdf'); | 110 testWriteByteInvalidArgs('asdf'); |
| 106 testWriteFromInvalidArgs(12, 0, 1); | 111 testWriteFromInvalidArgs(12, 0, 1); |
| 107 testWriteFromInvalidArgs(new List(10), '0', 1); | 112 testWriteFromInvalidArgs(new List(10), '0', 1); |
| 108 testWriteFromInvalidArgs(new List(10), 0, '1'); | 113 testWriteFromInvalidArgs(new List(10), 0, '1'); |
| 109 testWriteStringInvalidArgs("Hello, world", 42); | 114 testWriteStringInvalidArgs("Hello, world", 42); |
| 110 testFileSystemEntity(); | 115 testFileSystemEntity(); |
| 111 } | 116 } |
| OLD | NEW |