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 { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 }); | 82 }); |
83 return true; | 83 return true; |
84 }); | 84 }); |
85 readListFuture.then((bytes) { | 85 readListFuture.then((bytes) { |
86 Expect.fail('read list invalid arguments'); | 86 Expect.fail('read list invalid arguments'); |
87 }); | 87 }); |
88 } | 88 } |
89 | 89 |
90 static void testWriteByteInvalidArgs(value) { | 90 static void testWriteByteInvalidArgs(value) { |
91 String filename = getFilename("tests/vm/data/fixed_length_file"); | 91 String filename = getFilename("tests/vm/data/fixed_length_file"); |
92 var file = (new File(filename + "_out")).openSync(FileMode.WRITE); | 92 var file = (new File(filename.concat("_out"))).openSync(FileMode.WRITE); |
siva
2012/05/18 19:56:10
Why do you use concat here and not:
new File("${fi
hausner
2012/05/18 21:03:46
No particular reason, it just seemed more readable
| |
93 try { | 93 try { |
94 file.writeByteSync(value); | 94 file.writeByteSync(value); |
95 Expect.fail('exception expected'); | 95 Expect.fail('exception expected'); |
96 } catch (var e) { | 96 } catch (var e) { |
97 Expect.isTrue(e is FileIOException); | 97 Expect.isTrue(e is FileIOException); |
98 Expect.isTrue(e.toString().contains('Invalid argument')); | 98 Expect.isTrue(e.toString().contains('Invalid argument')); |
99 } | 99 } |
100 | 100 |
101 var writeByteFuture = file.writeByte(value); | 101 var writeByteFuture = file.writeByte(value); |
102 writeByteFuture.then((ignore) { | 102 writeByteFuture.then((ignore) { |
103 Expect.fail('write byte invalid argument'); | 103 Expect.fail('write byte invalid argument'); |
104 }); | 104 }); |
105 writeByteFuture.handleException((s) { | 105 writeByteFuture.handleException((s) { |
106 Expect.isTrue(s is FileIOException); | 106 Expect.isTrue(s is FileIOException); |
107 Expect.isTrue(s.toString().contains('Invalid argument')); | 107 Expect.isTrue(s.toString().contains('Invalid argument')); |
108 file.close(); | 108 file.close(); |
109 return true; | 109 return true; |
110 }); | 110 }); |
111 } | 111 } |
112 | 112 |
113 static void testWriteListInvalidArgs(buffer, offset, bytes) { | 113 static void testWriteListInvalidArgs(buffer, offset, bytes) { |
114 String filename = getFilename("tests/vm/data/fixed_length_file"); | 114 String filename = getFilename("tests/vm/data/fixed_length_file"); |
115 var file = (new File(filename + "_out")).openSync(FileMode.WRITE); | 115 var file = (new File(filename.concat("_out"))).openSync(FileMode.WRITE); |
116 try { | 116 try { |
117 file.writeListSync(buffer, offset, bytes); | 117 file.writeListSync(buffer, offset, bytes); |
118 Expect.fail('exception expected'); | 118 Expect.fail('exception expected'); |
119 } catch (var e) { | 119 } catch (var e) { |
120 Expect.isTrue(e is FileIOException); | 120 Expect.isTrue(e is FileIOException); |
121 Expect.isTrue(e.toString().contains('Invalid arguments')); | 121 Expect.isTrue(e.toString().contains('Invalid arguments')); |
122 } | 122 } |
123 | 123 |
124 var writeListFuture = file.writeList(buffer, offset, bytes); | 124 var writeListFuture = file.writeList(buffer, offset, bytes); |
125 writeListFuture.then((ignore) { | 125 writeListFuture.then((ignore) { |
126 Expect.fail('write list invalid argument'); | 126 Expect.fail('write list invalid argument'); |
127 }); | 127 }); |
128 writeListFuture.handleException((s) { | 128 writeListFuture.handleException((s) { |
129 Expect.isTrue(s is FileIOException); | 129 Expect.isTrue(s is FileIOException); |
130 Expect.isTrue(s.toString().contains('Invalid arguments')); | 130 Expect.isTrue(s.toString().contains('Invalid arguments')); |
131 file.close(); | 131 file.close(); |
132 return true; | 132 return true; |
133 }); | 133 }); |
134 } | 134 } |
135 | 135 |
136 static void testWriteStringInvalidArgs(string) { | 136 static void testWriteStringInvalidArgs(string) { |
137 String filename = getFilename("tests/vm/data/fixed_length_file"); | 137 String filename = getFilename("tests/vm/data/fixed_length_file"); |
138 var file = new File(filename + "_out"); | 138 var file = new File(filename.concat("_out")); |
139 file.openSync(FileMode.WRITE); | 139 file.openSync(FileMode.WRITE); |
140 try { | 140 try { |
141 file.writeString(string); | 141 file.writeString(string); |
142 Expect.fail('exception expected'); | 142 Expect.fail('exception expected'); |
143 } catch (var e) { | 143 } catch (var e) { |
144 Expect.isTrue(e is FileIOException); | 144 Expect.isTrue(e is FileIOException); |
145 Expect.isTrue(e.toString().contains('writeString failed')); | 145 Expect.isTrue(e.toString().contains('writeString failed')); |
146 } | 146 } |
147 | 147 |
148 var errors = 0; | 148 var errors = 0; |
(...skipping 25 matching lines...) Expand all Loading... | |
174 fullPathFuture.handleException((e) { | 174 fullPathFuture.handleException((e) { |
175 Expect.isTrue(e is IllegalArgumentException); | 175 Expect.isTrue(e is IllegalArgumentException); |
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 |