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

Side by Side Diff: tests/stub-generator/src/MintMakerFullyIsolatedTest.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=MintMakerFullyIsolatedTest.dart:Mint,Purse,PowerfulPurse 5 // IsolateStubs=MintMakerFullyIsolatedTest.dart:Mint,Purse,PowerfulPurse
6 6
7 #import("../../isolate/src/TestFramework.dart");
8
7 interface Purse { 9 interface Purse {
8 Purse(); 10 Purse();
9 int queryBalance(); 11 int queryBalance();
10 Purse$Proxy sproutPurse(); 12 Purse$Proxy sproutPurse();
11 // The deposit has not completed until the promise completes. If we 13 // The deposit has not completed until the promise completes. If we
12 // supported Promise<void> then this could use that. 14 // supported Promise<void> then this could use that.
13 Promise<int> deposit(int amount, Purse$Proxy source); 15 Promise<int> deposit(int amount, Purse$Proxy source);
14 } 16 }
15 17
16 interface PowerfulPurse extends Purse factory PurseImpl { 18 interface PowerfulPurse extends Purse factory PurseImpl {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 return this; 158 return this;
157 } 159 }
158 160
159 Mint$Proxy _mint; 161 Mint$Proxy _mint;
160 int _balance; 162 int _balance;
161 163
162 } 164 }
163 165
164 class MintMakerFullyIsolatedTest { 166 class MintMakerFullyIsolatedTest {
165 167
166 static void testMain() { 168 static void testMain(TestExpectation expect) {
167 Mint$Proxy mint = new Mint$ProxyImpl.createIsolate(); 169 Mint$Proxy mint = new Mint$ProxyImpl.createIsolate();
168 Purse$Proxy purse = mint.createPurse(100); 170 Purse$Proxy purse = mint.createPurse(100);
169 // FIXME(benl): how do I write this? 171 // FIXME(benl): how do I write this?
170 //PowerfulPurse$Proxy power = (PowerfulPurse$Proxy)purse; 172 //PowerfulPurse$Proxy power = (PowerfulPurse$Proxy)purse;
171 //expectEqualsStr("xxx", power.grab()); 173 //expectEqualsStr("xxx", power.grab());
172 expectEquals(100, purse.queryBalance()); 174 Promise<int> balance = purse.queryBalance();
175 expect.completesWithValue(balance, 100);
173 176
174 Purse$Proxy sprouted = purse.sproutPurse(); 177 Purse$Proxy sprouted = purse.sproutPurse();
175 expectEquals(0, sprouted.queryBalance()); 178 expect.completesWithValue(sprouted.queryBalance(), 0);
176 179
177 Promise<int> done = sprouted.deposit(5, purse); 180 Promise<int> done = sprouted.deposit(5, purse);
181 Promise<int> d3 = expect.completesWithValue(done, 5);
182 Promise<int> inner = new Promise<int>();
183 Promise<int> inner2 = new Promise<int>();
178 // FIXME(benl): it should not be necessary to wait here, I think, 184 // FIXME(benl): it should not be necessary to wait here, I think,
179 // but without this, the tests seem to execute prematurely. 185 // but without this, the tests seem to execute prematurely.
180 expectEquals(5, done); 186 Promise<int> d1 = done.then((val) {
181 done.then((int) { 187 expect.completesWithValue(sprouted.queryBalance(), 0 + 5);
182 expectEquals(0 + 5, sprouted.queryBalance()); 188 expect.completesWithValue(purse.queryBalance(), 100 - 5);
183 expectEquals(100 - 5, purse.queryBalance());
184 189
185 done = sprouted.deposit(42, purse); 190 done = sprouted.deposit(42, purse);
186 expectEquals(5 + 42, done); 191 expect.completesWithValue(done, 5 + 42);
187 done.then((int) { 192 Promise<int> d2 = done.then((val) {
188 expectEquals(0 + 5 + 42, sprouted.queryBalance()); 193 expect.completesWithValue(sprouted.queryBalance(), 0 + 5 + 42)
189 expectEquals(100 - 5 - 42, purse.queryBalance()); 194 .then((int value) => inner.complete(0));
190 195 expect.completesWithValue(purse.queryBalance(), 100 - 5 - 42)
191 expectDone(8); 196 .then((int value) => inner2.complete(0));
192 }); 197 });
198 expect.completes(d2);
193 }); 199 });
194 } 200 expect.completes(d1);
195 201 Promise<int> allDone = new Promise<int>();
196 static List<Promise> results; 202 allDone.waitFor([d3, inner, inner2], 3);
197 203 allDone.then((_) => expect.succeeded());
198 static void expectEqualsStr(String expected, Promise<String> promise) {
199 if (results === null) {
200 results = new List<Promise>();
201 }
202 results.add(promise.then((String actual) {
203 //print('done ' + expected + '/' + actual);
204 Expect.equals(expected, actual);
205 }));
206 }
207
208 static void expectEquals(int expected, Promise<int> promise) {
209 if (results === null) {
210 results = new List<Promise>();
211 }
212 results.add(promise.then((int actual) {
213 //print('done ' + expected + '/' + actual);
214 Expect.equals(expected, actual);
215 }));
216 }
217
218 static void expectDone(int n) {
219 if (results === null) {
220 Expect.equals(0, n);
221 print('##DONE##');
222 } else {
223 Promise done = new Promise();
224 done.waitFor(results, results.length);
225 done.then((ignored) {
226 //print('done all ' + n + '/' + results.length);
227 Expect.equals(n, results.length);
228 print('##DONE##');
229 });
230 }
231 } 204 }
232 205
233 } 206 }
234 207
235 main() { 208 main() {
236 MintMakerFullyIsolatedTest.testMain(); 209 runTests([MintMakerFullyIsolatedTest.testMain]);
237 } 210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698