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

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

Issue 12919011: Remove streamSpawnUri and mangler. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 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/message_stream2_test.dart ('k') | tests/isolate/nested_spawn_stream2_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) 2012, 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 '../../pkg/unittest/lib/unittest.dart'; 10 import '../../pkg/unittest/lib/unittest.dart';
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 var expected = elms[index]; 58 var expected = elms[index];
59 expect(expected, isList); 59 expect(expected, isList);
60 expect(actual, isList); 60 expect(actual, isList);
61 expect(actual.length, expected.length); 61 expect(actual.length, expected.length);
62 VerifyList(expected, actual); 62 VerifyList(expected, actual);
63 } 63 }
64 } 64 }
65 65
66 pingPong() { 66 pingPong() {
67 int count = 0; 67 int count = 0;
68 port.receive((var message, SendPort replyTo) { 68 bool isFirst = true;
69 if (message == -1) { 69 IsolateSink replyTo;
70 port.close(); 70 stream.listen((var message) {
71 replyTo.send(count, null); 71 if (isFirst) {
72 } else { 72 isFirst = false;
73 // Check if the received object is correct. 73 replyTo = message;
74 if (count < MessageTest.elms.length) { 74 return;
75 MessageTest.VerifyObject(count, message);
76 }
77 // Bounce the received object back so that the sender
78 // can make sure that the object matches.
79 replyTo.send(message, null);
80 count++;
81 } 75 }
76 // Check if the received object is correct.
77 if (count < MessageTest.elms.length) {
78 MessageTest.VerifyObject(count, message);
79 }
80 // Bounce the received object back so that the sender
81 // can make sure that the object matches.
82 replyTo.add(message);
83 count++;
84 }, onDone: () {
85 replyTo.add(count);
86 replyTo.close();
82 }); 87 });
83 } 88 }
84 89
85 main() { 90 main() {
86 test("send objects and receive them back", () { 91 test("send objects and receive them back", () {
87 SendPort remote = spawnFunction(pingPong); 92 IsolateSink remote = streamSpawnFunction(pingPong);
93 MessageBox box = new MessageBox();
94 remote.add(box.sink);
95
88 // Send objects and receive them back. 96 // Send objects and receive them back.
89 for (int i = 0; i < MessageTest.elms.length; i++) { 97 for (int i = 0; i < MessageTest.elms.length; i++) {
90 var sentObject = MessageTest.elms[i]; 98 var sentObject = MessageTest.elms[i];
91 // TODO(asiva): remove this local var idx once thew new for-loop 99 // TODO(asiva): remove this local var idx once thew new for-loop
92 // semantics for closures is implemented. 100 // semantics for closures is implemented.
93 var idx = i; 101 var idx = i;
94 remote.call(sentObject).then(expectAsync1((var receivedObject) { 102 remote.add(sentObject);
95 MessageTest.VerifyObject(idx, receivedObject);
96 }));
97 } 103 }
98 104
99 // Send recursive objects and receive them back. 105 // Send recursive objects and receive them back.
100 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff]; 106 List local_list1 = ["Hello", "World", "Hello", 0xffffffffff];
101 List local_list2 = [null, local_list1, local_list1 ]; 107 List local_list2 = [null, local_list1, local_list1 ];
102 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff]; 108 List local_list3 = [local_list2, 2.0, true, false, 0xffffffffff];
103 List sendObject = new List(5); 109 List sendObject = new List(5);
104 sendObject[0] = local_list1; 110 sendObject[0] = local_list1;
105 sendObject[1] = sendObject; 111 sendObject[1] = sendObject;
106 sendObject[2] = local_list2; 112 sendObject[2] = local_list2;
107 sendObject[3] = sendObject; 113 sendObject[3] = sendObject;
108 sendObject[4] = local_list3; 114 sendObject[4] = local_list3;
109 remote.call(sendObject).then((var replyObject) { 115 remote.add(sendObject);
110 expect(sendObject, isList);
111 expect(replyObject, isList);
112 expect(sendObject.length, equals(replyObject.length));
113 expect(replyObject[1], same(replyObject));
114 expect(replyObject[3], same(replyObject));
115 expect(replyObject[0], same(replyObject[2][1]));
116 expect(replyObject[0], same(replyObject[2][2]));
117 expect(replyObject[2], same(replyObject[4][0]));
118 expect(replyObject[0][0], same(replyObject[0][2]));
119 // Bigint literals are not canonicalized so do a == check.
120 expect(replyObject[0][3], equals(replyObject[4][4]));
121 });
122 116
123 // Shutdown the MessageServer. 117 // Shutdown the MessageServer.
124 remote.call(-1).then(expectAsync1((int message) { 118 remote.close();
119
120 int receivedCounter = 0;
121 box.stream.listen((message) {
122 if (receivedCounter < MessageTest.elms.length) {
123 MessageTest.VerifyObject(receivedCounter, message);
124 } else if (receivedCounter == MessageTest.elms.length) {
125 var replyObject = message;
126 expect(sendObject, isList);
127 expect(replyObject, isList);
128 expect(sendObject.length, equals(replyObject.length));
129 expect(replyObject[1], same(replyObject));
130 expect(replyObject[3], same(replyObject));
131 expect(replyObject[0], same(replyObject[2][1]));
132 expect(replyObject[0], same(replyObject[2][2]));
133 expect(replyObject[2], same(replyObject[4][0]));
134 expect(replyObject[0][0], same(replyObject[0][2]));
135 // Bigint literals are not canonicalized so do a == check.
136 expect(replyObject[0][3], equals(replyObject[4][4]));
137 } else {
138 // Reply from done.
125 expect(message, MessageTest.elms.length + 1); 139 expect(message, MessageTest.elms.length + 1);
126 })); 140 }
141 receivedCounter++;
142 });
127 }); 143 });
128 } 144 }
OLDNEW
« no previous file with comments | « tests/isolate/message_stream2_test.dart ('k') | tests/isolate/nested_spawn_stream2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698