| OLD | NEW |
| 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 #library("TestFramework"); | 5 #library("TestFramework"); |
| 6 #import("dart:coreimpl"); | 6 #import("dart:coreimpl"); |
| 7 | 7 |
| 8 | 8 |
| 9 typedef void AsynchronousTestFunction(TestExpectation check); | 9 typedef void AsynchronousTestFunction(TestExpectation check); |
| 10 | 10 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 void succeeded() { | 167 void succeeded() { |
| 168 Expect.equals(0, pendingCallbacks); | 168 Expect.equals(0, pendingCallbacks); |
| 169 hasSucceeded = true; | 169 hasSucceeded = true; |
| 170 testCase.tearDown(); | 170 testCase.tearDown(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void failed() { | 173 void failed() { |
| 174 testCase.tearDown(); | 174 testCase.tearDown(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 Promise completes(var promise) { | 177 Future completes(var future) { |
| 178 if (!(promise is Promise || promise is Future)) { | 178 if (!(future is Promise || future is Future)) { |
| 179 // TODO(mattsh) - remove this hack once we finish conversion of | 179 // TODO(mattsh) - remove this hack once we finish conversion of |
| 180 // Promise to Future | 180 // Promise to Future |
| 181 throw "must pass Promise or Future to TestFramework.completes"; | 181 throw "must pass Promise or Future to TestFramework.completes"; |
| 182 } | 182 } |
| 183 | 183 Completer completer = new Completer(); |
| 184 Promise result = new TestPromise(this); | 184 future.then(runs1((value) { |
| 185 promise.then((value) { result.complete(value); }); | 185 completer.complete(value); |
| 186 return result; | 186 })); |
| 187 return completer.future; |
| 187 } | 188 } |
| 188 | 189 |
| 189 Promise completesWithValue(Promise promise, var expected) { | 190 Promise completesWithValue(Promise promise, var expected) { |
| 190 Promise result = new TestPromise(this); | 191 Promise result = new TestPromise(this); |
| 191 promise.then((value) { | 192 promise.then((value) { |
| 192 Expect.equals(expected, value); | 193 Expect.equals(expected, value); |
| 193 result.complete(value); | 194 result.complete(value); |
| 194 }); | 195 }); |
| 195 return result; | 196 return result; |
| 196 } | 197 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 276 } |
| 276 } | 277 } |
| 277 | 278 |
| 278 AsynchronousTestFunction test; | 279 AsynchronousTestFunction test; |
| 279 | 280 |
| 280 static int running = 0; | 281 static int running = 0; |
| 281 static ReceivePort keepalive = null; | 282 static ReceivePort keepalive = null; |
| 282 | 283 |
| 283 } | 284 } |
| 284 | 285 |
| 285 | 286 // TODO(mattsh) - remove this once we have migrated the rpc system |
| 286 class TestPromise<T> extends PromiseImpl<T> { | 287 class TestPromise<T> extends PromiseImpl<T> { |
| 287 | 288 |
| 288 TestPromise(this.expect) : super(); | 289 TestPromise(this.expect) : super(); |
| 289 | 290 |
| 290 void addCompleteHandler(void completeHandler(T result)) { | 291 void addCompleteHandler(void completeHandler(T result)) { |
| 291 super.addCompleteHandler(expect.runs1((T result) { | 292 super.addCompleteHandler(expect.runs1((T result) { |
| 292 completeHandler(result); | 293 completeHandler(result); |
| 293 })); | 294 })); |
| 294 } | 295 } |
| 295 | 296 |
| 296 final TestExpectation expect; | 297 final TestExpectation expect; |
| 297 | 298 |
| 298 } | 299 } |
| OLD | NEW |