| OLD | NEW |
| 1 /* class = Purse (tests/stub-generator/src/MintMakerFullyIsolatedTest.dart/MintM
akerFullyIsolatedTest.dart: 7) */ | 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // IsolateStubs=MintMakerFullyIsolatedTest.dart:Mint,Purse,PowerfulPurse |
| 6 |
| 7 #import("../../isolate/src/TestFramework.dart"); |
| 8 |
| 9 /* class = Purse (tests/stub-generator/src/MintMakerFullyIsolatedTest.dart/MintM
akerFullyIsolatedTest.dart: 9) */ |
| 2 | 10 |
| 3 interface Purse$Proxy { | 11 interface Purse$Proxy { |
| 4 Promise<int> queryBalance(); | 12 Promise<int> queryBalance(); |
| 5 | 13 |
| 6 Purse$Proxy sproutPurse(); | 14 Purse$Proxy sproutPurse(); |
| 7 | 15 |
| 8 Promise<int> deposit(int amount, Purse$Proxy source); | 16 Promise<int> deposit(int amount, Purse$Proxy source); |
| 9 } | 17 } |
| 10 | 18 |
| 11 class Purse$ProxyImpl extends Proxy implements Purse$Proxy { | 19 class Purse$ProxyImpl extends Proxy implements Purse$Proxy { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 void main() { | 76 void main() { |
| 69 this.port.receive(void _(var message, SendPort replyTo) { | 77 this.port.receive(void _(var message, SendPort replyTo) { |
| 70 Purse thing = new Purse(); | 78 Purse thing = new Purse(); |
| 71 SendPort port = Dispatcher.serve(new Purse$Dispatcher(thing)); | 79 SendPort port = Dispatcher.serve(new Purse$Dispatcher(thing)); |
| 72 Proxy proxy = new Proxy.forPort(replyTo); | 80 Proxy proxy = new Proxy.forPort(replyTo); |
| 73 proxy.send([port]); | 81 proxy.send([port]); |
| 74 }); | 82 }); |
| 75 } | 83 } |
| 76 } | 84 } |
| 77 | 85 |
| 78 /* class = PowerfulPurse (tests/stub-generator/src/MintMakerFullyIsolatedTest.da
rt/MintMakerFullyIsolatedTest.dart: 16) */ | 86 /* class = PowerfulPurse (tests/stub-generator/src/MintMakerFullyIsolatedTest.da
rt/MintMakerFullyIsolatedTest.dart: 18) */ |
| 79 | 87 |
| 80 interface PowerfulPurse$Proxy { | 88 interface PowerfulPurse$Proxy { |
| 81 void init(Mint$Proxy mint, int balance); | 89 void init(Mint$Proxy mint, int balance); |
| 82 | 90 |
| 83 Promise<int> grab(int amount); | 91 Promise<int> grab(int amount); |
| 84 | 92 |
| 85 Purse$Proxy weak(); | 93 Purse$Proxy weak(); |
| 86 } | 94 } |
| 87 | 95 |
| 88 class PowerfulPurse$ProxyImpl extends Proxy implements PowerfulPurse$Proxy { | 96 class PowerfulPurse$ProxyImpl extends Proxy implements PowerfulPurse$Proxy { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 void main() { | 154 void main() { |
| 147 this.port.receive(void _(var message, SendPort replyTo) { | 155 this.port.receive(void _(var message, SendPort replyTo) { |
| 148 PowerfulPurse thing = new PowerfulPurse(); | 156 PowerfulPurse thing = new PowerfulPurse(); |
| 149 SendPort port = Dispatcher.serve(new PowerfulPurse$Dispatcher(thing)); | 157 SendPort port = Dispatcher.serve(new PowerfulPurse$Dispatcher(thing)); |
| 150 Proxy proxy = new Proxy.forPort(replyTo); | 158 Proxy proxy = new Proxy.forPort(replyTo); |
| 151 proxy.send([port]); | 159 proxy.send([port]); |
| 152 }); | 160 }); |
| 153 } | 161 } |
| 154 } | 162 } |
| 155 | 163 |
| 156 /* class = Mint (tests/stub-generator/src/MintMakerFullyIsolatedTest.dart/MintMa
kerFullyIsolatedTest.dart: 26) */ | 164 /* class = Mint (tests/stub-generator/src/MintMakerFullyIsolatedTest.dart/MintMa
kerFullyIsolatedTest.dart: 28) */ |
| 157 | 165 |
| 158 interface Mint$Proxy { | 166 interface Mint$Proxy { |
| 159 Purse$Proxy createPurse(int balance); | 167 Purse$Proxy createPurse(int balance); |
| 160 | 168 |
| 161 PowerfulPurse$Proxy promote(Purse$Proxy purse); | 169 PowerfulPurse$Proxy promote(Purse$Proxy purse); |
| 162 } | 170 } |
| 163 | 171 |
| 164 class Mint$ProxyImpl extends Proxy implements Mint$Proxy { | 172 class Mint$ProxyImpl extends Proxy implements Mint$Proxy { |
| 165 Mint$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } | 173 Mint$ProxyImpl(Promise<SendPort> port) : super.forReply(port) { } |
| 166 Mint$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])
) { } | 174 Mint$ProxyImpl.forIsolate(Proxy isolate) : super.forReply(isolate.call([null])
) { } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 221 |
| 214 void main() { | 222 void main() { |
| 215 this.port.receive(void _(var message, SendPort replyTo) { | 223 this.port.receive(void _(var message, SendPort replyTo) { |
| 216 Mint thing = new Mint(); | 224 Mint thing = new Mint(); |
| 217 SendPort port = Dispatcher.serve(new Mint$Dispatcher(thing)); | 225 SendPort port = Dispatcher.serve(new Mint$Dispatcher(thing)); |
| 218 Proxy proxy = new Proxy.forPort(replyTo); | 226 Proxy proxy = new Proxy.forPort(replyTo); |
| 219 proxy.send([port]); | 227 proxy.send([port]); |
| 220 }); | 228 }); |
| 221 } | 229 } |
| 222 } | 230 } |
| 223 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 224 // for details. All rights reserved. Use of this source code is governed by a | |
| 225 // BSD-style license that can be found in the LICENSE file. | |
| 226 | |
| 227 // IsolateStubs=MintMakerFullyIsolatedTest.dart:Mint,Purse,PowerfulPurse | |
| 228 | |
| 229 interface Purse { | 231 interface Purse { |
| 230 Purse(); | 232 Purse(); |
| 231 int queryBalance(); | 233 int queryBalance(); |
| 232 Purse$Proxy sproutPurse(); | 234 Purse$Proxy sproutPurse(); |
| 233 // The deposit has not completed until the promise completes. If we | 235 // The deposit has not completed until the promise completes. If we |
| 234 // supported Promise<void> then this could use that. | 236 // supported Promise<void> then this could use that. |
| 235 Promise<int> deposit(int amount, Purse$Proxy source); | 237 Promise<int> deposit(int amount, Purse$Proxy source); |
| 236 } | 238 } |
| 237 | 239 |
| 238 interface PowerfulPurse extends Purse factory PurseImpl { | 240 interface PowerfulPurse extends Purse factory PurseImpl { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 return this; | 380 return this; |
| 379 } | 381 } |
| 380 | 382 |
| 381 Mint$Proxy _mint; | 383 Mint$Proxy _mint; |
| 382 int _balance; | 384 int _balance; |
| 383 | 385 |
| 384 } | 386 } |
| 385 | 387 |
| 386 class MintMakerFullyIsolatedTest { | 388 class MintMakerFullyIsolatedTest { |
| 387 | 389 |
| 388 static void testMain() { | 390 static void testMain(TestExpectation expect) { |
| 389 Mint$Proxy mint = new Mint$ProxyImpl.createIsolate(); | 391 Mint$Proxy mint = new Mint$ProxyImpl.createIsolate(); |
| 390 Purse$Proxy purse = mint.createPurse(100); | 392 Purse$Proxy purse = mint.createPurse(100); |
| 391 // FIXME(benl): how do I write this? | 393 // FIXME(benl): how do I write this? |
| 392 //PowerfulPurse$Proxy power = (PowerfulPurse$Proxy)purse; | 394 //PowerfulPurse$Proxy power = (PowerfulPurse$Proxy)purse; |
| 393 //expectEqualsStr("xxx", power.grab()); | 395 //expectEqualsStr("xxx", power.grab()); |
| 394 expectEquals(100, purse.queryBalance()); | 396 Promise<int> balance = purse.queryBalance(); |
| 397 expect.completesWithValue(balance, 100); |
| 395 | 398 |
| 396 Purse$Proxy sprouted = purse.sproutPurse(); | 399 Purse$Proxy sprouted = purse.sproutPurse(); |
| 397 expectEquals(0, sprouted.queryBalance()); | 400 expect.completesWithValue(sprouted.queryBalance(), 0); |
| 398 | 401 |
| 399 Promise<int> done = sprouted.deposit(5, purse); | 402 Promise<int> done = sprouted.deposit(5, purse); |
| 403 Promise<int> d3 = expect.completesWithValue(done, 5); |
| 404 Promise<int> inner = new Promise<int>(); |
| 405 Promise<int> inner2 = new Promise<int>(); |
| 400 // FIXME(benl): it should not be necessary to wait here, I think, | 406 // FIXME(benl): it should not be necessary to wait here, I think, |
| 401 // but without this, the tests seem to execute prematurely. | 407 // but without this, the tests seem to execute prematurely. |
| 402 expectEquals(5, done); | 408 Promise<int> d1 = done.then((val) { |
| 403 done.then((int) { | 409 expect.completesWithValue(sprouted.queryBalance(), 0 + 5); |
| 404 expectEquals(0 + 5, sprouted.queryBalance()); | 410 expect.completesWithValue(purse.queryBalance(), 100 - 5); |
| 405 expectEquals(100 - 5, purse.queryBalance()); | |
| 406 | 411 |
| 407 done = sprouted.deposit(42, purse); | 412 done = sprouted.deposit(42, purse); |
| 408 expectEquals(5 + 42, done); | 413 expect.completesWithValue(done, 5 + 42); |
| 409 done.then((int) { | 414 Promise<int> d2 = done.then((val) { |
| 410 expectEquals(0 + 5 + 42, sprouted.queryBalance()); | 415 expect.completesWithValue(sprouted.queryBalance(), 0 + 5 + 42) |
| 411 expectEquals(100 - 5 - 42, purse.queryBalance()); | 416 .then((int value) => inner.complete(0)); |
| 412 | 417 expect.completesWithValue(purse.queryBalance(), 100 - 5 - 42) |
| 413 expectDone(8); | 418 .then((int value) => inner2.complete(0)); |
| 414 }); | 419 }); |
| 420 expect.completes(d2); |
| 415 }); | 421 }); |
| 416 } | 422 expect.completes(d1); |
| 417 | 423 Promise<int> allDone = new Promise<int>(); |
| 418 static List<Promise> results; | 424 allDone.waitFor([d3, inner, inner2], 3); |
| 419 | 425 allDone.then((_) => expect.succeeded()); |
| 420 static void expectEqualsStr(String expected, Promise<String> promise) { | |
| 421 if (results === null) { | |
| 422 results = new List<Promise>(); | |
| 423 } | |
| 424 results.add(promise.then((String actual) { | |
| 425 //print('done ' + expected + '/' + actual); | |
| 426 Expect.equals(expected, actual); | |
| 427 })); | |
| 428 } | |
| 429 | |
| 430 static void expectEquals(int expected, Promise<int> promise) { | |
| 431 if (results === null) { | |
| 432 results = new List<Promise>(); | |
| 433 } | |
| 434 results.add(promise.then((int actual) { | |
| 435 //print('done ' + expected + '/' + actual); | |
| 436 Expect.equals(expected, actual); | |
| 437 })); | |
| 438 } | |
| 439 | |
| 440 static void expectDone(int n) { | |
| 441 if (results === null) { | |
| 442 Expect.equals(0, n); | |
| 443 print('##DONE##'); | |
| 444 } else { | |
| 445 Promise done = new Promise(); | |
| 446 done.waitFor(results, results.length); | |
| 447 done.then((ignored) { | |
| 448 //print('done all ' + n + '/' + results.length); | |
| 449 Expect.equals(n, results.length); | |
| 450 print('##DONE##'); | |
| 451 }); | |
| 452 } | |
| 453 } | 426 } |
| 454 | 427 |
| 455 } | 428 } |
| 456 | 429 |
| 457 main() { | 430 main() { |
| 458 MintMakerFullyIsolatedTest.testMain(); | 431 runTests([MintMakerFullyIsolatedTest.testMain]); |
| 459 } | 432 } |
| OLD | NEW |