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

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

Issue 10153005: 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, 8 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
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('../../../lib/unittest/unittest.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
21 static final List list1 = const ["Hello", "World", "Hello", 0xfffffffffff]; 17 static final List list1 = const ["Hello", "World", "Hello", 0xfffffffffff];
22 static final List list2 = const [null, list1, list1, list1, list1]; 18 static final List list2 = const [null, list1, list1, list1, list1];
23 static final List list3 = const [list2, 2.0, true, false, 0xfffffffffff]; 19 static final List list3 = const [list2, 2.0, true, false, 0xfffffffffff];
24 static final Map map1 = const { 20 static final Map map1 = const {
25 "a=1" : 1, "b=2" : 2, "c=3" : 3, 21 "a=1" : 1, "b=2" : 2, "c=3" : 3,
26 }; 22 };
27 static final Map map2 = const { 23 static final Map map2 = const {
28 "list1" : list1, "list2" : list2, "list3" : list3, 24 "list1" : list1, "list2" : list2, "list3" : list3,
29 }; 25 };
30 static final List list4 = const [map1, map2]; 26 static final List list4 = const [map1, map2];
(...skipping 29 matching lines...) Expand all
60 56
61 static void VerifyObject(int index, var actual) { 57 static void VerifyObject(int index, var actual) {
62 var expected = elms[index]; 58 var expected = elms[index];
63 Expect.equals(true, expected is List); 59 Expect.equals(true, expected is List);
64 Expect.equals(true, actual is List); 60 Expect.equals(true, actual is List);
65 Expect.equals(expected.length, actual.length); 61 Expect.equals(expected.length, actual.length);
66 VerifyList(expected, actual); 62 VerifyList(expected, actual);
67 } 63 }
68 } 64 }
69 65
70 class PingPongClient { 66 class PingPongServer extends Isolate {
71 static void test(TestExpectation expect) { 67 PingPongServer() : super() {}
72 expect.completes(new PingPongServer().spawn()).then((SendPort remote) { 68
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(later1((SendPort remote) {
73 93
74 // Send objects and receive them back. 94 // Send objects and receive them back.
75 for (int i = 0; i < MessageTest.elms.length; i++) { 95 for (int i = 0; i < MessageTest.elms.length; i++) {
76 var sentObject = MessageTest.elms[i]; 96 var sentObject = MessageTest.elms[i];
77 // TODO(asiva): remove this local var idx once thew new for-loop 97 // TODO(asiva): remove this local var idx once thew new for-loop
78 // semantics for closures is implemented. 98 // semantics for closures is implemented.
79 var idx = i; 99 var idx = i;
80 remote.call(sentObject).then(expect.runs1((var receivedObject) { 100 remote.call(sentObject).then(later1((var receivedObject) {
81 MessageTest.VerifyObject(idx, receivedObject); 101 MessageTest.VerifyObject(idx, receivedObject);
82 })); 102 }));
83 } 103 }
84 104
85 // Send recursive objects and receive them back. 105 // Send recursive objects and receive them back.
86 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff]; 106 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff];
87 List local_list2 = [null, local_list1, local_list1 ]; 107 List local_list2 = [null, local_list1, local_list1 ];
88 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff]; 108 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff];
89 List sendObject = new List(5); 109 List sendObject = new List(5);
90 sendObject[0] = local_list1; 110 sendObject[0] = local_list1;
91 sendObject[1] = sendObject; 111 sendObject[1] = sendObject;
92 sendObject[2] = local_list2; 112 sendObject[2] = local_list2;
93 sendObject[3] = sendObject; 113 sendObject[3] = sendObject;
94 sendObject[4] = local_list3; 114 sendObject[4] = local_list3;
95 remote.call(sendObject).then((var replyObject) { 115 remote.call(sendObject).then((var replyObject) {
96 Expect.equals(true, sendObject is List); 116 Expect.equals(true, sendObject is List);
Bob Nystrom 2012/04/20 22:31:36 This should only be indented +2, not +4.
Siggi Cherem (dart-lang) 2012/04/21 00:03:43 Done.
97 Expect.equals(true, replyObject is List); 117 Expect.equals(true, replyObject is List);
98 Expect.equals(sendObject.length, replyObject.length); 118 Expect.equals(sendObject.length, replyObject.length);
99 Expect.equals(true, replyObject[1] === replyObject); 119 Expect.equals(true, replyObject[1] === replyObject);
100 Expect.equals(true, replyObject[3] === replyObject); 120 Expect.equals(true, replyObject[3] === replyObject);
101 Expect.equals(true, replyObject[0] === replyObject[2][1]); 121 Expect.equals(true, replyObject[0] === replyObject[2][1]);
102 Expect.equals(true, replyObject[0] === replyObject[2][2]); 122 Expect.equals(true, replyObject[0] === replyObject[2][2]);
103 Expect.equals(true, replyObject[2] === replyObject[4][0]); 123 Expect.equals(true, replyObject[2] === replyObject[4][0]);
104 Expect.equals(true, replyObject[0][0] === replyObject[0][2]); 124 Expect.equals(true, replyObject[0][0] === replyObject[0][2]);
105 // Bigint literals are not canonicalized so do a == check. 125 // Bigint literals are not canonicalized so do a == check.
106 Expect.equals(true, replyObject[0][3] == replyObject[4][4]); 126 Expect.equals(true, replyObject[0][3] == replyObject[4][4]);
107 }); 127 });
108 128
109 // Shutdown the MessageServer. 129 // Shutdown the MessageServer.
110 remote.call(-1).then(expect.runs1((int message) { 130 remote.call(-1).then(later1((int message) {
111 Expect.equals(MessageTest.elms.length + 1, message); 131 Expect.equals(MessageTest.elms.length + 1, message);
112 expect.succeeded();
113 })); 132 }));
114 }); 133 }));
115 } 134 });
116 } 135 }
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

Powered by Google App Engine
This is Rietveld 408576698