Chromium Code Reviews| Index: tests/standalone/io/file_invalid_arguments_test.dart |
| diff --git a/tests/standalone/io/file_invalid_arguments_test.dart b/tests/standalone/io/file_invalid_arguments_test.dart |
| index f8196e6d4d46e284585aff05b99392a062141374..7a73f1506fb0829a7874da5a9e4c8769f8ec00e7 100644 |
| --- a/tests/standalone/io/file_invalid_arguments_test.dart |
| +++ b/tests/standalone/io/file_invalid_arguments_test.dart |
| @@ -3,113 +3,141 @@ |
| // BSD-style license that can be found in the LICENSE file. |
| import "dart:io"; |
| +import "dart:isolate"; |
| -class FileTest { |
| - static void testReadListInvalidArgs(buffer, offset, length) { |
| - String filename = getFilename("tests/vm/data/fixed_length_file"); |
| - var file = (new File(filename)).openSync(); |
| - try { |
| - file.readListSync(buffer, offset, length); |
| - Expect.fail('exception expected'); |
| - } catch (e) { |
| - Expect.isTrue(e is FileIOException); |
| - Expect.isTrue(e.toString().contains('Invalid arguments')); |
| - } |
| +void testReadInvalidArgs(arg) { |
| + var port = new ReceivePort(); |
| + String filename = getFilename("tests/vm/data/fixed_length_file"); |
| + var file = (new File(filename)).openSync(); |
| + try { |
| + file.readSync(arg); |
| + Expect.fail('exception expected'); |
| + } catch (e) { |
| + Expect.isTrue(e is FileIOException); |
| + Expect.isTrue(e.toString().contains('Invalid arguments')); |
| + } |
| - var errors = 0; |
| - var readListFuture = file.readList(buffer, offset, length); |
| - readListFuture.then((bytes) { |
| - Expect.fail('read list invalid arguments'); |
| - }).catchError((e) { |
| - errors++; |
| - Expect.isTrue(e.error is FileIOException); |
| - Expect.isTrue(e.error.toString().contains('Invalid arguments')); |
| - file.close().then((ignore) { |
| - Expect.equals(1, errors); |
| - }); |
| + var errors = 0; |
| + var readFuture = file.read(arg); |
| + readFuture.then((bytes) { |
| + Expect.fail('read list invalid arguments'); |
|
floitsch
2013/01/09 09:12:59
replace string with "Exception expected".
The e.er
Mads Ager (google)
2013/01/09 09:29:14
Done.
|
| + }).catchError((e) { |
| + errors++; |
| + Expect.isTrue(e.error is FileIOException); |
|
floitsch
2013/01/09 09:12:59
Alternatively you could use "test: (error) => erro
Mads Ager (google)
2013/01/09 09:29:14
I find this more readable since I want to check mo
|
| + Expect.isTrue(e.error.toString().contains('Invalid arguments')); |
| + file.close().then((ignore) { |
| + Expect.equals(1, errors); |
| + port.close(); |
| }); |
| - } |
| + }); |
| +} |
| - static void testWriteByteInvalidArgs(value) { |
| - String filename = getFilename("tests/vm/data/fixed_length_file"); |
| - var file = (new File(filename.concat("_out"))).openSync(FileMode.WRITE); |
| - try { |
| - file.writeByteSync(value); |
| - Expect.fail('exception expected'); |
| - } catch (e) { |
| - Expect.isTrue(e is FileIOException); |
| - Expect.isTrue(e.toString().contains('Invalid argument')); |
| - } |
| +void testReadListInvalidArgs(buffer, offset, length) { |
| + String filename = getFilename("tests/vm/data/fixed_length_file"); |
| + var file = (new File(filename)).openSync(); |
| + try { |
| + file.readListSync(buffer, offset, length); |
| + Expect.fail('exception expected'); |
| + } catch (e) { |
| + Expect.isTrue(e is FileIOException); |
| + Expect.isTrue(e.toString().contains('Invalid arguments')); |
| + } |
| - var writeByteFuture = file.writeByte(value); |
| - writeByteFuture.then((ignore) { |
| - Expect.fail('write byte invalid argument'); |
| - }).catchError((s) { |
| - Expect.isTrue(s.error is FileIOException); |
| - Expect.isTrue(s.error.toString().contains('Invalid argument')); |
| - file.close(); |
| + var errors = 0; |
| + var readListFuture = file.readList(buffer, offset, length); |
| + readListFuture.then((bytes) { |
| + Expect.fail('read list invalid arguments'); |
| + }).catchError((e) { |
| + errors++; |
| + Expect.isTrue(e.error is FileIOException); |
| + Expect.isTrue(e.error.toString().contains('Invalid arguments')); |
| + file.close().then((ignore) { |
| + Expect.equals(1, errors); |
|
floitsch
2013/01/09 09:12:59
add a receive-port to make sure the test is run.
Mads Ager (google)
2013/01/09 09:29:14
Done.
|
| }); |
| + }); |
| +} |
| + |
| +void testWriteByteInvalidArgs(value) { |
| + String filename = getFilename("tests/vm/data/fixed_length_file"); |
| + var file = (new File(filename.concat("_out"))).openSync(FileMode.WRITE); |
| + try { |
| + file.writeByteSync(value); |
| + Expect.fail('exception expected'); |
| + } catch (e) { |
| + Expect.isTrue(e is FileIOException); |
| + Expect.isTrue(e.toString().contains('Invalid argument')); |
| } |
| - static void testWriteListInvalidArgs(buffer, offset, bytes) { |
| - String filename = getFilename("tests/vm/data/fixed_length_file"); |
| - var file = (new File(filename.concat("_out"))).openSync(FileMode.WRITE); |
| - try { |
| - file.writeListSync(buffer, offset, bytes); |
| - Expect.fail('exception expected'); |
| - } catch (e) { |
| - Expect.isTrue(e is FileIOException); |
| - Expect.isTrue(e.toString().contains('Invalid arguments')); |
| - } |
| + var writeByteFuture = file.writeByte(value); |
| + writeByteFuture.then((ignore) { |
| + Expect.fail('write byte invalid argument'); |
|
floitsch
2013/01/09 09:12:59
ditto (change exception string).
Mads Ager (google)
2013/01/09 09:29:14
Done.
|
| + }).catchError((s) { |
| + Expect.isTrue(s.error is FileIOException); |
| + Expect.isTrue(s.error.toString().contains('Invalid argument')); |
| + file.close(); |
|
floitsch
2013/01/09 09:12:59
ditto (receive-port).
Mads Ager (google)
2013/01/09 09:29:14
Done.
|
| + }); |
| +} |
| - var writeListFuture = file.writeList(buffer, offset, bytes); |
| - writeListFuture.then((ignore) { |
| - Expect.fail('write list invalid argument'); |
| - }).catchError((s) { |
| - Expect.isTrue(s.error is FileIOException); |
| - Expect.isTrue(s.error.toString().contains('Invalid arguments')); |
| - file.close(); |
| - }); |
| +void testWriteListInvalidArgs(buffer, offset, bytes) { |
| + String filename = getFilename("tests/vm/data/fixed_length_file"); |
| + var file = (new File(filename.concat("_out"))).openSync(FileMode.WRITE); |
| + try { |
| + file.writeListSync(buffer, offset, bytes); |
| + Expect.fail('exception expected'); |
| + } catch (e) { |
| + Expect.isTrue(e is FileIOException); |
| + Expect.isTrue(e.toString().contains('Invalid arguments')); |
| } |
| - static void testWriteStringInvalidArgs(string) { |
| - String filename = getFilename("tests/vm/data/fixed_length_file"); |
| - var file = new File(filename.concat("_out")); |
| - file.openSync(FileMode.WRITE); |
| - try { |
| - file.writeString(string); |
| - Expect.fail('exception expected'); |
| - } catch (e) { |
| - Expect.isTrue(e is FileIOException); |
| - Expect.isTrue(e.toString().contains('writeString failed')); |
| - } |
| + var writeListFuture = file.writeList(buffer, offset, bytes); |
| + writeListFuture.then((ignore) { |
| + Expect.fail('write list invalid argument'); |
|
floitsch
2013/01/09 09:12:59
ditto (change exception string).
Mads Ager (google)
2013/01/09 09:29:14
Done.
|
| + }).catchError((s) { |
| + Expect.isTrue(s.error is FileIOException); |
| + Expect.isTrue(s.error.toString().contains('Invalid arguments')); |
| + file.close(); |
|
floitsch
2013/01/09 09:12:59
ditto (receive-port).
Mads Ager (google)
2013/01/09 09:29:14
Done.
|
| + }); |
| +} |
| - var errors = 0; |
| - file.onError = (s) { |
| - errors++; |
| - Expect.isTrue(s.contains('writeString failed')); |
| - }; |
| - var calls = 0; |
| - file.onNoPendingWrites = () { |
| - if (++calls > 1) Expect.fail('write list invalid argument'); |
| - }; |
| +void testWriteStringInvalidArgs(string) { |
| + String filename = getFilename("tests/vm/data/fixed_length_file"); |
| + var file = new File(filename.concat("_out")); |
| + file.openSync(FileMode.WRITE); |
| + try { |
| file.writeString(string); |
| - file.onClosed = () { |
| - Expect.equals(1, errors); |
| - }; |
| - file.close(); |
| + Expect.fail('exception expected'); |
| + } catch (e) { |
| + Expect.isTrue(e is FileIOException); |
| + Expect.isTrue(e.toString().contains('writeString failed')); |
| } |
| - static String getFilename(String path) => |
| - new File(path).existsSync() ? path : 'runtime/$path'; |
| + var errors = 0; |
| + file.onError = (s) { |
| + errors++; |
| + Expect.isTrue(s.contains('writeString failed')); |
| + }; |
| + var calls = 0; |
| + file.onNoPendingWrites = () { |
| + if (++calls > 1) Expect.fail('write list invalid argument'); |
| + }; |
| + file.writeString(string); |
| + file.onClosed = () { |
| + Expect.equals(1, errors); |
|
Mads Ager (google)
2013/01/09 09:29:14
Added port to this test as well and closed it here
|
| + }; |
| + file.close(); |
| +} |
| + |
| +String getFilename(String path) { |
| + return new File(path).existsSync() ? path : 'runtime/$path'; |
| } |
| main() { |
| - FileTest.testReadListInvalidArgs(12, 0, 1); |
| - FileTest.testReadListInvalidArgs(new List.fixedLength(10), '0', 1); |
| - FileTest.testReadListInvalidArgs(new List.fixedLength(10), 0, '1'); |
| - FileTest.testWriteByteInvalidArgs('asdf'); |
| - FileTest.testWriteListInvalidArgs(12, 0, 1); |
| - FileTest.testWriteListInvalidArgs(new List.fixedLength(10), '0', 1); |
| - FileTest.testWriteListInvalidArgs(new List.fixedLength(10), 0, '1'); |
| + testReadInvalidArgs('asdf'); |
| + testReadListInvalidArgs(12, 0, 1); |
| + testReadListInvalidArgs(new List.fixedLength(10), '0', 1); |
| + testReadListInvalidArgs(new List.fixedLength(10), 0, '1'); |
| + testWriteByteInvalidArgs('asdf'); |
| + testWriteListInvalidArgs(12, 0, 1); |
| + testWriteListInvalidArgs(new List.fixedLength(10), '0', 1); |
| + testWriteListInvalidArgs(new List.fixedLength(10), 0, '1'); |
| } |