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