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

Side by Side Diff: samples/tests/samples/src/proxy/PromiseTest.dart

Issue 10253022: test rename overhaul: step 13 - samples (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #library("PromiseTest");
6 #import("../../../../proxy/promise.dart");
7
8 class PromiseTest {
9
10 static void testMain() {
11 testNormalComplete();
12 testFromValue();
13 testNormalCompleteWithHandler();
14 testNormalCompleteManyHandlers();
15 testError();
16 testErrorWithHandler();
17 testCancel();
18 testCancelWithHandler();
19 testChainComplete();
20 testChainError();
21 testChainCancel();
22 testFlatten();
23 testJoinSelectSecond();
24 testWaitFor1();
25 testWaitForAll();
26 }
27
28 static void testNormalComplete() {
29 Promise<int> a = new Promise<int>();
30 Expect.equals(false, a.isDone());
31 Expect.equals(false, a.hasValue());
32 Expect.equals(false, a.hasError());
33 Expect.equals(false, a.isCancelled());
34
35 readValueThrowsException_(a);
36 readErrorThrowsException_(a);
37 a.complete(3);
38 Expect.equals(true, a.isDone());
39 Expect.equals(true, a.hasValue());
40 Expect.equals(false, a.hasError());
41 Expect.equals(false, a.isCancelled());
42 Expect.equals(3, a.value);
43 Expect.equals(null, a.error);
44 }
45
46 static void testFromValue() {
47 Promise<int> a = new Promise<int>.fromValue(3);
48 Expect.equals(true, a.isDone());
49 Expect.equals(false, a.isCancelled());
50 Expect.equals(true, a.hasValue());
51 Expect.equals(false, a.hasError());
52 Expect.equals(false, a.isCancelled());
53 Expect.equals(3, a.value);
54 Expect.equals(null, a.error);
55 }
56
57 static void testNormalCompleteWithHandler() {
58 Promise<int> a = new Promise<int>();
59 Promise<int> b = new Promise<int>();
60 Expect.equals(false, a.isDone());
61 Expect.equals(false, a.hasValue());
62 Expect.equals(false, a.hasError());
63 Expect.equals(false, a.isCancelled());
64 Expect.equals(false, b.isDone());
65 Expect.equals(false, b.hasValue());
66 Expect.equals(false, b.hasError());
67 Expect.equals(false, b.isCancelled());
68 readValueThrowsException_(a);
69 readErrorThrowsException_(a);
70 readValueThrowsException_(b);
71 readErrorThrowsException_(b);
72 int afterA = null;
73 int afterB = null;
74
75 // value computed after setup is done.
76 a.addCompleteHandler((int v) { afterA = v; });
77 a.complete(3);
78
79 // value computed before setup was done.
80 b.complete(4);
81 b.addCompleteHandler((int v) { afterB = v; });
82
83 Expect.equals(true, a.isDone());
84 Expect.equals(true, a.hasValue());
85 Expect.equals(false, a.hasError());
86 Expect.equals(false, a.isCancelled());
87 Expect.equals(true, b.isDone());
88 Expect.equals(true, b.hasValue());
89 Expect.equals(false, b.hasError());
90 Expect.equals(false, b.isCancelled());
91 Expect.equals(null, a.error);
92 Expect.equals(null, b.error);
93
94 Expect.equals(3, a.value);
95 Expect.equals(4, b.value);
96 Expect.equals(3, afterA);
97 Expect.equals(4, afterB);
98 }
99
100 static void testNormalCompleteManyHandlers() {
101 Promise<int> a = new Promise<int>();
102 Expect.equals(false, a.isDone());
103 Expect.equals(false, a.hasValue());
104 Expect.equals(false, a.hasError());
105 Expect.equals(false, a.isCancelled());
106 readValueThrowsException_(a);
107 readErrorThrowsException_(a);
108 int afterA1 = null;
109 int afterA2 = null;
110 int afterA3 = null;
111
112 // value computed after setup is done.
113 a.addCompleteHandler((int v) { afterA1 = v; });
114 a.complete(3);
115 a.addCompleteHandler((int v) { afterA2 = v; });
116 a.addCompleteHandler((int v) { afterA3 = v; });
117
118 Expect.equals(true, a.isDone());
119 Expect.equals(true, a.hasValue());
120 Expect.equals(false, a.hasError());
121 Expect.equals(false, a.isCancelled());
122 Expect.equals(null, a.error);
123 Expect.equals(3, a.value);
124 Expect.equals(3, afterA1);
125 Expect.equals(3, afterA2);
126 Expect.equals(3, afterA3);
127 }
128
129 static void testError() {
130 Promise<int> a = new Promise<int>();
131 Expect.equals(false, a.isDone());
132 Expect.equals(false, a.hasValue());
133 Expect.equals(false, a.hasError());
134 Expect.equals(false, a.isCancelled());
135 readValueThrowsException_(a);
136 readErrorThrowsException_(a);
137 a.fail("Err");
138 Expect.equals(true, a.isDone());
139 Expect.equals(false, a.hasValue());
140 Expect.equals(true, a.hasError());
141 Expect.equals(false, a.isCancelled());
142 Expect.equals("Err", a.error);
143 readValueThrowsException_(a, a.error);
144 }
145
146 static void testErrorWithHandler() {
147 Promise<int> a = new Promise<int>();
148 Promise<int> b = new Promise<int>();
149 Expect.equals(false, a.isDone());
150 Expect.equals(false, a.hasValue());
151 Expect.equals(false, a.hasError());
152 Expect.equals(false, a.isCancelled());
153 Expect.equals(false, b.isDone());
154 Expect.equals(false, b.hasValue());
155 Expect.equals(false, b.hasError());
156 Expect.equals(false, b.isCancelled());
157 readValueThrowsException_(a);
158 readErrorThrowsException_(a);
159 readValueThrowsException_(b);
160 readErrorThrowsException_(b);
161 String afterA = null;
162 String afterB = null;
163
164 // error after set up is done
165 a.addErrorHandler((v) { afterA = v; });
166 a.fail("ErrA");
167
168 // error before setup is done
169 b.fail("ErrB");
170 b.addErrorHandler((v) { afterB = v; });
171
172 Expect.equals(true, a.isDone());
173 Expect.equals(false, a.hasValue());
174 Expect.equals(true, a.hasError());
175 Expect.equals(false, a.isCancelled());
176
177 Expect.equals(true, b.isDone());
178 Expect.equals(false, b.hasValue());
179 Expect.equals(true, b.hasError());
180 Expect.equals(false, b.isCancelled());
181
182 Expect.equals("ErrA", a.error);
183 Expect.equals("ErrB", b.error);
184 Expect.equals("ErrA", afterA);
185 Expect.equals("ErrB", afterB);
186
187 readValueThrowsException_(a, a.error);
188 readValueThrowsException_(b, b.error);
189 }
190
191 static void testCancel() {
192 Promise<int> a = new Promise<int>();
193 Expect.equals(false, a.isDone());
194 Expect.equals(false, a.hasValue());
195 Expect.equals(false, a.hasError());
196 Expect.equals(false, a.isCancelled());
197
198 readValueThrowsException_(a);
199 readErrorThrowsException_(a);
200 a.cancel();
201 Expect.equals(true, a.isDone());
202 Expect.equals(false, a.hasValue());
203 Expect.equals(false, a.hasError());
204 Expect.equals(true, a.isCancelled());
205 Expect.equals(null, a.value);
206 Expect.equals(null, a.error);
207 }
208
209 static void testCancelWithHandler() {
210 Promise<int> a = new Promise<int>();
211 Promise<int> b = new Promise<int>();
212 Expect.equals(false, a.isDone());
213 Expect.equals(false, a.hasValue());
214 Expect.equals(false, a.hasError());
215 Expect.equals(false, a.isCancelled());
216 Expect.equals(false, b.isDone());
217 Expect.equals(false, b.hasValue());
218 Expect.equals(false, b.hasError());
219 Expect.equals(false, b.isCancelled());
220 readValueThrowsException_(a);
221 readErrorThrowsException_(a);
222 readValueThrowsException_(b);
223 readErrorThrowsException_(b);
224 bool aCancel = false;
225 bool bCancel = false;
226
227 // cancel after setup
228 a.addCancelHandler(() { aCancel = true; });
229 a.cancel();
230
231 // cancel before setup is done
232 b.cancel();
233 b.addCancelHandler(() { bCancel = true; });
234
235 Expect.equals(true, a.isDone());
236 Expect.equals(false, a.hasValue());
237 Expect.equals(false, a.hasError());
238 Expect.equals(true, a.isCancelled());
239 Expect.equals(true, b.isDone());
240 Expect.equals(false, b.hasValue());
241 Expect.equals(false, b.hasError());
242 Expect.equals(true, b.isCancelled());
243 Expect.equals(null, a.value);
244 Expect.equals(null, b.value);
245 Expect.equals(null, a.error);
246 Expect.equals(null, b.error);
247 Expect.equals(true, aCancel);
248 Expect.equals(true, bCancel);
249
250 Promise<int> c = new Promise<int>();
251 bool cCancel = false;
252 c.cancel();
253 c.complete(3);
254 c.addCancelHandler(() { cCancel = true; });
255 Expect.equals(true, cCancel);
256 Expect.equals(true, c.isDone());
257 Expect.equals(true, c.hasValue());
258 Expect.equals(false, c.hasError());
259 Expect.equals(true, c.isCancelled());
260
261 Promise<int> d = new Promise<int>();
262 bool dCancel = false;
263 d.cancel();
264 d.fail("fail");
265 d.addCancelHandler(() { dCancel = true; });
266 Expect.equals(true, dCancel);
267 Expect.equals(true, d.isDone());
268 Expect.equals(false, d.hasValue());
269 Expect.equals(true, d.hasError());
270 Expect.equals(true, d.isCancelled());
271 }
272
273 static void testChainComplete() {
274 Promise<int> a = new Promise<int>();
275 Promise<int> b = a.then((int ares) => ares + 1);
276 Expect.equals(false, a.isDone());
277 Expect.equals(false, a.hasValue());
278 Expect.equals(false, a.hasError());
279 Expect.equals(false, a.isCancelled());
280 Expect.equals(false, b.isDone());
281 Expect.equals(false, b.hasValue());
282 Expect.equals(false, b.hasError());
283 Expect.equals(false, b.isCancelled());
284 readValueThrowsException_(a);
285 readErrorThrowsException_(a);
286 readValueThrowsException_(b);
287 readErrorThrowsException_(b);
288 int resA = null;
289 a.addCompleteHandler((int v) { resA = v; });
290 int resB = null;
291 b.addCompleteHandler((int v) { resB = v; });
292
293 a.complete(3);
294
295 Expect.equals(true, a.isDone());
296 Expect.equals(true, a.hasValue());
297 Expect.equals(false, a.hasError());
298 Expect.equals(false, a.isCancelled());
299
300 Expect.equals(true, b.isDone());
301 Expect.equals(true, b.hasValue());
302 Expect.equals(false, b.hasError());
303 Expect.equals(false, b.isCancelled());
304
305 Expect.equals(3, a.value);
306 Expect.equals(4, b.value);
307 Expect.equals(null, a.error);
308 Expect.equals(null, b.error);
309 Expect.equals(3, resA);
310 Expect.equals(4, resB);
311 }
312
313 static void testChainError() {
314 Promise<int> a = new Promise<int>();
315 Promise<int> b = a.then((int ares) => ares + 1);
316 Expect.equals(false, a.isDone());
317 Expect.equals(false, a.hasValue());
318 Expect.equals(false, a.hasError());
319 Expect.equals(false, a.isCancelled());
320 Expect.equals(false, b.isDone());
321 Expect.equals(false, b.hasValue());
322 Expect.equals(false, b.hasError());
323 Expect.equals(false, b.isCancelled());
324 readValueThrowsException_(a);
325 readErrorThrowsException_(a);
326 readValueThrowsException_(b);
327 readErrorThrowsException_(b);
328 String errA = null;
329 a.addErrorHandler((e) { errA = e; });
330 String errB = null;
331 b.addErrorHandler((e) { errB = e; });
332
333 a.fail("err-from-a");
334
335 Expect.equals(true, a.isDone());
336 Expect.equals(false, a.hasValue());
337 Expect.equals(true, a.hasError());
338 Expect.equals(false, a.isCancelled());
339 Expect.equals(true, b.isDone());
340 Expect.equals(false, b.hasValue());
341 Expect.equals(true, b.hasError());
342 Expect.equals(false, b.isCancelled());
343
344 Expect.equals("err-from-a", a.error);
345 Expect.equals("err-from-a", b.error);
346 Expect.equals("err-from-a", errA);
347 Expect.equals("err-from-a", errB);
348
349 readValueThrowsException_(a, a.error);
350 readValueThrowsException_(b, b.error);
351 }
352
353 static void testChainCancel() {
354 Promise<int> a = new Promise<int>();
355 Promise<int> b = a.then((int ares) => ares + 1);
356 Expect.equals(false, a.isDone());
357 Expect.equals(false, a.hasValue());
358 Expect.equals(false, a.hasError());
359 Expect.equals(false, a.isCancelled());
360 Expect.equals(false, b.isDone());
361 Expect.equals(false, b.hasValue());
362 Expect.equals(false, b.hasError());
363 Expect.equals(false, b.isCancelled());
364 readValueThrowsException_(a);
365 readErrorThrowsException_(a);
366 readValueThrowsException_(b);
367 readErrorThrowsException_(b);
368 bool bCancel = false;
369 b.addCancelHandler(() { bCancel = true; });
370 bool bError = false;
371 b.addErrorHandler((e) { bError = true; });
372 bool aCancel = false;
373 a.addCancelHandler(() { aCancel = true; });
374
375 a.cancel();
376
377 Expect.equals(true, a.isDone());
378 Expect.equals(false, a.hasValue());
379 Expect.equals(false, a.hasError());
380 Expect.equals(true, a.isCancelled());
381 Expect.equals(true, b.isDone());
382 Expect.equals(false, b.hasValue());
383 Expect.equals(true, b.hasError());
384 Expect.equals(false, b.isCancelled());
385 Expect.equals(null, a.value);
386 Expect.equals(null, a.error);
387 Expect.equals("Source promise was cancelled", b.error);
388 readValueThrowsException_(b, b.error);
389 Expect.equals(false, bCancel);
390 Expect.equals(true, bError);
391 Expect.equals(true, aCancel);
392 }
393
394 static void testFlatten() {
395 Promise<int> a = new Promise<int>();
396 Promise<Promise<int>> b = new Promise<Promise<int>>();
397 Promise<Promise<Promise<int>>> c = new Promise<Promise<Promise<int>>>();
398 Promise<Promise<Promise<Promise<int>>>> d =
399 new Promise<Promise<Promise<Promise<int>>>>();
400 Promise<int> flat = d.flatten();
401
402 Expect.equals(false, a.isDone());
403 Expect.equals(false, b.isDone());
404 Expect.equals(false, c.isDone());
405 Expect.equals(false, d.isDone());
406 Expect.equals(false, flat.isDone());
407 readValueThrowsException_(a);
408 readValueThrowsException_(b);
409 readValueThrowsException_(c);
410 readValueThrowsException_(d);
411 readValueThrowsException_(flat);
412
413 b.complete(a);
414
415 Expect.equals(false, a.isDone());
416 Expect.equals(true, b.isDone());
417 Expect.equals(false, c.isDone());
418 Expect.equals(false, d.isDone());
419 Expect.equals(false, flat.isDone());
420 readValueThrowsException_(a);
421 Expect.equals(a, b.value);
422 readValueThrowsException_(c);
423 readValueThrowsException_(d);
424 readValueThrowsException_(flat);
425
426 d.complete(c);
427
428 Expect.equals(false, a.isDone());
429 Expect.equals(true, b.isDone());
430 Expect.equals(false, c.isDone());
431 Expect.equals(true, d.isDone());
432 Expect.equals(false, flat.isDone());
433 readValueThrowsException_(a);
434 Expect.equals(a, b.value);
435 readValueThrowsException_(c);
436 Expect.equals(c, d.value);
437 readValueThrowsException_(flat);
438
439 a.complete(2);
440
441 Expect.equals(true, a.isDone());
442 Expect.equals(true, b.isDone());
443 Expect.equals(false, c.isDone());
444 Expect.equals(true, d.isDone());
445 Expect.equals(false, flat.isDone());
446 Expect.equals(2, a.value);
447 Expect.equals(a, b.value);
448 readValueThrowsException_(c);
449 Expect.equals(c, d.value);
450 readValueThrowsException_(flat);
451
452 c.complete(b);
453
454 Expect.equals(true, a.isDone());
455 Expect.equals(true, b.isDone());
456 Expect.equals(true, c.isDone());
457 Expect.equals(true, d.isDone());
458 Expect.equals(true, flat.isDone());
459 Expect.equals(2, a.value);
460 Expect.equals(a, b.value);
461 Expect.equals(b, c.value);
462 Expect.equals(c, d.value);
463 Expect.equals(2, flat.value);
464 }
465
466 static void testJoinSelectSecond() {
467 Promise<int> a = new Promise<int>();
468 Promise<int> b = new Promise<int>();
469 Promise<int> c = new Promise<int>();
470 Promise<int> second = new Promise<int>();
471 bool first = true;
472 second.join([a, b, c], (p) {
473 if (first == true) {
474 first = false;
475 return false;
476 } else {
477 return true;
478 }
479 });
480
481 Expect.equals(false, a.isDone());
482 Expect.equals(false, b.isDone());
483 Expect.equals(false, c.isDone());
484 readValueThrowsException_(a);
485 readErrorThrowsException_(a);
486 readValueThrowsException_(b);
487 readErrorThrowsException_(b);
488 readValueThrowsException_(c);
489 readErrorThrowsException_(c);
490 Expect.equals(false, second.isDone());
491 readValueThrowsException_(second);
492 readErrorThrowsException_(second);
493
494 b.complete(2);
495
496 Expect.equals(false, a.isDone());
497 Expect.equals(true, b.isDone());
498 Expect.equals(false, c.isDone());
499 readValueThrowsException_(a);
500 readErrorThrowsException_(a);
501 Expect.equals(2, b.value);
502 Expect.equals(null, b.error);
503 readValueThrowsException_(c);
504 readErrorThrowsException_(c);
505 Expect.equals(false, second.isDone());
506 readValueThrowsException_(second);
507 readErrorThrowsException_(second);
508
509 c.complete(3);
510
511 Expect.equals(true, second.isDone());
512 Expect.equals(false, a.isDone());
513 Expect.equals(true, b.isDone());
514 Expect.equals(true, c.isDone());
515
516 readValueThrowsException_(a);
517 readErrorThrowsException_(a);
518 Expect.equals(2, b.value);
519 Expect.equals(null, b.error);
520 Expect.equals(3, c.value);
521 Expect.equals(null, c.error);
522 Expect.equals(3, second.value);
523 }
524
525 static void testWaitFor1() {
526 Promise<int> a = new Promise<int>();
527 Promise<int> b = new Promise<int>();
528 Promise<int> c = new Promise<int>();
529 Promise<int> first = new Promise<int>();
530 first.waitFor([a, b, c], 1);
531
532 Expect.equals(false, a.isDone());
533 Expect.equals(false, a.hasValue());
534 Expect.equals(false, a.hasError());
535 Expect.equals(false, a.isCancelled());
536 Expect.equals(false, b.isDone());
537 Expect.equals(false, b.hasValue());
538 Expect.equals(false, b.hasError());
539 Expect.equals(false, b.isCancelled());
540 Expect.equals(false, c.isDone());
541 Expect.equals(false, c.hasValue());
542 Expect.equals(false, c.hasError());
543 Expect.equals(false, c.isCancelled());
544 readValueThrowsException_(a);
545 readErrorThrowsException_(a);
546 readValueThrowsException_(b);
547 readErrorThrowsException_(b);
548 readValueThrowsException_(c);
549 readErrorThrowsException_(c);
550 Expect.equals(false, first.isDone());
551
552 b.complete(2);
553
554 // a & c got cancelled
555 Expect.equals(true, first.isDone());
556 Expect.equals(true, first.hasValue());
557 Expect.equals(false, first.hasError());
558 Expect.equals(false, first.isCancelled());
559 Expect.equals(true, a.isDone());
560 Expect.equals(false, a.hasValue());
561 Expect.equals(false, a.hasError());
562 Expect.equals(true, a.isCancelled());
563 Expect.equals(true, b.isDone());
564 Expect.equals(true, b.hasValue());
565 Expect.equals(false, b.hasError());
566 Expect.equals(false, b.isCancelled());
567 Expect.equals(true, c.isDone());
568 Expect.equals(false, c.hasValue());
569 Expect.equals(false, c.hasError());
570 Expect.equals(true, c.isCancelled());
571
572 Expect.equals(null, a.value);
573 Expect.equals(2, b.value);
574 Expect.equals(null, c.value);
575 Expect.equals(null, a.error);
576 Expect.equals(null, b.error);
577 Expect.equals(null, c.error);
578 Expect.equals(2, first.value);
579 }
580
581 static void testWaitForAll() {
582 Promise<int> a = new Promise<int>();
583 Promise<int> b = new Promise<int>();
584 Promise<int> c = new Promise<int>();
585 Promise<int> all = new Promise<int>();
586 all.waitFor([a, b, c], 3);
587
588 Expect.equals(false, a.isDone());
589 Expect.equals(false, a.hasValue());
590 Expect.equals(false, a.hasError());
591 Expect.equals(false, a.isCancelled());
592 Expect.equals(false, b.isDone());
593 Expect.equals(false, b.hasValue());
594 Expect.equals(false, b.hasError());
595 Expect.equals(false, b.isCancelled());
596 Expect.equals(false, c.isDone());
597 Expect.equals(false, c.hasValue());
598 Expect.equals(false, c.hasError());
599 Expect.equals(false, c.isCancelled());
600 Expect.equals(false, all.isDone());
601 Expect.equals(false, all.hasValue());
602 Expect.equals(false, all.hasError());
603 Expect.equals(false, all.isCancelled());
604 readValueThrowsException_(a);
605 readErrorThrowsException_(a);
606 readValueThrowsException_(b);
607 readErrorThrowsException_(b);
608 readValueThrowsException_(c);
609 readErrorThrowsException_(c);
610 readValueThrowsException_(all);
611 readErrorThrowsException_(all);
612
613 b.complete(2);
614
615 Expect.equals(false, a.isDone());
616 Expect.equals(false, a.hasValue());
617 Expect.equals(false, a.hasError());
618 Expect.equals(false, a.isCancelled());
619 Expect.equals(true, b.isDone());
620 Expect.equals(true, b.hasValue());
621 Expect.equals(false, b.hasError());
622 Expect.equals(false, b.isCancelled());
623 Expect.equals(false, c.isDone());
624 Expect.equals(false, c.hasValue());
625 Expect.equals(false, c.hasError());
626 Expect.equals(false, c.isCancelled());
627 Expect.equals(false, all.isDone());
628 Expect.equals(false, all.hasValue());
629 Expect.equals(false, all.hasError());
630 Expect.equals(false, all.isCancelled());
631
632 readValueThrowsException_(a);
633 readErrorThrowsException_(a);
634 Expect.equals(2, b.value);
635 Expect.equals(null, b.error);
636 readValueThrowsException_(c);
637 readErrorThrowsException_(c);
638 readValueThrowsException_(all);
639 readErrorThrowsException_(all);
640
641 c.complete(3);
642
643 Expect.equals(false, a.isDone());
644 Expect.equals(false, a.hasValue());
645 Expect.equals(false, a.hasError());
646 Expect.equals(false, a.isCancelled());
647 Expect.equals(true, b.isDone());
648 Expect.equals(true, b.hasValue());
649 Expect.equals(false, b.hasError());
650 Expect.equals(false, b.isCancelled());
651 Expect.equals(true, c.isDone());
652 Expect.equals(true, c.hasValue());
653 Expect.equals(false, c.hasError());
654 Expect.equals(false, c.isCancelled());
655 Expect.equals(false, all.isDone());
656 Expect.equals(false, all.hasValue());
657 Expect.equals(false, all.hasError());
658 Expect.equals(false, all.isCancelled());
659
660 readValueThrowsException_(a);
661 readErrorThrowsException_(a);
662 Expect.equals(2, b.value);
663 Expect.equals(null, b.error);
664 Expect.equals(3, c.value);
665 Expect.equals(null, c.error);
666 readValueThrowsException_(all);
667 readErrorThrowsException_(all);
668
669 a.complete(1);
670
671 Expect.equals(true, a.isDone());
672 Expect.equals(true, a.hasValue());
673 Expect.equals(false, a.hasError());
674 Expect.equals(false, a.isCancelled());
675 Expect.equals(true, b.isDone());
676 Expect.equals(true, b.hasValue());
677 Expect.equals(false, b.hasError());
678 Expect.equals(false, b.isCancelled());
679 Expect.equals(true, c.isDone());
680 Expect.equals(true, c.hasValue());
681 Expect.equals(false, c.hasError());
682 Expect.equals(false, c.isCancelled());
683 Expect.equals(true, all.isDone());
684 Expect.equals(true, all.hasValue());
685 Expect.equals(false, all.hasError());
686 Expect.equals(false, all.isCancelled());
687
688 Expect.equals(1, a.value);
689 Expect.equals(null, a.error);
690 Expect.equals(2, b.value);
691 Expect.equals(null, b.error);
692 Expect.equals(3, c.value);
693 Expect.equals(null, c.error);
694 Expect.equals(1, all.value);
695 Expect.equals(null, all.error);
696 }
697
698 static void readValueThrowsException_(Promise p, [var error = null]) {
699 bool errorFound = false;
700 try {
701 var x = p.value;
702 } catch (var e) {
703 errorFound = true;
704 if (error !== null) {
705 Expect.equals(true, error === e);
706 }
707 }
708 Expect.equals(true, errorFound);
709 }
710
711 static void readErrorThrowsException_(Promise p) {
712 bool errorFound = false;
713 try {
714 var x = p.error;
715 } catch (var e) {
716 errorFound = true;
717 }
718 Expect.equals(true, errorFound);
719 }
720 }
721
722 main() {
723 PromiseTest.testMain();
724 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698