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

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

Issue 9652001: SendPort + ReceivePort changes: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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
« no previous file with comments | « tests/isolate/src/Message2Test.dart ('k') | tests/isolate/src/MintMakerTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Dart test program for testing serialization of messages. 5 // Dart test program for testing serialization of messages.
6 // VMOptions=--enable_type_checks --enable_asserts 6 // VMOptions=--enable_type_checks --enable_asserts
7 7
8 #library('MessageTest'); 8 #library('MessageTest');
9 #import("dart:isolate"); 9 #import("dart:isolate");
10 #import("TestFramework.dart"); 10 #import("TestFramework.dart");
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 class PingPongClient { 70 class PingPongClient {
71 static void test(TestExpectation expect) { 71 static void test(TestExpectation expect) {
72 expect.completes(new PingPongServer().spawn()).then((SendPort remote) { 72 expect.completes(new PingPongServer().spawn()).then((SendPort remote) {
73 73
74 // Send objects and receive them back. 74 // Send objects and receive them back.
75 for (int i = 0; i < MessageTest.elms.length; i++) { 75 for (int i = 0; i < MessageTest.elms.length; i++) {
76 var sentObject = MessageTest.elms[i]; 76 var sentObject = MessageTest.elms[i];
77 // TODO(asiva): remove this local var idx once thew new for-loop 77 // TODO(asiva): remove this local var idx once thew new for-loop
78 // semantics for closures is implemented. 78 // semantics for closures is implemented.
79 var idx = i; 79 var idx = i;
80 remote.call(sentObject).receive(expect.runs2( 80 remote.call(sentObject).then(expect.runs1((var receivedObject) {
81 (var receivedObject, SendPort replyTo) { 81 MessageTest.VerifyObject(idx, receivedObject);
82 MessageTest.VerifyObject(idx, receivedObject); 82 }));
83 }));
84 } 83 }
85 84
86 // Send recursive objects and receive them back. 85 // Send recursive objects and receive them back.
87 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff]; 86 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff];
88 List local_list2 = [null, local_list1, local_list1 ]; 87 List local_list2 = [null, local_list1, local_list1 ];
89 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff]; 88 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff];
90 List sendObject = new List(5); 89 List sendObject = new List(5);
91 sendObject[0] = local_list1; 90 sendObject[0] = local_list1;
92 sendObject[1] = sendObject; 91 sendObject[1] = sendObject;
93 sendObject[2] = local_list2; 92 sendObject[2] = local_list2;
94 sendObject[3] = sendObject; 93 sendObject[3] = sendObject;
95 sendObject[4] = local_list3; 94 sendObject[4] = local_list3;
96 remote.call(sendObject).receive( 95 remote.call(sendObject).then((var replyObject) {
97 (var replyObject, SendPort replyTo) { 96 Expect.equals(true, sendObject is List);
98 Expect.equals(true, sendObject is List); 97 Expect.equals(true, replyObject is List);
99 Expect.equals(true, replyObject is List); 98 Expect.equals(sendObject.length, replyObject.length);
100 Expect.equals(sendObject.length, replyObject.length); 99 Expect.equals(true, replyObject[1] === replyObject);
101 Expect.equals(true, replyObject[1] === replyObject); 100 Expect.equals(true, replyObject[3] === replyObject);
102 Expect.equals(true, replyObject[3] === replyObject); 101 Expect.equals(true, replyObject[0] === replyObject[2][1]);
103 Expect.equals(true, replyObject[0] === replyObject[2][1]); 102 Expect.equals(true, replyObject[0] === replyObject[2][2]);
104 Expect.equals(true, replyObject[0] === replyObject[2][2]); 103 Expect.equals(true, replyObject[2] === replyObject[4][0]);
105 Expect.equals(true, replyObject[2] === replyObject[4][0]); 104 Expect.equals(true, replyObject[0][0] === replyObject[0][2]);
106 Expect.equals(true, replyObject[0][0] === replyObject[0][2]); 105 // Bigint literals are not canonicalized so do a == check.
107 // Bigint literals are not canonicalized so do a == check. 106 Expect.equals(true, replyObject[0][3] == replyObject[4][4]);
108 Expect.equals(true, replyObject[0][3] == replyObject[4][4]); 107 });
109 });
110 108
111 // Shutdown the MessageServer. 109 // Shutdown the MessageServer.
112 remote.call(-1).receive(expect.runs2( 110 remote.call(-1).then(expect.runs1((int message) {
113 (int message, SendPort replyTo) { 111 Expect.equals(MessageTest.elms.length + 1, message);
114 Expect.equals(MessageTest.elms.length + 1, message); 112 expect.succeeded();
115 expect.succeeded(); 113 }));
116 }));
117 }); 114 });
118 } 115 }
119 } 116 }
120 117
121 class PingPongServer extends Isolate { 118 class PingPongServer extends Isolate {
122 PingPongServer() : super() {} 119 PingPongServer() : super() {}
123 120
124 void main() { 121 void main() {
125 int count = 0; 122 int count = 0;
126 this.port.receive( 123 this.port.receive(
(...skipping 11 matching lines...) Expand all
138 replyTo.send(message, null); 135 replyTo.send(message, null);
139 count++; 136 count++;
140 } 137 }
141 }); 138 });
142 } 139 }
143 } 140 }
144 141
145 main() { 142 main() {
146 runTests([MessageTest.test]); 143 runTests([MessageTest.test]);
147 } 144 }
OLDNEW
« no previous file with comments | « tests/isolate/src/Message2Test.dart ('k') | tests/isolate/src/MintMakerTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698