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

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

Issue 10226008: Revert "unittest step 3 and 4: remove TestFramework.dart, make test.dart use" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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('../../../lib/unittest/unittest.dart'); 10 #import("TestFramework.dart");
11 11
12 // --------------------------------------------------------------------------- 12 // ---------------------------------------------------------------------------
13 // Message passing test. 13 // Message passing test.
14 // --------------------------------------------------------------------------- 14 // ---------------------------------------------------------------------------
15 15
16 class MessageTest { 16 class MessageTest {
17 static void test(TestExpectation expect) {
18 PingPongClient.test(expect);
19 }
20
17 static final List list1 = const ["Hello", "World", "Hello", 0xfffffffffff]; 21 static final List list1 = const ["Hello", "World", "Hello", 0xfffffffffff];
18 static final List list2 = const [null, list1, list1, list1, list1]; 22 static final List list2 = const [null, list1, list1, list1, list1];
19 static final List list3 = const [list2, 2.0, true, false, 0xfffffffffff]; 23 static final List list3 = const [list2, 2.0, true, false, 0xfffffffffff];
20 static final Map map1 = const { 24 static final Map map1 = const {
21 "a=1" : 1, "b=2" : 2, "c=3" : 3, 25 "a=1" : 1, "b=2" : 2, "c=3" : 3,
22 }; 26 };
23 static final Map map2 = const { 27 static final Map map2 = const {
24 "list1" : list1, "list2" : list2, "list3" : list3, 28 "list1" : list1, "list2" : list2, "list3" : list3,
25 }; 29 };
26 static final List list4 = const [map1, map2]; 30 static final List list4 = const [map1, map2];
(...skipping 29 matching lines...) Expand all
56 60
57 static void VerifyObject(int index, var actual) { 61 static void VerifyObject(int index, var actual) {
58 var expected = elms[index]; 62 var expected = elms[index];
59 Expect.equals(true, expected is List); 63 Expect.equals(true, expected is List);
60 Expect.equals(true, actual is List); 64 Expect.equals(true, actual is List);
61 Expect.equals(expected.length, actual.length); 65 Expect.equals(expected.length, actual.length);
62 VerifyList(expected, actual); 66 VerifyList(expected, actual);
63 } 67 }
64 } 68 }
65 69
66 class PingPongServer extends Isolate { 70 class PingPongClient {
67 PingPongServer() : super() {} 71 static void test(TestExpectation expect) {
68 72 expect.completes(new PingPongServer().spawn()).then((SendPort remote) {
69 void main() {
70 int count = 0;
71 this.port.receive(
72 (var message, SendPort replyTo) {
73 if (message == -1) {
74 this.port.close();
75 replyTo.send(count, null);
76 } else {
77 // Check if the received object is correct.
78 if (count < MessageTest.elms.length) {
79 MessageTest.VerifyObject(count, message);
80 }
81 // Bounce the received object back so that the sender
82 // can make sure that the object matches.
83 replyTo.send(message, null);
84 count++;
85 }
86 });
87 }
88 }
89
90 main() {
91 test("send objects and receive them back", () {
92 new PingPongServer().spawn().then(expectAsync1((SendPort remote) {
93 73
94 // Send objects and receive them back. 74 // Send objects and receive them back.
95 for (int i = 0; i < MessageTest.elms.length; i++) { 75 for (int i = 0; i < MessageTest.elms.length; i++) {
96 var sentObject = MessageTest.elms[i]; 76 var sentObject = MessageTest.elms[i];
97 // 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
98 // semantics for closures is implemented. 78 // semantics for closures is implemented.
99 var idx = i; 79 var idx = i;
100 remote.call(sentObject).then(expectAsync1((var receivedObject) { 80 remote.call(sentObject).then(expect.runs1((var receivedObject) {
101 MessageTest.VerifyObject(idx, receivedObject); 81 MessageTest.VerifyObject(idx, receivedObject);
102 })); 82 }));
103 } 83 }
104 84
105 // Send recursive objects and receive them back. 85 // Send recursive objects and receive them back.
106 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff]; 86 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff];
107 List local_list2 = [null, local_list1, local_list1 ]; 87 List local_list2 = [null, local_list1, local_list1 ];
108 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff]; 88 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff];
109 List sendObject = new List(5); 89 List sendObject = new List(5);
110 sendObject[0] = local_list1; 90 sendObject[0] = local_list1;
111 sendObject[1] = sendObject; 91 sendObject[1] = sendObject;
112 sendObject[2] = local_list2; 92 sendObject[2] = local_list2;
113 sendObject[3] = sendObject; 93 sendObject[3] = sendObject;
114 sendObject[4] = local_list3; 94 sendObject[4] = local_list3;
115 remote.call(sendObject).then((var replyObject) { 95 remote.call(sendObject).then((var replyObject) {
116 Expect.equals(true, sendObject is List); 96 Expect.equals(true, sendObject is List);
117 Expect.equals(true, replyObject is List); 97 Expect.equals(true, replyObject is List);
118 Expect.equals(sendObject.length, replyObject.length); 98 Expect.equals(sendObject.length, replyObject.length);
119 Expect.equals(true, replyObject[1] === replyObject); 99 Expect.equals(true, replyObject[1] === replyObject);
120 Expect.equals(true, replyObject[3] === replyObject); 100 Expect.equals(true, replyObject[3] === replyObject);
121 Expect.equals(true, replyObject[0] === replyObject[2][1]); 101 Expect.equals(true, replyObject[0] === replyObject[2][1]);
122 Expect.equals(true, replyObject[0] === replyObject[2][2]); 102 Expect.equals(true, replyObject[0] === replyObject[2][2]);
123 Expect.equals(true, replyObject[2] === replyObject[4][0]); 103 Expect.equals(true, replyObject[2] === replyObject[4][0]);
124 Expect.equals(true, replyObject[0][0] === replyObject[0][2]); 104 Expect.equals(true, replyObject[0][0] === replyObject[0][2]);
125 // Bigint literals are not canonicalized so do a == check. 105 // Bigint literals are not canonicalized so do a == check.
126 Expect.equals(true, replyObject[0][3] == replyObject[4][4]); 106 Expect.equals(true, replyObject[0][3] == replyObject[4][4]);
127 }); 107 });
128 108
129 // Shutdown the MessageServer. 109 // Shutdown the MessageServer.
130 remote.call(-1).then(expectAsync1((int message) { 110 remote.call(-1).then(expect.runs1((int message) {
131 Expect.equals(MessageTest.elms.length + 1, message); 111 Expect.equals(MessageTest.elms.length + 1, message);
112 expect.succeeded();
132 })); 113 }));
133 })); 114 });
134 }); 115 }
135 } 116 }
117
118 class PingPongServer extends Isolate {
119 PingPongServer() : super() {}
120
121 void main() {
122 int count = 0;
123 this.port.receive(
124 (var message, SendPort replyTo) {
125 if (message == -1) {
126 this.port.close();
127 replyTo.send(count, null);
128 } else {
129 // Check if the received object is correct.
130 if (count < MessageTest.elms.length) {
131 MessageTest.VerifyObject(count, message);
132 }
133 // Bounce the received object back so that the sender
134 // can make sure that the object matches.
135 replyTo.send(message, null);
136 count++;
137 }
138 });
139 }
140 }
141
142 main() {
143 runTests([MessageTest.test]);
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