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

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

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

Powered by Google App Engine
This is Rietveld 408576698