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 "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 import "dart:io"; | 7 import "dart:io"; |
8 import "dart:isolate"; | 8 import "dart:isolate"; |
9 | 9 |
10 void testReadInvalidArgs(arg) { | 10 void testReadInvalidArgs(arg) { |
11 var port = new ReceivePort(); | 11 var port = new ReceivePort(); |
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 try { | 14 try { |
15 file.readSync(arg); | 15 file.readSync(arg); |
16 Expect.fail('exception expected'); | 16 Expect.fail('exception expected'); |
17 } catch (e) { | 17 } catch (e) { |
18 Expect.isTrue(e is FileIOException); | 18 Expect.isTrue(e is FileException); |
19 Expect.isTrue(e.toString().contains('Invalid arguments')); | 19 Expect.isTrue(e.toString().contains('Invalid arguments')); |
20 } | 20 } |
21 | 21 |
22 var errors = 0; | 22 var errors = 0; |
23 var readFuture = file.read(arg); | 23 var readFuture = file.read(arg); |
24 readFuture.then((bytes) { | 24 readFuture.then((bytes) { |
25 Expect.fail('exception expected'); | 25 Expect.fail('exception expected'); |
26 }).catchError((error) { | 26 }).catchError((error) { |
27 errors++; | 27 errors++; |
28 Expect.isTrue(error is FileIOException); | 28 Expect.isTrue(error is FileException); |
29 Expect.isTrue(error.toString().contains('Invalid arguments')); | 29 Expect.isTrue(error.toString().contains('Invalid arguments')); |
30 file.close().then((ignore) { | 30 file.close().then((ignore) { |
31 Expect.equals(1, errors); | 31 Expect.equals(1, errors); |
32 port.close(); | 32 port.close(); |
33 }); | 33 }); |
34 }); | 34 }); |
35 } | 35 } |
36 | 36 |
37 void testReadIntoInvalidArgs(buffer, start, end) { | 37 void testReadIntoInvalidArgs(buffer, start, end) { |
38 var port = new ReceivePort(); | 38 var port = new ReceivePort(); |
39 String filename = getFilename("tests/vm/data/fixed_length_file"); | 39 String filename = getFilename("tests/vm/data/fixed_length_file"); |
40 var file = (new File(filename)).openSync(); | 40 var file = (new File(filename)).openSync(); |
41 try { | 41 try { |
42 file.readIntoSync(buffer, start, end); | 42 file.readIntoSync(buffer, start, end); |
43 Expect.fail('exception expected'); | 43 Expect.fail('exception expected'); |
44 } catch (e) { | 44 } catch (e) { |
45 Expect.isTrue(e is FileIOException); | 45 Expect.isTrue(e is FileException); |
46 Expect.isTrue(e.toString().contains('Invalid arguments')); | 46 Expect.isTrue(e.toString().contains('Invalid arguments')); |
47 } | 47 } |
48 | 48 |
49 var errors = 0; | 49 var errors = 0; |
50 var readIntoFuture = file.readInto(buffer, start, end); | 50 var readIntoFuture = file.readInto(buffer, start, end); |
51 readIntoFuture.then((bytes) { | 51 readIntoFuture.then((bytes) { |
52 Expect.fail('exception expected'); | 52 Expect.fail('exception expected'); |
53 }).catchError((error) { | 53 }).catchError((error) { |
54 errors++; | 54 errors++; |
55 Expect.isTrue(error is FileIOException); | 55 Expect.isTrue(error is FileException); |
56 Expect.isTrue(error.toString().contains('Invalid arguments')); | 56 Expect.isTrue(error.toString().contains('Invalid arguments')); |
57 file.close().then((ignore) { | 57 file.close().then((ignore) { |
58 Expect.equals(1, errors); | 58 Expect.equals(1, errors); |
59 port.close(); | 59 port.close(); |
60 }); | 60 }); |
61 }); | 61 }); |
62 } | 62 } |
63 | 63 |
64 void testWriteByteInvalidArgs(value) { | 64 void testWriteByteInvalidArgs(value) { |
65 var port = new ReceivePort(); | 65 var port = new ReceivePort(); |
66 String filename = getFilename("tests/vm/data/fixed_length_file"); | 66 String filename = getFilename("tests/vm/data/fixed_length_file"); |
67 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); | 67 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); |
68 try { | 68 try { |
69 file.writeByteSync(value); | 69 file.writeByteSync(value); |
70 Expect.fail('exception expected'); | 70 Expect.fail('exception expected'); |
71 } catch (e) { | 71 } catch (e) { |
72 Expect.isTrue(e is FileIOException); | 72 Expect.isTrue(e is FileException); |
73 Expect.isTrue(e.toString().contains('Invalid argument')); | 73 Expect.isTrue(e.toString().contains('Invalid argument')); |
74 } | 74 } |
75 | 75 |
76 var writeByteFuture = file.writeByte(value); | 76 var writeByteFuture = file.writeByte(value); |
77 writeByteFuture.then((ignore) { | 77 writeByteFuture.then((ignore) { |
78 Expect.fail('exception expected'); | 78 Expect.fail('exception expected'); |
79 }).catchError((error) { | 79 }).catchError((error) { |
80 Expect.isTrue(error is FileIOException); | 80 Expect.isTrue(error is FileException); |
81 Expect.isTrue(error.toString().contains('Invalid argument')); | 81 Expect.isTrue(error.toString().contains('Invalid argument')); |
82 file.close().then((ignore) { | 82 file.close().then((ignore) { |
83 port.close(); | 83 port.close(); |
84 }); | 84 }); |
85 }); | 85 }); |
86 } | 86 } |
87 | 87 |
88 void testWriteFromInvalidArgs(buffer, start, end) { | 88 void testWriteFromInvalidArgs(buffer, start, end) { |
89 var port = new ReceivePort(); | 89 var port = new ReceivePort(); |
90 String filename = getFilename("tests/vm/data/fixed_length_file"); | 90 String filename = getFilename("tests/vm/data/fixed_length_file"); |
91 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); | 91 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); |
92 try { | 92 try { |
93 file.writeFromSync(buffer, start, end); | 93 file.writeFromSync(buffer, start, end); |
94 Expect.fail('exception expected'); | 94 Expect.fail('exception expected'); |
95 } catch (e) { | 95 } catch (e) { |
96 Expect.isTrue(e is FileIOException); | 96 Expect.isTrue(e is FileException); |
97 Expect.isTrue(e.toString().contains('Invalid arguments')); | 97 Expect.isTrue(e.toString().contains('Invalid arguments')); |
98 } | 98 } |
99 | 99 |
100 var writeFromFuture = file.writeFrom(buffer, start, end); | 100 var writeFromFuture = file.writeFrom(buffer, start, end); |
101 writeFromFuture.then((ignore) { | 101 writeFromFuture.then((ignore) { |
102 Expect.fail('exception expected'); | 102 Expect.fail('exception expected'); |
103 }).catchError((error) { | 103 }).catchError((error) { |
104 Expect.isTrue(error is FileIOException); | 104 Expect.isTrue(error is FileException); |
105 Expect.isTrue(error.toString().contains('Invalid arguments')); | 105 Expect.isTrue(error.toString().contains('Invalid arguments')); |
106 file.close().then((ignore) { | 106 file.close().then((ignore) { |
107 port.close(); | 107 port.close(); |
108 }); | 108 }); |
109 }); | 109 }); |
110 } | 110 } |
111 | 111 |
112 void testWriteStringInvalidArgs(string, encoding) { | 112 void testWriteStringInvalidArgs(string, encoding) { |
113 var port = new ReceivePort(); | 113 var port = new ReceivePort(); |
114 String filename = getFilename("tests/vm/data/fixed_length_file"); | 114 String filename = getFilename("tests/vm/data/fixed_length_file"); |
115 var file = new File("${filename}_out").openSync(mode: FileMode.WRITE); | 115 var file = new File("${filename}_out").openSync(mode: FileMode.WRITE); |
116 try { | 116 try { |
117 file.writeStringSync(string, encoding: encoding); | 117 file.writeStringSync(string, encoding: encoding); |
118 Expect.fail('exception expected'); | 118 Expect.fail('exception expected'); |
119 } catch (e) { | 119 } catch (e) { |
120 Expect.isTrue(e is FileIOException); | 120 Expect.isTrue(e is FileException); |
121 } | 121 } |
122 | 122 |
123 var writeStringFuture = file.writeString(string, encoding: encoding); | 123 var writeStringFuture = file.writeString(string, encoding: encoding); |
124 writeStringFuture.then((ignore) { | 124 writeStringFuture.then((ignore) { |
125 Expect.fail('exception expected'); | 125 Expect.fail('exception expected'); |
126 }).catchError((error) { | 126 }).catchError((error) { |
127 Expect.isTrue(error is FileIOException); | 127 Expect.isTrue(error is FileException); |
128 file.close().then((ignore) { | 128 file.close().then((ignore) { |
129 port.close(); | 129 port.close(); |
130 }); | 130 }); |
131 }); | 131 }); |
132 } | 132 } |
133 | 133 |
134 Future futureThrows(Future result) { | 134 Future futureThrows(Future result) { |
135 return result.then((value) { | 135 return result.then((value) { |
136 throw new ExpectException( | 136 throw new ExpectException( |
137 "futureThrows received $value instead of an exception"); | 137 "futureThrows received $value instead of an exception"); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 testReadIntoInvalidArgs(12, 0, 1); | 175 testReadIntoInvalidArgs(12, 0, 1); |
176 testReadIntoInvalidArgs(new List(10), '0', 1); | 176 testReadIntoInvalidArgs(new List(10), '0', 1); |
177 testReadIntoInvalidArgs(new List(10), 0, '1'); | 177 testReadIntoInvalidArgs(new List(10), 0, '1'); |
178 testWriteByteInvalidArgs('asdf'); | 178 testWriteByteInvalidArgs('asdf'); |
179 testWriteFromInvalidArgs(12, 0, 1); | 179 testWriteFromInvalidArgs(12, 0, 1); |
180 testWriteFromInvalidArgs(new List(10), '0', 1); | 180 testWriteFromInvalidArgs(new List(10), '0', 1); |
181 testWriteFromInvalidArgs(new List(10), 0, '1'); | 181 testWriteFromInvalidArgs(new List(10), 0, '1'); |
182 testWriteStringInvalidArgs("Hello, world", 42); | 182 testWriteStringInvalidArgs("Hello, world", 42); |
183 testFileSystemEntity(); | 183 testFileSystemEntity(); |
184 } | 184 } |
OLD | NEW |