| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:io"); | 5 #import("dart:io"); |
| 6 | 6 |
| 7 class FileTest { | 7 class FileTest { |
| 8 static void testOpenInvalidArgs(name, [writable = false]) { | 8 static void testOpenInvalidArgs(name) { |
| 9 var file = new File(name); | 9 var file = new File(name); |
| 10 try { | 10 try { |
| 11 file.openSync(); | 11 file.openSync(); |
| 12 Expect.fail('exception expected'); | 12 Expect.fail('exception expected'); |
| 13 } catch (var e) { | 13 } catch (var e) { |
| 14 Expect.isTrue(e is FileIOException); | 14 Expect.isTrue(e is IllegalArgumentException); |
| 15 Expect.isTrue(e.toString().contains('open file')); | |
| 16 } | 15 } |
| 17 | 16 |
| 18 file.onError = (s) { | 17 file.onError = (e) { |
| 19 Expect.isTrue(s.contains('open file')); | 18 Expect.isTrue(e is IllegalArgumentException); |
| 20 }; | 19 }; |
| 21 file.open(FileMode.READ, (opened) { | 20 file.open(FileMode.READ, (opened) { |
| 22 Expect.fail('non-string name open'); | 21 Expect.fail('non-string name open'); |
| 23 }); | 22 }); |
| 24 } | 23 } |
| 25 | 24 |
| 26 static void testExistsInvalidArgs(name) { | 25 static void testExistsInvalidArgs(name) { |
| 27 var file = new File(name); | 26 var file = new File(name); |
| 28 try { | 27 try { |
| 29 file.existsSync(); | 28 file.existsSync(); |
| 30 Expect.fail('exception expected'); | 29 Expect.fail('exception expected'); |
| 31 } catch (var e) { | 30 } catch (var e) { |
| 32 Expect.isTrue(e is FileIOException); | 31 Expect.isTrue(e is IllegalArgumentException); |
| 33 Expect.isTrue(e.toString().contains('is not a string')); | |
| 34 } | 32 } |
| 35 | 33 |
| 36 file.onError = (s) { | 34 file.onError = (e) { |
| 37 Expect.isTrue(s.contains('is not a string')); | 35 Expect.isTrue(e is IllegalArgumentException); |
| 38 }; | 36 }; |
| 39 file.exists((bool) { | 37 file.exists((bool) { |
| 40 Expect.fail('non-string name exists'); | 38 Expect.fail('non-string name exists'); |
| 41 }); | 39 }); |
| 42 } | 40 } |
| 43 | 41 |
| 44 static void testCreateInvalidArgs(name) { | 42 static void testCreateInvalidArgs(name) { |
| 45 var file = new File(name); | 43 var file = new File(name); |
| 46 try { | 44 try { |
| 47 file.createSync(); | 45 file.createSync(); |
| 48 Expect.fail('exception expected'); | 46 Expect.fail('exception expected'); |
| 49 } catch (var e) { | 47 } catch (var e) { |
| 50 Expect.isTrue(e is FileIOException); | 48 Expect.isTrue(e is IllegalArgumentException); |
| 51 Expect.isTrue(e.toString().contains('Cannot create file')); | |
| 52 } | 49 } |
| 53 | 50 |
| 54 file.onError = (s) { | 51 file.onError = (e) => Expect.isTrue(e is IllegalArgumentException); |
| 55 Expect.isTrue(s.contains('Cannot create file')); | 52 file.create(() => Expect.fail('non-string name exists')); |
| 56 }; | |
| 57 file.create((created) { | |
| 58 Expect.fail('non-string name exists'); | |
| 59 }); | |
| 60 } | 53 } |
| 61 | 54 |
| 62 static void testReadListInvalidArgs(buffer, offset, length) { | 55 static void testReadListInvalidArgs(buffer, offset, length) { |
| 63 String filename = getFilename("tests/vm/data/fixed_length_file"); | 56 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 64 var file = (new File(filename)).openSync(); | 57 var file = (new File(filename)).openSync(); |
| 65 try { | 58 try { |
| 66 file.readListSync(buffer, offset, length); | 59 file.readListSync(buffer, offset, length); |
| 67 Expect.fail('exception expected'); | 60 Expect.fail('exception expected'); |
| 68 } catch (var e) { | 61 } catch (var e) { |
| 69 Expect.isTrue(e is FileIOException); | 62 Expect.isTrue(e is FileIOException); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 }; | 155 }; |
| 163 file.close(); | 156 file.close(); |
| 164 } | 157 } |
| 165 | 158 |
| 166 static void testFullPathInvalidArgs(name) { | 159 static void testFullPathInvalidArgs(name) { |
| 167 var file = new File(name); | 160 var file = new File(name); |
| 168 try { | 161 try { |
| 169 file.fullPathSync(); | 162 file.fullPathSync(); |
| 170 Expect.fail('exception expected'); | 163 Expect.fail('exception expected'); |
| 171 } catch (var e) { | 164 } catch (var e) { |
| 172 Expect.isTrue(e is FileIOException); | 165 Expect.isTrue(e is IllegalArgumentException); |
| 173 Expect.isTrue(e.toString().contains('fullPath failed')); | |
| 174 } | 166 } |
| 175 | 167 |
| 176 file.onError = (s) { | 168 file.onError = (e) { |
| 177 Expect.isTrue(s.contains('fullPath failed')); | 169 Expect.isTrue(e is IllegalArgumentException); |
| 178 }; | 170 }; |
| 179 file.fullPath((path) { | 171 file.fullPath((path) { |
| 180 Expect.fail('full path invalid argument'); | 172 Expect.fail('full path invalid argument'); |
| 181 }); | 173 }); |
| 182 } | 174 } |
| 183 | 175 |
| 184 static String getFilename(String path) => | 176 static String getFilename(String path) => |
| 185 new File(path).existsSync() ? path : 'runtime/' + path; | 177 new File(path).existsSync() ? path : 'runtime/' + path; |
| 186 } | 178 } |
| 187 | 179 |
| 188 main() { | 180 main() { |
| 189 FileTest.testOpenInvalidArgs(0); | 181 FileTest.testOpenInvalidArgs(0); |
| 190 FileTest.testOpenInvalidArgs('name', 0); | |
| 191 FileTest.testExistsInvalidArgs(0); | 182 FileTest.testExistsInvalidArgs(0); |
| 192 FileTest.testCreateInvalidArgs(0); | 183 FileTest.testCreateInvalidArgs(0); |
| 193 FileTest.testReadListInvalidArgs(12, 0, 1); | 184 FileTest.testReadListInvalidArgs(12, 0, 1); |
| 194 FileTest.testReadListInvalidArgs(new List(10), '0', 1); | 185 FileTest.testReadListInvalidArgs(new List(10), '0', 1); |
| 195 FileTest.testReadListInvalidArgs(new List(10), 0, '1'); | 186 FileTest.testReadListInvalidArgs(new List(10), 0, '1'); |
| 196 FileTest.testWriteByteInvalidArgs('asdf'); | 187 FileTest.testWriteByteInvalidArgs('asdf'); |
| 197 FileTest.testWriteListInvalidArgs(12, 0, 1); | 188 FileTest.testWriteListInvalidArgs(12, 0, 1); |
| 198 FileTest.testWriteListInvalidArgs(new List(10), '0', 1); | 189 FileTest.testWriteListInvalidArgs(new List(10), '0', 1); |
| 199 FileTest.testWriteListInvalidArgs(new List(10), 0, '1'); | 190 FileTest.testWriteListInvalidArgs(new List(10), 0, '1'); |
| 200 FileTest.testFullPathInvalidArgs(12); | 191 FileTest.testFullPathInvalidArgs(12); |
| 201 } | 192 } |
| OLD | NEW |