| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 void succeeded() { | 166 void succeeded() { |
| 167 Expect.equals(0, pendingCallbacks); | 167 Expect.equals(0, pendingCallbacks); |
| 168 hasSucceeded = true; | 168 hasSucceeded = true; |
| 169 testCase.tearDown(); | 169 testCase.tearDown(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void failed() { | 172 void failed() { |
| 173 testCase.tearDown(); | 173 testCase.tearDown(); |
| 174 } | 174 } |
| 175 | 175 |
| 176 Future completes(var future) { | 176 Future completes(Future future) { |
| 177 if (!(future is Promise || future is Future)) { | |
| 178 // TODO(mattsh) - remove this hack once we finish conversion of | |
| 179 // Promise to Future | |
| 180 throw "must pass Promise or Future to TestFramework.completes"; | |
| 181 } | |
| 182 Completer completer = new Completer(); | 177 Completer completer = new Completer(); |
| 183 future.then(runs1((value) { | 178 future.then(runs1((value) { |
| 184 completer.complete(value); | 179 completer.complete(value); |
| 185 })); | 180 })); |
| 186 return completer.future; | 181 return completer.future; |
| 187 } | 182 } |
| 188 | 183 |
| 189 Promise completesWithValue(Promise promise, var expected) { | |
| 190 Promise promiseResult = new TestPromise(this); | |
| 191 promise.then((value) { | |
| 192 Expect.equals(expected, value); | |
| 193 promiseResult.complete(value); | |
| 194 }); | |
| 195 return promiseResult; | |
| 196 } | |
| 197 | |
| 198 Function runs0(Function fn) { | 184 Function runs0(Function fn) { |
| 199 bool ran = false; // We only check that the function is executed once. | 185 bool ran = false; // We only check that the function is executed once. |
| 200 pendingCallbacks++; | 186 pendingCallbacks++; |
| 201 return () { | 187 return () { |
| 202 if (!ran) pendingCallbacks--; | 188 if (!ran) pendingCallbacks--; |
| 203 ran = true; | 189 ran = true; |
| 204 return result.runGuarded(testCase, () => fn()); | 190 return result.runGuarded(testCase, () => fn()); |
| 205 }; | 191 }; |
| 206 } | 192 } |
| 207 | 193 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 void performTest() { | 265 void performTest() { |
| 280 Expect.fail('performTest called in AsynchronousTestCase'); | 266 Expect.fail('performTest called in AsynchronousTestCase'); |
| 281 } | 267 } |
| 282 | 268 |
| 283 AsynchronousTestFunction test; | 269 AsynchronousTestFunction test; |
| 284 | 270 |
| 285 static int running = 0; | 271 static int running = 0; |
| 286 static ReceivePort keepalive = null; | 272 static ReceivePort keepalive = null; |
| 287 | 273 |
| 288 } | 274 } |
| 289 | |
| 290 // TODO(mattsh) - remove this once we have migrated the rpc system | |
| 291 class TestPromise<T> extends PromiseImpl<T> { | |
| 292 | |
| 293 TestPromise(this.expect) : super(); | |
| 294 | |
| 295 void addCompleteHandler(void completeHandler(T result)) { | |
| 296 super.addCompleteHandler(expect.runs1((T result) { | |
| 297 completeHandler(result); | |
| 298 })); | |
| 299 } | |
| 300 | |
| 301 final TestExpectation expect; | |
| 302 | |
| 303 } | |
| OLD | NEW |