| OLD | NEW |
| 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 // IsolateStubs=MintMakerPromiseWithStubsTest.dart:Mint,Purse | 5 // IsolateStubs=MintMakerPromiseWithStubsTest.dart:Mint,Purse |
| 6 | 6 |
| 7 #library("MintMakerPromiseWithStubsTest-generatedTest"); | 7 #library("MintMakerPromiseWithStubsTest-generatedTest"); |
| 8 #import("dart:isolate"); | 8 #import("dart:isolate"); |
| 9 #import("../../../../proxy/promise.dart"); | 9 #import("../../../../proxy/promise.dart"); |
| 10 #import("../../../../../tests/isolate/src/TestFramework.dart"); | 10 #import("../../../../../lib/unittest/unittest.dart"); |
| 11 | 11 |
| 12 interface Mint default MintImpl { | 12 interface Mint default MintImpl { |
| 13 | 13 |
| 14 Mint(); | 14 Mint(); |
| 15 | 15 |
| 16 Purse createPurse(int balance); | 16 Purse createPurse(int balance); |
| 17 | 17 |
| 18 } | 18 } |
| 19 | 19 |
| 20 interface Purse default PurseImpl { | 20 interface Purse default PurseImpl { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 balance.complete(_balance); | 75 balance.complete(_balance); |
| 76 }); | 76 }); |
| 77 return balance; | 77 return balance; |
| 78 } | 78 } |
| 79 | 79 |
| 80 Mint _mint; | 80 Mint _mint; |
| 81 int _balance; | 81 int _balance; |
| 82 | 82 |
| 83 } | 83 } |
| 84 | 84 |
| 85 class MintMakerPromiseWithStubsTest { | 85 _completesWithValue(Promise promise, var expected) { |
| 86 promise.then(expectAsync1((value) { |
| 87 Expect.equals(expected, value); |
| 88 })); |
| 89 } |
| 86 | 90 |
| 87 completesWithValue(TestExpectation expect, Promise promise, var expected) { | 91 main() { |
| 88 promise.then(expect.runs1((value) { | 92 test("MintMakerPromiseWithStubsTest", () { |
| 89 Expect.equals(expected, value); | |
| 90 })); | |
| 91 } | |
| 92 | |
| 93 static void testMain(TestExpectation expect) { | |
| 94 Mint$Proxy mint = new Mint$ProxyImpl.createIsolate(); | 93 Mint$Proxy mint = new Mint$ProxyImpl.createIsolate(); |
| 95 Purse$Proxy purse = mint.createPurse(100); | 94 Purse$Proxy purse = mint.createPurse(100); |
| 96 completesWithValue(expect, purse.queryBalance(), 100); | 95 _completesWithValue(purse.queryBalance(), 100); |
| 97 | 96 |
| 98 Purse$Proxy sprouted = purse.sproutPurse(); | 97 Purse$Proxy sprouted = purse.sproutPurse(); |
| 99 completesWithValue(expect, sprouted.queryBalance(), 0); | 98 _completesWithValue(sprouted.queryBalance(), 0); |
| 100 | 99 |
| 101 // FIXME(benl): We should not have to manually order the calls | 100 // FIXME(benl): We should not have to manually order the calls |
| 102 // like this. | 101 // like this. |
| 103 Promise<int> result = sprouted.deposit(5, purse); | 102 Promise<int> result = sprouted.deposit(5, purse); |
| 104 Promise p1 = result; | 103 Promise p1 = result; |
| 105 completesWithValue(expect, result, 5); | 104 _completesWithValue(result, 5); |
| 106 Promise<bool> p2 = new Promise<bool>(); | 105 Promise<bool> p2 = new Promise<bool>(); |
| 107 Promise<bool> p3 = new Promise<bool>(); | 106 Promise<bool> p3 = new Promise<bool>(); |
| 108 Promise<bool> p4 = new Promise<bool>(); | 107 Promise<bool> p4 = new Promise<bool>(); |
| 109 Promise<bool> p5 = new Promise<bool>(); | 108 Promise<bool> p5 = new Promise<bool>(); |
| 110 Promise<bool> p6 = new Promise<bool>(); | 109 Promise<bool> p6 = new Promise<bool>(); |
| 111 result.addCompleteHandler((unused) { | 110 result.addCompleteHandler((unused) { |
| 112 Promise<int> bal1 = sprouted.queryBalance(); | 111 Promise<int> bal1 = sprouted.queryBalance(); |
| 113 completesWithValue(expect, bal1, 0 + 5); | 112 _completesWithValue(bal1, 0 + 5); |
| 114 bal1.then(expect.runs1((unused_) => p2.complete(true))); | 113 bal1.then(expectAsync1((unused_) => p2.complete(true))); |
| 115 Promise<int> bal2 = purse.queryBalance(); | 114 Promise<int> bal2 = purse.queryBalance(); |
| 116 completesWithValue(expect, bal2, 100 - 5); | 115 _completesWithValue(bal2, 100 - 5); |
| 117 bal2.then(expect.runs1((unused_) => p3.complete(true))); | 116 bal2.then(expectAsync1((unused_) => p3.complete(true))); |
| 118 | 117 |
| 119 result = sprouted.deposit(42, purse); | 118 result = sprouted.deposit(42, purse); |
| 120 completesWithValue(expect, result, 5 + 42); | 119 _completesWithValue(result, 5 + 42); |
| 121 result.then(expect.runs1((unused__) => p4.complete(true))); | 120 result.then(expectAsync1((unused__) => p4.complete(true))); |
| 122 result.addCompleteHandler((unused_) { | 121 result.addCompleteHandler((unused_) { |
| 123 Promise<int> bal3 = sprouted.queryBalance(); | 122 Promise<int> bal3 = sprouted.queryBalance(); |
| 124 completesWithValue(expect, bal3, 0 + 5 + 42); | 123 _completesWithValue(bal3, 0 + 5 + 42); |
| 125 bal3.then(expect.runs1((unused___) => p5.complete(true))); | 124 bal3.then(expectAsync1((unused___) => p5.complete(true))); |
| 126 Promise<int> bal4 = purse.queryBalance(); | 125 Promise<int> bal4 = purse.queryBalance(); |
| 127 completesWithValue(expect, bal4, 100 - 5 - 42); | 126 _completesWithValue(bal4, 100 - 5 - 42); |
| 128 bal4.then(expect.runs1((unused___) => p6.complete(true))); | 127 bal4.then(expectAsync1((unused___) => p6.complete(true))); |
| 129 }); | 128 }); |
| 130 }); | 129 }); |
| 131 Promise<bool> done = new Promise<bool>(); | 130 Promise<bool> done = new Promise<bool>(); |
| 132 done.waitFor([p1, p2, p3, p4, p5, p6], 6); | 131 done.waitFor([p1, p2, p3, p4, p5, p6], 6); |
| 133 done.then((_) { | 132 done.then((_) { |
| 134 expect.succeeded(); | |
| 135 print("##DONE##"); | 133 print("##DONE##"); |
| 136 }); | 134 }); |
| 137 } | 135 }); |
| 138 | |
| 139 } | 136 } |
| 140 | |
| 141 main() { | |
| 142 runTests([MintMakerPromiseWithStubsTest.testMain]); | |
| 143 } | |
| OLD | NEW |