Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: tests/standalone/io/file_invalid_arguments_test.dart

Issue 11827017: Update remaining usages of Completer.completeException. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/lib/async/future_test.dart ('k') | tools/dom/src/Measurement.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import "dart:isolate";
6 7
7 class FileTest { 8 void testReadInvalidArgs(arg) {
8 static void testReadListInvalidArgs(buffer, offset, length) { 9 var port = new ReceivePort();
9 String filename = getFilename("tests/vm/data/fixed_length_file"); 10 String filename = getFilename("tests/vm/data/fixed_length_file");
10 var file = (new File(filename)).openSync(); 11 var file = (new File(filename)).openSync();
11 try { 12 try {
12 file.readListSync(buffer, offset, length); 13 file.readSync(arg);
13 Expect.fail('exception expected'); 14 Expect.fail('exception expected');
14 } catch (e) { 15 } catch (e) {
15 Expect.isTrue(e is FileIOException); 16 Expect.isTrue(e is FileIOException);
16 Expect.isTrue(e.toString().contains('Invalid arguments')); 17 Expect.isTrue(e.toString().contains('Invalid arguments'));
17 }
18
19 var errors = 0;
20 var readListFuture = file.readList(buffer, offset, length);
21 readListFuture.then((bytes) {
22 Expect.fail('read list invalid arguments');
23 }).catchError((e) {
24 errors++;
25 Expect.isTrue(e.error is FileIOException);
26 Expect.isTrue(e.error.toString().contains('Invalid arguments'));
27 file.close().then((ignore) {
28 Expect.equals(1, errors);
29 });
30 });
31 } 18 }
32 19
33 static void testWriteByteInvalidArgs(value) { 20 var errors = 0;
34 String filename = getFilename("tests/vm/data/fixed_length_file"); 21 var readFuture = file.read(arg);
35 var file = (new File(filename.concat("_out"))).openSync(FileMode.WRITE); 22 readFuture.then((bytes) {
36 try { 23 Expect.fail('exception expected');
37 file.writeByteSync(value); 24 }).catchError((e) {
38 Expect.fail('exception expected'); 25 errors++;
39 } catch (e) { 26 Expect.isTrue(e.error is FileIOException);
40 Expect.isTrue(e is FileIOException); 27 Expect.isTrue(e.error.toString().contains('Invalid arguments'));
41 Expect.isTrue(e.toString().contains('Invalid argument')); 28 file.close().then((ignore) {
42 } 29 Expect.equals(1, errors);
30 port.close();
31 });
32 });
33 }
43 34
44 var writeByteFuture = file.writeByte(value); 35 void testReadListInvalidArgs(buffer, offset, length) {
45 writeByteFuture.then((ignore) { 36 var port = new ReceivePort();
46 Expect.fail('write byte invalid argument'); 37 String filename = getFilename("tests/vm/data/fixed_length_file");
47 }).catchError((s) { 38 var file = (new File(filename)).openSync();
48 Expect.isTrue(s.error is FileIOException); 39 try {
49 Expect.isTrue(s.error.toString().contains('Invalid argument')); 40 file.readListSync(buffer, offset, length);
50 file.close(); 41 Expect.fail('exception expected');
51 }); 42 } catch (e) {
43 Expect.isTrue(e is FileIOException);
44 Expect.isTrue(e.toString().contains('Invalid arguments'));
52 } 45 }
53 46
54 static void testWriteListInvalidArgs(buffer, offset, bytes) { 47 var errors = 0;
55 String filename = getFilename("tests/vm/data/fixed_length_file"); 48 var readListFuture = file.readList(buffer, offset, length);
56 var file = (new File(filename.concat("_out"))).openSync(FileMode.WRITE); 49 readListFuture.then((bytes) {
57 try { 50 Expect.fail('exception expected');
58 file.writeListSync(buffer, offset, bytes); 51 }).catchError((e) {
59 Expect.fail('exception expected'); 52 errors++;
60 } catch (e) { 53 Expect.isTrue(e.error is FileIOException);
61 Expect.isTrue(e is FileIOException); 54 Expect.isTrue(e.error.toString().contains('Invalid arguments'));
62 Expect.isTrue(e.toString().contains('Invalid arguments')); 55 file.close().then((ignore) {
63 } 56 Expect.equals(1, errors);
57 port.close();
58 });
59 });
60 }
64 61
65 var writeListFuture = file.writeList(buffer, offset, bytes); 62 void testWriteByteInvalidArgs(value) {
66 writeListFuture.then((ignore) { 63 var port = new ReceivePort();
67 Expect.fail('write list invalid argument'); 64 String filename = getFilename("tests/vm/data/fixed_length_file");
68 }).catchError((s) { 65 var file = (new File(filename.concat("_out"))).openSync(FileMode.WRITE);
69 Expect.isTrue(s.error is FileIOException); 66 try {
70 Expect.isTrue(s.error.toString().contains('Invalid arguments')); 67 file.writeByteSync(value);
71 file.close(); 68 Expect.fail('exception expected');
72 }); 69 } catch (e) {
70 Expect.isTrue(e is FileIOException);
71 Expect.isTrue(e.toString().contains('Invalid argument'));
73 } 72 }
74 73
75 static void testWriteStringInvalidArgs(string) { 74 var writeByteFuture = file.writeByte(value);
76 String filename = getFilename("tests/vm/data/fixed_length_file"); 75 writeByteFuture.then((ignore) {
77 var file = new File(filename.concat("_out")); 76 Expect.fail('exception expected');
78 file.openSync(FileMode.WRITE); 77 }).catchError((s) {
79 try { 78 Expect.isTrue(s.error is FileIOException);
80 file.writeString(string); 79 Expect.isTrue(s.error.toString().contains('Invalid argument'));
81 Expect.fail('exception expected'); 80 file.close().then((ignore) {
82 } catch (e) { 81 port.close();
83 Expect.isTrue(e is FileIOException); 82 });
84 Expect.isTrue(e.toString().contains('writeString failed')); 83 });
85 } 84 }
86 85
87 var errors = 0; 86 void testWriteListInvalidArgs(buffer, offset, bytes) {
88 file.onError = (s) { 87 var port = new ReceivePort();
89 errors++; 88 String filename = getFilename("tests/vm/data/fixed_length_file");
90 Expect.isTrue(s.contains('writeString failed')); 89 var file = (new File(filename.concat("_out"))).openSync(FileMode.WRITE);
91 }; 90 try {
92 var calls = 0; 91 file.writeListSync(buffer, offset, bytes);
93 file.onNoPendingWrites = () { 92 Expect.fail('exception expected');
94 if (++calls > 1) Expect.fail('write list invalid argument'); 93 } catch (e) {
95 }; 94 Expect.isTrue(e is FileIOException);
96 file.writeString(string); 95 Expect.isTrue(e.toString().contains('Invalid arguments'));
97 file.onClosed = () {
98 Expect.equals(1, errors);
99 };
100 file.close();
101 } 96 }
102 97
103 static String getFilename(String path) => 98 var writeListFuture = file.writeList(buffer, offset, bytes);
104 new File(path).existsSync() ? path : 'runtime/$path'; 99 writeListFuture.then((ignore) {
100 Expect.fail('exception expected');
101 }).catchError((s) {
102 Expect.isTrue(s.error is FileIOException);
103 Expect.isTrue(s.error.toString().contains('Invalid arguments'));
104 file.close().then((ignore) {
105 port.close();
106 });
107 });
108 }
109
110 void testWriteStringInvalidArgs(string) {
111 var port = new ReceivePort();
112 String filename = getFilename("tests/vm/data/fixed_length_file");
113 var file = new File(filename.concat("_out"));
114 file.openSync(FileMode.WRITE);
115 try {
116 file.writeString(string);
117 Expect.fail('exception expected');
118 } catch (e) {
119 Expect.isTrue(e is FileIOException);
120 Expect.isTrue(e.toString().contains('writeString failed'));
121 }
122
123 var errors = 0;
124 file.onError = (s) {
125 errors++;
126 Expect.isTrue(s.contains('writeString failed'));
127 };
128 var calls = 0;
129 file.onNoPendingWrites = () {
130 if (++calls > 1) Expect.fail('write list invalid argument');
131 };
132 file.writeString(string);
133 file.onClosed = () {
134 Expect.equals(1, errors);
135 port.close();
136 };
137 file.close();
138 }
139
140 String getFilename(String path) {
141 return new File(path).existsSync() ? path : 'runtime/$path';
105 } 142 }
106 143
107 main() { 144 main() {
108 FileTest.testReadListInvalidArgs(12, 0, 1); 145 testReadInvalidArgs('asdf');
109 FileTest.testReadListInvalidArgs(new List.fixedLength(10), '0', 1); 146 testReadListInvalidArgs(12, 0, 1);
110 FileTest.testReadListInvalidArgs(new List.fixedLength(10), 0, '1'); 147 testReadListInvalidArgs(new List.fixedLength(10), '0', 1);
111 FileTest.testWriteByteInvalidArgs('asdf'); 148 testReadListInvalidArgs(new List.fixedLength(10), 0, '1');
112 FileTest.testWriteListInvalidArgs(12, 0, 1); 149 testWriteByteInvalidArgs('asdf');
113 FileTest.testWriteListInvalidArgs(new List.fixedLength(10), '0', 1); 150 testWriteListInvalidArgs(12, 0, 1);
114 FileTest.testWriteListInvalidArgs(new List.fixedLength(10), 0, '1'); 151 testWriteListInvalidArgs(new List.fixedLength(10), '0', 1);
152 testWriteListInvalidArgs(new List.fixedLength(10), 0, '1');
115 } 153 }
OLDNEW
« no previous file with comments | « tests/lib/async/future_test.dart ('k') | tools/dom/src/Measurement.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698