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

Side by Side Diff: tests/isolate/message_test.dart

Issue 10837070: Remove old isolate API and update all code in the repository to use (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 8 years, 4 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/message2_test.dart ('k') | tests/isolate/mint_maker_test.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) 2012, 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('../../lib/unittest/unittest.dart'); 10 #import('../../lib/unittest/unittest.dart');
11 11
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 static void VerifyObject(int index, var actual) { 57 static void VerifyObject(int index, var actual) {
58 var expected = elms[index]; 58 var expected = elms[index];
59 Expect.equals(true, expected is List); 59 Expect.equals(true, expected is List);
60 Expect.equals(true, actual is List); 60 Expect.equals(true, actual is List);
61 Expect.equals(expected.length, actual.length); 61 Expect.equals(expected.length, actual.length);
62 VerifyList(expected, actual); 62 VerifyList(expected, actual);
63 } 63 }
64 } 64 }
65 65
66 class PingPongServer extends Isolate { 66 pingPong() {
67 PingPongServer() : super() {} 67 int count = 0;
68 68 port.receive((var message, SendPort replyTo) {
69 void main() { 69 if (message == -1) {
70 int count = 0; 70 port.close();
71 this.port.receive( 71 replyTo.send(count, null);
72 (var message, SendPort replyTo) { 72 } else {
73 if (message == -1) { 73 // Check if the received object is correct.
74 this.port.close(); 74 if (count < MessageTest.elms.length) {
75 replyTo.send(count, null); 75 MessageTest.VerifyObject(count, message);
76 } else { 76 }
77 // Check if the received object is correct. 77 // Bounce the received object back so that the sender
78 if (count < MessageTest.elms.length) { 78 // can make sure that the object matches.
79 MessageTest.VerifyObject(count, message); 79 replyTo.send(message, null);
80 } 80 count++;
81 // Bounce the received object back so that the sender 81 }
82 // can make sure that the object matches. 82 });
83 replyTo.send(message, null);
84 count++;
85 }
86 });
87 }
88 } 83 }
89 84
90 main() { 85 main() {
91 test("send objects and receive them back", () { 86 test("send objects and receive them back", () {
92 new PingPongServer().spawn().then(expectAsync1((SendPort remote) { 87 SendPort remote = spawnFunction(pingPong);
88 // Send objects and receive them back.
89 for (int i = 0; i < MessageTest.elms.length; i++) {
90 var sentObject = MessageTest.elms[i];
91 // TODO(asiva): remove this local var idx once thew new for-loop
92 // semantics for closures is implemented.
93 var idx = i;
94 remote.call(sentObject).then(expectAsync1((var receivedObject) {
95 MessageTest.VerifyObject(idx, receivedObject);
96 }));
97 }
93 98
94 // Send objects and receive them back. 99 // Send recursive objects and receive them back.
95 for (int i = 0; i < MessageTest.elms.length; i++) { 100 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff];
96 var sentObject = MessageTest.elms[i]; 101 List local_list2 = [null, local_list1, local_list1 ];
97 // TODO(asiva): remove this local var idx once thew new for-loop 102 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff];
98 // semantics for closures is implemented. 103 List sendObject = new List(5);
99 var idx = i; 104 sendObject[0] = local_list1;
100 remote.call(sentObject).then(expectAsync1((var receivedObject) { 105 sendObject[1] = sendObject;
101 MessageTest.VerifyObject(idx, receivedObject); 106 sendObject[2] = local_list2;
102 })); 107 sendObject[3] = sendObject;
103 } 108 sendObject[4] = local_list3;
109 remote.call(sendObject).then((var replyObject) {
110 Expect.equals(true, sendObject is List);
111 Expect.equals(true, replyObject is List);
112 Expect.equals(sendObject.length, replyObject.length);
113 Expect.equals(true, replyObject[1] === replyObject);
114 Expect.equals(true, replyObject[3] === replyObject);
115 Expect.equals(true, replyObject[0] === replyObject[2][1]);
116 Expect.equals(true, replyObject[0] === replyObject[2][2]);
117 Expect.equals(true, replyObject[2] === replyObject[4][0]);
118 Expect.equals(true, replyObject[0][0] === replyObject[0][2]);
119 // Bigint literals are not canonicalized so do a == check.
120 Expect.equals(true, replyObject[0][3] == replyObject[4][4]);
121 });
104 122
105 // Send recursive objects and receive them back. 123 // Shutdown the MessageServer.
106 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff]; 124 remote.call(-1).then(expectAsync1((int message) {
107 List local_list2 = [null, local_list1, local_list1 ]; 125 Expect.equals(MessageTest.elms.length + 1, message);
108 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff]; 126 }));
109 List sendObject = new List(5);
110 sendObject[0] = local_list1;
111 sendObject[1] = sendObject;
112 sendObject[2] = local_list2;
113 sendObject[3] = sendObject;
114 sendObject[4] = local_list3;
115 remote.call(sendObject).then((var replyObject) {
116 Expect.equals(true, sendObject is List);
117 Expect.equals(true, replyObject is List);
118 Expect.equals(sendObject.length, replyObject.length);
119 Expect.equals(true, replyObject[1] === replyObject);
120 Expect.equals(true, replyObject[3] === replyObject);
121 Expect.equals(true, replyObject[0] === replyObject[2][1]);
122 Expect.equals(true, replyObject[0] === replyObject[2][2]);
123 Expect.equals(true, replyObject[2] === replyObject[4][0]);
124 Expect.equals(true, replyObject[0][0] === replyObject[0][2]);
125 // Bigint literals are not canonicalized so do a == check.
126 Expect.equals(true, replyObject[0][3] == replyObject[4][4]);
127 });
128
129 // Shutdown the MessageServer.
130 remote.call(-1).then(expectAsync1((int message) {
131 Expect.equals(MessageTest.elms.length + 1, message);
132 }));
133 }));
134 }); 127 });
135 } 128 }
OLDNEW
« no previous file with comments | « tests/isolate/message2_test.dart ('k') | tests/isolate/mint_maker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698