OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 class FileTest { | 5 class FileTest { |
6 static void testOpenInvalidArgs(name, [writable = false]) { | 6 static void testOpenInvalidArgs(name, [writable = false]) { |
7 var file = new File(name); | 7 var file = new File(name); |
8 try { | 8 try { |
9 file.openSync(); | 9 file.openSync(); |
10 Expect.fail('exception expected'); | 10 Expect.fail('exception expected'); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 file.errorHandler = (s) { | 54 file.errorHandler = (s) { |
55 Expect.isTrue(s.contains('Cannot create file')); | 55 Expect.isTrue(s.contains('Cannot create file')); |
56 }; | 56 }; |
57 file.createHandler = (created) { | 57 file.createHandler = (created) { |
58 Expect.fail('non-string name exists'); | 58 Expect.fail('non-string name exists'); |
59 }; | 59 }; |
60 file.create(); | 60 file.create(); |
61 } | 61 } |
62 | 62 |
63 static void testCloseNonOpened() { | |
64 var file = new File(0); | |
65 try { | |
66 file.closeSync(); | |
67 Expect.fail('exception expected'); | |
68 } catch (var e) { | |
69 Expect.isTrue(e is FileIOException); | |
70 Expect.isTrue(e.toString().contains('Cannot close file')); | |
71 } | |
72 | |
73 file.errorHandler = (s) { | |
74 Expect.isTrue(s.contains('Cannot close file')); | |
75 }; | |
76 file.closeHandler = () { | |
77 Expect.fail('close non-opened file'); | |
78 }; | |
79 file.close(); | |
80 } | |
81 | |
82 static void testReadListInvalidArgs(buffer, offset, length) { | 63 static void testReadListInvalidArgs(buffer, offset, length) { |
83 String filename = getFilename("tests/vm/data/fixed_length_file"); | 64 String filename = getFilename("tests/vm/data/fixed_length_file"); |
84 var file = new File(filename); | 65 var file = (new File(filename)).openSync(); |
85 file.openSync(); | |
86 try { | 66 try { |
87 file.readListSync(buffer, offset, length); | 67 file.readListSync(buffer, offset, length); |
88 Expect.fail('exception expected'); | 68 Expect.fail('exception expected'); |
89 } catch (var e) { | 69 } catch (var e) { |
90 Expect.isTrue(e is FileIOException); | 70 Expect.isTrue(e is FileIOException); |
91 Expect.isTrue(e.toString().contains('Invalid arguments')); | 71 Expect.isTrue(e.toString().contains('Invalid arguments')); |
92 } | 72 } |
93 | 73 |
94 var errors = 0; | 74 var errors = 0; |
95 file.errorHandler = (s) { | 75 file.errorHandler = (s) { |
96 errors++; | 76 errors++; |
97 Expect.isTrue(s.contains('Invalid arguments')); | 77 Expect.isTrue(s.contains('Invalid arguments')); |
98 }; | 78 }; |
99 file.readListHandler = (bytes) { | 79 file.readListHandler = (bytes) { |
100 Expect.fail('read list invalid arguments'); | 80 Expect.fail('read list invalid arguments'); |
101 }; | 81 }; |
102 file.readList(buffer, offset, length); | 82 file.readList(buffer, offset, length); |
103 file.closeHandler = () { | 83 file.closeHandler = () { |
104 Expect.equals(1, errors); | 84 Expect.equals(1, errors); |
105 }; | 85 }; |
106 file.close(); | 86 file.close(); |
107 } | 87 } |
108 | 88 |
109 static void testWriteByteInvalidArgs(value) { | 89 static void testWriteByteInvalidArgs(value) { |
110 String filename = getFilename("tests/vm/data/fixed_length_file"); | 90 String filename = getFilename("tests/vm/data/fixed_length_file"); |
111 var file = new File(filename + "_out"); | 91 var file = (new File(filename + "_out")).openSync(true); |
112 file.openSync(true); | |
113 try { | 92 try { |
114 file.writeByteSync(value); | 93 file.writeByteSync(value); |
115 Expect.fail('exception expected'); | 94 Expect.fail('exception expected'); |
116 } catch (var e) { | 95 } catch (var e) { |
117 Expect.isTrue(e is FileIOException); | 96 Expect.isTrue(e is FileIOException); |
118 Expect.isTrue(e.toString().contains('Invalid argument')); | 97 Expect.isTrue(e.toString().contains('Invalid argument')); |
119 } | 98 } |
120 | 99 |
121 var errors = 0; | 100 var errors = 0; |
122 file.errorHandler = (s) { | 101 file.errorHandler = (s) { |
123 errors++; | 102 errors++; |
124 Expect.isTrue(s.contains('Invalid argument')); | 103 Expect.isTrue(s.contains('Invalid argument')); |
125 }; | 104 }; |
126 file.noPendingWriteHandler = (bytes) { | 105 file.noPendingWriteHandler = (bytes) { |
127 Expect.fail('write list invalid argument'); | 106 Expect.fail('write list invalid argument'); |
128 }; | 107 }; |
129 file.writeByte(value); | 108 file.writeByte(value); |
130 file.closeHandler = () { | 109 file.closeHandler = () { |
131 Expect.equals(1, errors); | 110 Expect.equals(1, errors); |
132 }; | 111 }; |
133 file.close(); | 112 file.close(); |
134 } | 113 } |
135 | 114 |
136 static void testWriteListInvalidArgs(buffer, offset, bytes) { | 115 static void testWriteListInvalidArgs(buffer, offset, bytes) { |
137 String filename = getFilename("tests/vm/data/fixed_length_file"); | 116 String filename = getFilename("tests/vm/data/fixed_length_file"); |
138 var file = new File(filename + "_out"); | 117 var file = (new File(filename + "_out")).openSync(true); |
139 file.openSync(true); | |
140 try { | 118 try { |
141 file.writeListSync(buffer, offset, bytes); | 119 file.writeListSync(buffer, offset, bytes); |
142 Expect.fail('exception expected'); | 120 Expect.fail('exception expected'); |
143 } catch (var e) { | 121 } catch (var e) { |
144 Expect.isTrue(e is FileIOException); | 122 Expect.isTrue(e is FileIOException); |
145 Expect.isTrue(e.toString().contains('Invalid arguments')); | 123 Expect.isTrue(e.toString().contains('Invalid arguments')); |
146 } | 124 } |
147 | 125 |
148 var errors = 0; | 126 var errors = 0; |
149 file.errorHandler = (s) { | 127 file.errorHandler = (s) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 186 |
209 static String getFilename(String path) => | 187 static String getFilename(String path) => |
210 new File(path).existsSync() ? path : 'runtime/' + path; | 188 new File(path).existsSync() ? path : 'runtime/' + path; |
211 } | 189 } |
212 | 190 |
213 main() { | 191 main() { |
214 FileTest.testOpenInvalidArgs(0); | 192 FileTest.testOpenInvalidArgs(0); |
215 FileTest.testOpenInvalidArgs('name', 0); | 193 FileTest.testOpenInvalidArgs('name', 0); |
216 FileTest.testExistsInvalidArgs(0); | 194 FileTest.testExistsInvalidArgs(0); |
217 FileTest.testCreateInvalidArgs(0); | 195 FileTest.testCreateInvalidArgs(0); |
218 FileTest.testCloseNonOpened(); | |
219 FileTest.testReadListInvalidArgs(12, 0, 1); | 196 FileTest.testReadListInvalidArgs(12, 0, 1); |
220 FileTest.testReadListInvalidArgs(new List(10), '0', 1); | 197 FileTest.testReadListInvalidArgs(new List(10), '0', 1); |
221 FileTest.testReadListInvalidArgs(new List(10), 0, '1'); | 198 FileTest.testReadListInvalidArgs(new List(10), 0, '1'); |
222 FileTest.testWriteByteInvalidArgs('asdf'); | 199 FileTest.testWriteByteInvalidArgs('asdf'); |
223 FileTest.testWriteListInvalidArgs(12, 0, 1); | 200 FileTest.testWriteListInvalidArgs(12, 0, 1); |
224 FileTest.testWriteListInvalidArgs(new List(10), '0', 1); | 201 FileTest.testWriteListInvalidArgs(new List(10), '0', 1); |
225 FileTest.testWriteListInvalidArgs(new List(10), 0, '1'); | 202 FileTest.testWriteListInvalidArgs(new List(10), 0, '1'); |
226 FileTest.testFullPathInvalidArgs(12); | 203 FileTest.testFullPathInvalidArgs(12); |
227 } | 204 } |
OLD | NEW |