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

Side by Side Diff: tests/isolate/src/PromiseBasedTest.dart

Issue 8478014: convert isolate TestFramework from Promise Future (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: change TestFramework to Future Created 9 years, 1 month 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
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("PromiseBasedTest"); 5 #library("PromiseBasedTest");
6 #import("TestFramework.dart"); 6 #import("TestFramework.dart");
7 7
8 class TestIsolate extends Isolate { 8 class TestIsolate extends Isolate {
9 9
10 TestIsolate() : super(); 10 TestIsolate() : super();
(...skipping 15 matching lines...) Expand all
26 } 26 }
27 }); 27 });
28 } 28 }
29 29
30 } 30 }
31 31
32 void test(TestExpectation expect) { 32 void test(TestExpectation expect) {
33 Proxy proxy = new Proxy.forIsolate(new TestIsolate()); 33 Proxy proxy = new Proxy.forIsolate(new TestIsolate());
34 proxy.send([42]); // Seed the isolate. 34 proxy.send([42]); // Seed the isolate.
35 Promise<int> result = new PromiseProxy<int>(proxy.call([87])); 35 Promise<int> result = new PromiseProxy<int>(proxy.call([87]));
36 Promise promise = expect.completes(result).then((int value) { 36 Completer completer = new Completer();
37 expect.completes(result).then((int value) {
37 //print("expect 1: $value"); 38 //print("expect 1: $value");
38 Expect.equals(42 + 87, value); 39 Expect.equals(42 + 87, value);
39 return 99; 40 completer.complete(99);
40 }); 41 });
41 expect.completes(promise).then((int value) { 42 expect.completes(completer.future).then((int value) {
42 //print("expect 2: $value"); 43 //print("expect 2: $value");
43 Expect.equals(99, value); 44 Expect.equals(99, value);
44 expect.succeeded(); 45 expect.succeeded();
45 }); 46 });
46 } 47 }
47 48
48 void expandedTest(TestExpectation expect) { 49 void expandedTest(TestExpectation expect) {
49 Proxy proxy = new Proxy.forIsolate(new TestIsolate()); 50 Proxy proxy = new Proxy.forIsolate(new TestIsolate());
50 proxy.send([42]); // Seed the isolate. 51 proxy.send([42]); // Seed the isolate.
51 Promise<SendPort> sendCompleter = proxy.call([87]); 52 Promise<SendPort> sendCompleter = proxy.call([87]);
52 Promise<int> result = new Promise<int>(); 53 Promise<int> result = new Promise<int>();
53 ReceivePort completer = new ReceivePort.singleShot(); 54 ReceivePort receivePort = new ReceivePort.singleShot();
54 completer.receive((var msg, SendPort _) { 55 receivePort.receive((var msg, SendPort _) {
55 //print("test completer"); 56 //print("test completer");
56 result.complete(msg[0]); 57 result.complete(msg[0]);
57 }); 58 });
58 sendCompleter.addCompleteHandler((SendPort port) { 59 sendCompleter.addCompleteHandler((SendPort port) {
59 //print("test send"); 60 //print("test send");
60 port.send([completer.toSendPort()], null); 61 port.send([receivePort.toSendPort()], null);
61 }); 62 });
62 Promise promise = expect.completes(result).then((int value) { 63 Completer completer = new Completer();
64 expect.completes(result).then((int value) {
63 //print("expect 1: $value"); 65 //print("expect 1: $value");
64 Expect.equals(42 + 87, value); 66 Expect.equals(42 + 87, value);
65 return 99; 67 completer.complete(99);
66 }); 68 });
67 expect.completes(promise).then((int value) { 69 expect.completes(completer.future).then((int value) {
68 //print("expect 2: $value"); 70 //print("expect 2: $value");
69 Expect.equals(99, value); 71 Expect.equals(99, value);
70 expect.succeeded(); 72 expect.succeeded();
71 }); 73 });
72 } 74 }
73 75
74 void main() { 76 void main() {
75 runTests([test, expandedTest]); 77 runTests([test, expandedTest]);
76 } 78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698