Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, 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:io"; | 5 import "dart:io"; |
| 6 import "dart:isolate"; | 6 import "dart:isolate"; |
| 7 | 7 |
| 8 void testReadInvalidArgs(arg) { | 8 void testReadInvalidArgs(arg) { |
| 9 var port = new ReceivePort(); | 9 var port = new ReceivePort(); |
| 10 String filename = getFilename("tests/vm/data/fixed_length_file"); | 10 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 11 var file = (new File(filename)).openSync(); | 11 var file = (new File(filename)).openSync(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 file.close().then((ignore) { | 55 file.close().then((ignore) { |
| 56 Expect.equals(1, errors); | 56 Expect.equals(1, errors); |
| 57 port.close(); | 57 port.close(); |
| 58 }); | 58 }); |
| 59 }); | 59 }); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void testWriteByteInvalidArgs(value) { | 62 void testWriteByteInvalidArgs(value) { |
| 63 var port = new ReceivePort(); | 63 var port = new ReceivePort(); |
| 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}_out")).openSync(FileMode.WRITE); | 65 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); |
| 66 try { | 66 try { |
| 67 file.writeByteSync(value); | 67 file.writeByteSync(value); |
| 68 Expect.fail('exception expected'); | 68 Expect.fail('exception expected'); |
| 69 } catch (e) { | 69 } catch (e) { |
| 70 Expect.isTrue(e is FileIOException); | 70 Expect.isTrue(e is FileIOException); |
| 71 Expect.isTrue(e.toString().contains('Invalid argument')); | 71 Expect.isTrue(e.toString().contains('Invalid argument')); |
| 72 } | 72 } |
| 73 | 73 |
| 74 var writeByteFuture = file.writeByte(value); | 74 var writeByteFuture = file.writeByte(value); |
| 75 writeByteFuture.then((ignore) { | 75 writeByteFuture.then((ignore) { |
| 76 Expect.fail('exception expected'); | 76 Expect.fail('exception expected'); |
| 77 }).catchError((s) { | 77 }).catchError((s) { |
| 78 Expect.isTrue(s.error is FileIOException); | 78 Expect.isTrue(s.error is FileIOException); |
| 79 Expect.isTrue(s.error.toString().contains('Invalid argument')); | 79 Expect.isTrue(s.error.toString().contains('Invalid argument')); |
| 80 file.close().then((ignore) { | 80 file.close().then((ignore) { |
| 81 port.close(); | 81 port.close(); |
| 82 }); | 82 }); |
| 83 }); | 83 }); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void testWriteListInvalidArgs(buffer, offset, bytes) { | 86 void testWriteListInvalidArgs(buffer, offset, bytes) { |
| 87 var port = new ReceivePort(); | 87 var port = new ReceivePort(); |
| 88 String filename = getFilename("tests/vm/data/fixed_length_file"); | 88 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 89 var file = (new File("${filename}_out")).openSync(FileMode.WRITE); | 89 var file = (new File("${filename}_out")).openSync(mode: FileMode.WRITE); |
| 90 try { | 90 try { |
| 91 file.writeListSync(buffer, offset, bytes); | 91 file.writeListSync(buffer, offset, bytes); |
| 92 Expect.fail('exception expected'); | 92 Expect.fail('exception expected'); |
| 93 } catch (e) { | 93 } catch (e) { |
| 94 Expect.isTrue(e is FileIOException); | 94 Expect.isTrue(e is FileIOException); |
| 95 Expect.isTrue(e.toString().contains('Invalid arguments')); | 95 Expect.isTrue(e.toString().contains('Invalid arguments')); |
| 96 } | 96 } |
| 97 | 97 |
| 98 var writeListFuture = file.writeList(buffer, offset, bytes); | 98 var writeListFuture = file.writeList(buffer, offset, bytes); |
| 99 writeListFuture.then((ignore) { | 99 writeListFuture.then((ignore) { |
| 100 Expect.fail('exception expected'); | 100 Expect.fail('exception expected'); |
| 101 }).catchError((s) { | 101 }).catchError((s) { |
| 102 Expect.isTrue(s.error is FileIOException); | 102 Expect.isTrue(s.error is FileIOException); |
| 103 Expect.isTrue(s.error.toString().contains('Invalid arguments')); | 103 Expect.isTrue(s.error.toString().contains('Invalid arguments')); |
| 104 file.close().then((ignore) { | 104 file.close().then((ignore) { |
| 105 port.close(); | 105 port.close(); |
| 106 }); | 106 }); |
| 107 }); | 107 }); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void testWriteStringInvalidArgs(string) { | 110 void testWriteStringInvalidArgs(string) { |
| 111 var port = new ReceivePort(); | 111 var port = new ReceivePort(); |
| 112 String filename = getFilename("tests/vm/data/fixed_length_file"); | 112 String filename = getFilename("tests/vm/data/fixed_length_file"); |
| 113 var file = new File("${filename}_out"); | 113 var file = new File("${filename}_out"); |
| 114 file.openSync(FileMode.WRITE); | 114 file.openSync(node: FileMode.WRITE); |
|
Mads Ager (google)
2013/03/13 16:08:45
mode!
| |
| 115 try { | 115 try { |
| 116 file.writeString(string); | 116 file.writeString(string); |
| 117 Expect.fail('exception expected'); | 117 Expect.fail('exception expected'); |
| 118 } catch (e) { | 118 } catch (e) { |
| 119 Expect.isTrue(e is FileIOException); | 119 Expect.isTrue(e is FileIOException); |
| 120 Expect.isTrue(e.toString().contains('writeString failed')); | 120 Expect.isTrue(e.toString().contains('writeString failed')); |
| 121 } | 121 } |
| 122 | 122 |
| 123 var errors = 0; | 123 var errors = 0; |
| 124 file.onError = (s) { | 124 file.onError = (s) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 144 main() { | 144 main() { |
| 145 testReadInvalidArgs('asdf'); | 145 testReadInvalidArgs('asdf'); |
| 146 testReadListInvalidArgs(12, 0, 1); | 146 testReadListInvalidArgs(12, 0, 1); |
| 147 testReadListInvalidArgs(new List(10), '0', 1); | 147 testReadListInvalidArgs(new List(10), '0', 1); |
| 148 testReadListInvalidArgs(new List(10), 0, '1'); | 148 testReadListInvalidArgs(new List(10), 0, '1'); |
| 149 testWriteByteInvalidArgs('asdf'); | 149 testWriteByteInvalidArgs('asdf'); |
| 150 testWriteListInvalidArgs(12, 0, 1); | 150 testWriteListInvalidArgs(12, 0, 1); |
| 151 testWriteListInvalidArgs(new List(10), '0', 1); | 151 testWriteListInvalidArgs(new List(10), '0', 1); |
| 152 testWriteListInvalidArgs(new List(10), 0, '1'); | 152 testWriteListInvalidArgs(new List(10), 0, '1'); |
| 153 } | 153 } |
| OLD | NEW |