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

Side by Side Diff: tests/stub-generator/src/MintMakerPromiseWithStubsTest.dart

Issue 8380003: Switch to new test framework. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // IsolateStubs=MintMakerPromiseWithStubsTest.dart:Mint,Purse 5 // IsolateStubs=MintMakerPromiseWithStubsTest.dart:Mint,Purse
6 6
7 #import("../../isolate/src/TestFramework.dart");
8
7 interface Mint factory MintImpl { 9 interface Mint factory MintImpl {
8 10
9 Mint(); 11 Mint();
10 12
11 Purse createPurse(int balance); 13 Purse createPurse(int balance);
12 14
13 } 15 }
14 16
15 interface Purse factory PurseImpl { 17 interface Purse factory PurseImpl {
16 18
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 return _balance; 70 return _balance;
69 } 71 }
70 72
71 Mint _mint; 73 Mint _mint;
72 int _balance; 74 int _balance;
73 75
74 } 76 }
75 77
76 class MintMakerPromiseWithStubsTest { 78 class MintMakerPromiseWithStubsTest {
77 79
78 static void testMain() { 80 static void testMain(TestExpectation expect) {
79 Mint$Proxy mint = new Mint$ProxyImpl.createIsolate(); 81 Mint$Proxy mint = new Mint$ProxyImpl.createIsolate();
80 Purse$Proxy purse = mint.createPurse(100); 82 Purse$Proxy purse = mint.createPurse(100);
81 expectEquals(100, purse.queryBalance()); 83 expect.completesWithValue(purse.queryBalance(), 100);
82 84
83 Purse$Proxy sprouted = purse.sproutPurse(); 85 Purse$Proxy sprouted = purse.sproutPurse();
84 expectEquals(0, sprouted.queryBalance()); 86 expect.completesWithValue(sprouted.queryBalance(), 0);
85 87
86 // FIXME(benl): We should not have to manually order the calls 88 // FIXME(benl): We should not have to manually order the calls
87 // like this. 89 // like this.
88 Promise<int> result = sprouted.deposit(5, purse); 90 Promise<int> result = sprouted.deposit(5, purse);
89 expectEquals(5, result); 91 expect.completesWithValue(result, 5);
90 result.addCompleteHandler((_) { 92 result.addCompleteHandler((_) {
91 expectEquals(0 + 5, sprouted.queryBalance()); 93 expect.completesWithValue(sprouted.queryBalance(), 0 + 5);
92 expectEquals(100 - 5, purse.queryBalance()); 94 expect.completesWithValue(purse.queryBalance(), 100 - 5);
93 95
94 result = sprouted.deposit(42, purse); 96 result = sprouted.deposit(42, purse);
95 expectEquals(5 + 42, result); 97 expect.completesWithValue(result, 5 + 42);
96 result.addCompleteHandler((_) { 98 result.addCompleteHandler((_) {
97 expectEquals(0 + 5 + 42, sprouted.queryBalance()); 99 expect.completesWithValue(sprouted.queryBalance(), 0 + 5 + 42);
98 expectEquals(100 - 5 - 42, purse.queryBalance()); 100 expect.completesWithValue(purse.queryBalance(), 100 - 5 - 42);
99 expectDone(8); 101 });
100 });
101 }); 102 });
102 } 103 expect.succeeded();
103
104 static List<Promise> results;
105
106 static void expectEquals(int expected, Promise<int> promise) {
107 if (results === null) {
108 results = new List<Promise>();
109 }
110 results.add(promise.then((int actual) {
111 //print("done $expected/$actual");
112 Expect.equals(expected, actual);
113 }));
114 }
115
116 static void expectDone(int n) {
117 if (results === null) {
118 Expect.equals(0, n);
119 print('##DONE##');
120 } else {
121 Promise done = new Promise();
122 done.waitFor(results, results.length);
123 done.then((ignored) {
124 Expect.equals(n, results.length);
125 print('##DONE##');
126 });
127 }
128 } 104 }
129 105
130 } 106 }
131 107
132 main() { 108 main() {
133 MintMakerPromiseWithStubsTest.testMain(); 109 runTests([MintMakerPromiseWithStubsTest.testMain]);
134 } 110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698