| 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) { | 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 (e) { | 13 } catch (e) { |
| 14 Expect.isTrue(e is IllegalArgumentException); | 14 Expect.isTrue(e is ArgumentError); |
| 15 } | 15 } |
| 16 | 16 |
| 17 var openFuture = file.open(FileMode.READ); | 17 var openFuture = file.open(FileMode.READ); |
| 18 openFuture.handleException((e) { | 18 openFuture.handleException((e) { |
| 19 Expect.isTrue(e is IllegalArgumentException); | 19 Expect.isTrue(e is ArgumentError); |
| 20 return true; | 20 return true; |
| 21 }); | 21 }); |
| 22 openFuture.then((opened) { | 22 openFuture.then((opened) { |
| 23 Expect.fail('non-string name open'); | 23 Expect.fail('non-string name open'); |
| 24 }); | 24 }); |
| 25 } | 25 } |
| 26 | 26 |
| 27 static void testExistsInvalidArgs(name) { | 27 static void testExistsInvalidArgs(name) { |
| 28 var file = new File(name); | 28 var file = new File(name); |
| 29 try { | 29 try { |
| 30 file.existsSync(); | 30 file.existsSync(); |
| 31 Expect.fail('exception expected'); | 31 Expect.fail('exception expected'); |
| 32 } catch (e) { | 32 } catch (e) { |
| 33 Expect.isTrue(e is IllegalArgumentException); | 33 Expect.isTrue(e is ArgumentError); |
| 34 } | 34 } |
| 35 | 35 |
| 36 var existsFuture = file.exists(); | 36 var existsFuture = file.exists(); |
| 37 existsFuture.handleException((e) { | 37 existsFuture.handleException((e) { |
| 38 Expect.isTrue(e is IllegalArgumentException); | 38 Expect.isTrue(e is ArgumentError); |
| 39 return true; | 39 return true; |
| 40 }); | 40 }); |
| 41 existsFuture.then((bool) { | 41 existsFuture.then((bool) { |
| 42 Expect.fail('non-string name exists'); | 42 Expect.fail('non-string name exists'); |
| 43 }); | 43 }); |
| 44 } | 44 } |
| 45 | 45 |
| 46 static void testCreateInvalidArgs(name) { | 46 static void testCreateInvalidArgs(name) { |
| 47 var file = new File(name); | 47 var file = new File(name); |
| 48 try { | 48 try { |
| 49 file.createSync(); | 49 file.createSync(); |
| 50 Expect.fail('exception expected'); | 50 Expect.fail('exception expected'); |
| 51 } catch (e) { | 51 } catch (e) { |
| 52 Expect.isTrue(e is IllegalArgumentException); | 52 Expect.isTrue(e is ArgumentError); |
| 53 } | 53 } |
| 54 | 54 |
| 55 var createFuture = file.create(); | 55 var createFuture = file.create(); |
| 56 createFuture.handleException((e) { | 56 createFuture.handleException((e) { |
| 57 Expect.isTrue(e is IllegalArgumentException); | 57 Expect.isTrue(e is ArgumentError); |
| 58 return true; | 58 return true; |
| 59 }); | 59 }); |
| 60 createFuture.then((ignore) => Expect.fail('non-string name exists')); | 60 createFuture.then((ignore) => Expect.fail('non-string name exists')); |
| 61 } | 61 } |
| 62 | 62 |
| 63 static void testReadListInvalidArgs(buffer, offset, length) { | 63 static void testReadListInvalidArgs(buffer, offset, length) { |
| 64 String filename = getFilename("tests/vm/data/fixed_length_file"); | 64 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 65 var file = (new File(filename)).openSync(); | 65 var file = (new File(filename)).openSync(); |
| 66 try { | 66 try { |
| 67 file.readListSync(buffer, offset, length); | 67 file.readListSync(buffer, offset, length); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 }; | 160 }; |
| 161 file.close(); | 161 file.close(); |
| 162 } | 162 } |
| 163 | 163 |
| 164 static void testFullPathInvalidArgs(name) { | 164 static void testFullPathInvalidArgs(name) { |
| 165 var file = new File(name); | 165 var file = new File(name); |
| 166 try { | 166 try { |
| 167 file.fullPathSync(); | 167 file.fullPathSync(); |
| 168 Expect.fail('exception expected'); | 168 Expect.fail('exception expected'); |
| 169 } catch (e) { | 169 } catch (e) { |
| 170 Expect.isTrue(e is IllegalArgumentException); | 170 Expect.isTrue(e is ArgumentError); |
| 171 } | 171 } |
| 172 | 172 |
| 173 var fullPathFuture = file.fullPath(); | 173 var fullPathFuture = file.fullPath(); |
| 174 fullPathFuture.handleException((e) { | 174 fullPathFuture.handleException((e) { |
| 175 Expect.isTrue(e is IllegalArgumentException); | 175 Expect.isTrue(e is ArgumentError); |
| 176 return true; | 176 return true; |
| 177 }); | 177 }); |
| 178 fullPathFuture.then((path) { | 178 fullPathFuture.then((path) { |
| 179 Expect.fail('full path invalid argument'); | 179 Expect.fail('full path invalid argument'); |
| 180 }); | 180 }); |
| 181 } | 181 } |
| 182 | 182 |
| 183 static String getFilename(String path) => | 183 static String getFilename(String path) => |
| 184 new File(path).existsSync() ? path : 'runtime/$path'; | 184 new File(path).existsSync() ? path : 'runtime/$path'; |
| 185 } | 185 } |
| 186 | 186 |
| 187 main() { | 187 main() { |
| 188 FileTest.testOpenInvalidArgs(0); | 188 FileTest.testOpenInvalidArgs(0); |
| 189 FileTest.testExistsInvalidArgs(0); | 189 FileTest.testExistsInvalidArgs(0); |
| 190 FileTest.testCreateInvalidArgs(0); | 190 FileTest.testCreateInvalidArgs(0); |
| 191 FileTest.testReadListInvalidArgs(12, 0, 1); | 191 FileTest.testReadListInvalidArgs(12, 0, 1); |
| 192 FileTest.testReadListInvalidArgs(new List(10), '0', 1); | 192 FileTest.testReadListInvalidArgs(new List(10), '0', 1); |
| 193 FileTest.testReadListInvalidArgs(new List(10), 0, '1'); | 193 FileTest.testReadListInvalidArgs(new List(10), 0, '1'); |
| 194 FileTest.testWriteByteInvalidArgs('asdf'); | 194 FileTest.testWriteByteInvalidArgs('asdf'); |
| 195 FileTest.testWriteListInvalidArgs(12, 0, 1); | 195 FileTest.testWriteListInvalidArgs(12, 0, 1); |
| 196 FileTest.testWriteListInvalidArgs(new List(10), '0', 1); | 196 FileTest.testWriteListInvalidArgs(new List(10), '0', 1); |
| 197 FileTest.testWriteListInvalidArgs(new List(10), 0, '1'); | 197 FileTest.testWriteListInvalidArgs(new List(10), 0, '1'); |
| 198 FileTest.testFullPathInvalidArgs(12); | 198 FileTest.testFullPathInvalidArgs(12); |
| 199 } | 199 } |
| OLD | NEW |