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 // OtherResources=fixed_length_file |
| 6 |
5 import "dart:async"; | 7 import "dart:async"; |
6 import "dart:io"; | 8 import "dart:io"; |
7 | 9 |
8 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
9 import "package:expect/expect.dart"; | 11 import "package:expect/expect.dart"; |
10 | 12 |
11 void testReadInvalidArgs(arg) { | 13 void testReadInvalidArgs(arg) { |
12 String filename = getFilename("tests/vm/data/fixed_length_file"); | 14 String filename = getFilename("fixed_length_file"); |
13 var file = (new File(filename)).openSync(); | 15 var file = (new File(filename)).openSync(); |
14 Expect.throws(() => file.readSync(arg), | 16 Expect.throws(() => file.readSync(arg), |
15 (e) => e is ArgumentError); | 17 (e) => e is ArgumentError); |
16 | 18 |
17 Expect.throws(() => file.read(arg), | 19 Expect.throws(() => file.read(arg), |
18 (e) => e is ArgumentError); | 20 (e) => e is ArgumentError); |
19 file.closeSync(); | 21 file.closeSync(); |
20 } | 22 } |
21 | 23 |
22 void testReadIntoInvalidArgs(buffer, start, end) { | 24 void testReadIntoInvalidArgs(buffer, start, end) { |
23 String filename = getFilename("tests/vm/data/fixed_length_file"); | 25 String filename = getFilename("fixed_length_file"); |
24 var file = (new File(filename)).openSync(); | 26 var file = (new File(filename)).openSync(); |
25 Expect.throws(() => file.readIntoSync(buffer, start, end), | 27 Expect.throws(() => file.readIntoSync(buffer, start, end), |
26 (e) => e is ArgumentError); | 28 (e) => e is ArgumentError); |
27 | 29 |
28 Expect.throws(() => file.readInto(buffer, start, end), | 30 Expect.throws(() => file.readInto(buffer, start, end), |
29 (e) => e is ArgumentError); | 31 (e) => e is ArgumentError); |
30 file.closeSync(); | 32 file.closeSync(); |
31 } | 33 } |
32 | 34 |
33 void testWriteByteInvalidArgs(value) { | 35 void testWriteByteInvalidArgs(value) { |
34 String filename = getFilename("tests/vm/data/fixed_length_file"); | 36 String filename = getFilename("fixed_length_file"); |
35 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); | 37 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); |
36 Expect.throws(() => file.writeByteSync(value), | 38 Expect.throws(() => file.writeByteSync(value), |
37 (e) => e is ArgumentError); | 39 (e) => e is ArgumentError); |
38 | 40 |
39 Expect.throws(() => file.writeByte(value), | 41 Expect.throws(() => file.writeByte(value), |
40 (e) => e is ArgumentError); | 42 (e) => e is ArgumentError); |
41 file.closeSync(); | 43 file.closeSync(); |
42 } | 44 } |
43 | 45 |
44 void testWriteFromInvalidArgs(buffer, start, end) { | 46 void testWriteFromInvalidArgs(buffer, start, end) { |
45 String filename = getFilename("tests/vm/data/fixed_length_file"); | 47 String filename = getFilename("fixed_length_file"); |
46 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); | 48 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); |
47 Expect.throws(() => file.writeFromSync(buffer, start, end), | 49 Expect.throws(() => file.writeFromSync(buffer, start, end), |
48 (e) => e is ArgumentError); | 50 (e) => e is ArgumentError); |
49 | 51 |
50 Expect.throws(() => file.writeFrom(buffer, start, end), | 52 Expect.throws(() => file.writeFrom(buffer, start, end), |
51 (e) => e is ArgumentError); | 53 (e) => e is ArgumentError); |
52 file.closeSync(); | 54 file.closeSync(); |
53 } | 55 } |
54 | 56 |
55 void testWriteStringInvalidArgs(string, encoding) { | 57 void testWriteStringInvalidArgs(string, encoding) { |
56 String filename = getFilename("tests/vm/data/fixed_length_file"); | 58 String filename = getFilename("fixed_length_file"); |
57 var file = new File("${filename}_out").openSync(mode: FileMode.WRITE); | 59 var file = new File("${filename}_out").openSync(mode: FileMode.WRITE); |
58 Expect.throws(() => file.writeStringSync(string, encoding: encoding), | 60 Expect.throws(() => file.writeStringSync(string, encoding: encoding), |
59 (e) => e is ArgumentError); | 61 (e) => e is ArgumentError); |
60 | 62 |
61 Expect.throws(() => file.writeString(string, encoding: encoding), | 63 Expect.throws(() => file.writeString(string, encoding: encoding), |
62 (e) => e is ArgumentError); | 64 (e) => e is ArgumentError); |
63 file.closeSync(); | 65 file.closeSync(); |
64 } | 66 } |
65 | 67 |
66 Future futureThrows(Future result) { | 68 Future futureThrows(Future result) { |
(...skipping 25 matching lines...) Expand all Loading... |
92 FileSystemEntity.identical(x, y))([1,2,3], "."))) | 94 FileSystemEntity.identical(x, y))([1,2,3], "."))) |
93 .then((_) => futureThrows(((x, y) => | 95 .then((_) => futureThrows(((x, y) => |
94 FileSystemEntity.identical(x, y))(".", 52))) | 96 FileSystemEntity.identical(x, y))(".", 52))) |
95 .then((_) => futureThrows(((x) => FileSystemEntity.isLink(x))(52))) | 97 .then((_) => futureThrows(((x) => FileSystemEntity.isLink(x))(52))) |
96 .then((_) => futureThrows(((x) => FileSystemEntity.isFile(x))(52))) | 98 .then((_) => futureThrows(((x) => FileSystemEntity.isFile(x))(52))) |
97 .then((_) => futureThrows(((x) => FileSystemEntity.isDirectory(x))(52))) | 99 .then((_) => futureThrows(((x) => FileSystemEntity.isDirectory(x))(52))) |
98 .then((_) => asyncEnd()); | 100 .then((_) => asyncEnd()); |
99 } | 101 } |
100 | 102 |
101 String getFilename(String path) { | 103 String getFilename(String path) { |
102 var testPath = Platform.script.resolve('../../../$path'); | 104 return Platform.script.resolve(path).toFilePath(); |
103 return new File.fromUri(testPath).existsSync() | |
104 ? testPath.toFilePath() | |
105 : Platform.script.resolve('../../../runtime/$path').toFilePath(); | |
106 } | 105 } |
107 | 106 |
108 main() { | 107 main() { |
109 testReadInvalidArgs('asdf'); | 108 testReadInvalidArgs('asdf'); |
110 testReadIntoInvalidArgs(12, 0, 1); | 109 testReadIntoInvalidArgs(12, 0, 1); |
111 testReadIntoInvalidArgs(new List(10), '0', 1); | 110 testReadIntoInvalidArgs(new List(10), '0', 1); |
112 testReadIntoInvalidArgs(new List(10), 0, '1'); | 111 testReadIntoInvalidArgs(new List(10), 0, '1'); |
113 testWriteByteInvalidArgs('asdf'); | 112 testWriteByteInvalidArgs('asdf'); |
114 testWriteFromInvalidArgs(12, 0, 1); | 113 testWriteFromInvalidArgs(12, 0, 1); |
115 testWriteFromInvalidArgs(new List(10), '0', 1); | 114 testWriteFromInvalidArgs(new List(10), '0', 1); |
116 testWriteFromInvalidArgs(new List(10), 0, '1'); | 115 testWriteFromInvalidArgs(new List(10), 0, '1'); |
117 testWriteStringInvalidArgs("Hello, world", 42); | 116 testWriteStringInvalidArgs("Hello, world", 42); |
118 testFileSystemEntity(); | 117 testFileSystemEntity(); |
119 } | 118 } |
OLD | NEW |