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

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

Issue 2774783002: Re-land "Format all multitests" (Closed)
Patch Set: Created 3 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
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
9 import 'dart:async'; 10 import 'dart:async';
10 import 'dart:collection'; 11 import 'dart:collection';
11 import 'dart:isolate'; 12 import 'dart:isolate';
12 import 'package:async_helper/async_helper.dart'; 13 import 'package:async_helper/async_helper.dart';
13 import 'package:expect/expect.dart'; 14 import 'package:expect/expect.dart';
14 import 'dart:typed_data'; 15 import 'dart:typed_data';
15 16
16 void echoMain(msg) { 17 void echoMain(msg) {
17 SendPort replyTo = msg[0]; 18 SendPort replyTo = msg[0];
18 SendPort pong = msg[1]; 19 SendPort pong = msg[1];
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 var gee = 123; 56 var gee = 123;
56 } 57 }
57 58
58 class E { 59 class E {
59 Function fun; 60 Function fun;
60 E(this.fun); 61 E(this.fun);
61 62
62 static fooFun() => 499; 63 static fooFun() => 499;
63 instanceFun() => 1234; 64 instanceFun() => 1234;
64 } 65 }
66
65 barFun() => 42; 67 barFun() => 42;
66 68
67 class F { 69 class F {
68 final field = "field"; 70 final field = "field";
69 const F(); 71 const F();
70 } 72 }
71 73
72 class G { 74 class G {
73 final field; 75 final field;
74 const G(this.field); 76 const G(this.field);
75 } 77 }
76 78
77 class Value { 79 class Value {
78 final val; 80 final val;
79 Value(this.val); 81 Value(this.val);
80 82
81 operator==(other) { 83 operator ==(other) {
82 if (other is! Value) return false; 84 if (other is! Value) return false;
83 return other.val == val; 85 return other.val == val;
84 } 86 }
85 87
86 get hashCode => val; 88 get hashCode => val;
87 } 89 }
88 90
89 void runTests(SendPort ping, Queue checks) { 91 void runTests(SendPort ping, Queue checks) {
90 ping.send("abc"); 92 ping.send("abc");
91 checks.add((x) => Expect.equals("abc", x)); 93 checks.add((x) => Expect.equals("abc", x));
(...skipping 14 matching lines...) Expand all
106 fixed[0] = 0; 108 fixed[0] = 0;
107 fixed[1] = 1; 109 fixed[1] = 1;
108 ping.send(fixed); 110 ping.send(fixed);
109 checks.add((x) { 111 checks.add((x) {
110 Expect.isTrue(x is List); 112 Expect.isTrue(x is List);
111 Expect.listEquals([0, 1], x); 113 Expect.listEquals([0, 1], x);
112 // List must be mutable. 114 // List must be mutable.
113 x[0] = 3; 115 x[0] = 3;
114 Expect.equals(3, x[0]); 116 Expect.equals(3, x[0]);
115 // List must be fixed length. 117 // List must be fixed length.
116 Expect.throws(() { x.add(5); }); 118 Expect.throws(() {
119 x.add(5);
120 });
117 }); 121 });
118 122
119 List cyclic = []; 123 List cyclic = [];
120 cyclic.add(cyclic); 124 cyclic.add(cyclic);
121 ping.send(cyclic); 125 ping.send(cyclic);
122 checks.add((x) { 126 checks.add((x) {
123 Expect.isTrue(x is List); 127 Expect.isTrue(x is List);
124 Expect.equals(1, x.length); 128 Expect.equals(1, x.length);
125 Expect.identical(x, x[0]); 129 Expect.identical(x, x[0]);
126 // List must be mutable. 130 // List must be mutable.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 ping.send(byteBuffer); // //# byteBuffer: ok 179 ping.send(byteBuffer); // //# byteBuffer: ok
176 checks.add( // //# byteBuffer: ok 180 checks.add( // //# byteBuffer: ok
177 (x) { 181 (x) {
178 Expect.isTrue(x is ByteBuffer); 182 Expect.isTrue(x is ByteBuffer);
179 Uint16List uint16View = new Uint16List.view(x); 183 Uint16List uint16View = new Uint16List.view(x);
180 Expect.equals(2, uint16View.length); 184 Expect.equals(2, uint16View.length);
181 Expect.equals(0, uint16View[0]); 185 Expect.equals(0, uint16View[0]);
182 Expect.equals(1, uint16View[1]); 186 Expect.equals(1, uint16View[1]);
183 } 187 }
184 ) // //# byteBuffer: ok 188 ) // //# byteBuffer: ok
185 ; 189 ;
186 190
187 Int32x4List list32x4 = new Int32x4List(2); 191 Int32x4List list32x4 = new Int32x4List(2);
188 list32x4[0] = new Int32x4(1, 2, 3, 4); 192 list32x4[0] = new Int32x4(1, 2, 3, 4);
189 list32x4[1] = new Int32x4(5, 6, 7, 8); 193 list32x4[1] = new Int32x4(5, 6, 7, 8);
190 ping.send(list32x4); // //# int32x4: ok 194 ping.send(list32x4); // //# int32x4: ok
191 checks.add( // //# int32x4: ok 195 checks.add( // //# int32x4: ok
192 (x) { 196 (x) {
193 Expect.isTrue(x is Int32x4List); 197 Expect.isTrue(x is Int32x4List);
194 Expect.equals(2, x.length); 198 Expect.equals(2, x.length);
195 Int32x4 entry1 = x[0]; 199 Int32x4 entry1 = x[0];
196 Int32x4 entry2 = x[1]; 200 Int32x4 entry2 = x[1];
197 Expect.equals(1, entry1.x); 201 Expect.equals(1, entry1.x);
198 Expect.equals(2, entry1.y); 202 Expect.equals(2, entry1.y);
199 Expect.equals(3, entry1.z); 203 Expect.equals(3, entry1.z);
200 Expect.equals(4, entry1.w); 204 Expect.equals(4, entry1.w);
201 Expect.equals(5, entry2.x); 205 Expect.equals(5, entry2.x);
202 Expect.equals(6, entry2.y); 206 Expect.equals(6, entry2.y);
203 Expect.equals(7, entry2.z); 207 Expect.equals(7, entry2.z);
204 Expect.equals(8, entry2.w); 208 Expect.equals(8, entry2.w);
205 } 209 }
206 ) // //# int32x4: ok 210 ) // //# int32x4: ok
207 ; 211 ;
208 212
209 ping.send({"foo": 499, "bar": 32}); 213 ping.send({"foo": 499, "bar": 32});
210 checks.add((x) { 214 checks.add((x) {
211 Expect.isTrue(x is LinkedHashMap); 215 Expect.isTrue(x is LinkedHashMap);
212 Expect.listEquals(["foo", "bar"], x.keys.toList()); 216 Expect.listEquals(["foo", "bar"], x.keys.toList());
213 Expect.listEquals([499, 32], x.values.toList()); 217 Expect.listEquals([499, 32], x.values.toList());
214 Expect.equals(499, x["foo"]); 218 Expect.equals(499, x["foo"]);
215 Expect.equals(32, x["bar"]); 219 Expect.equals(32, x["bar"]);
216 // Must be mutable. 220 // Must be mutable.
217 x["foo"] = 22; 221 x["foo"] = 22;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 Expect.identical(constF, x); // //# constInstance: ok 384 Expect.identical(constF, x); // //# constInstance: ok
381 }); 385 });
382 386
383 G g1 = new G(nonConstF); 387 G g1 = new G(nonConstF);
384 G g2 = new G(constF); 388 G g2 = new G(constF);
385 G g3 = const G(constF); 389 G g3 = const G(constF);
386 ping.send(g1); 390 ping.send(g1);
387 ping.send(g2); 391 ping.send(g2);
388 ping.send(g3); 392 ping.send(g3);
389 393
390 checks.add((x) { // g1. 394 checks.add((x) {
395 // g1.
391 Expect.isTrue(x is G); 396 Expect.isTrue(x is G);
392 Expect.isFalse(identical(g1, x)); 397 Expect.isFalse(identical(g1, x));
393 F f = x.field; 398 F f = x.field;
394 Expect.equals("field", f.field); 399 Expect.equals("field", f.field);
395 Expect.isFalse(identical(nonConstF, f)); 400 Expect.isFalse(identical(nonConstF, f));
396 }); 401 });
397 checks.add((x) { // g2. 402 checks.add((x) {
403 // g2.
398 Expect.isTrue(x is G); 404 Expect.isTrue(x is G);
399 Expect.isFalse(identical(g1, x)); 405 Expect.isFalse(identical(g1, x));
400 F f = x.field; 406 F f = x.field;
401 Expect.equals("field", f.field); 407 Expect.equals("field", f.field);
402 Expect.identical(constF, f); // //# constInstance: continued 408 Expect.identical(constF, f); // //# constInstance: continued
403 }); 409 });
404 checks.add((x) { // g3. 410 checks.add((x) {
411 // g3.
405 Expect.isTrue(x is G); 412 Expect.isTrue(x is G);
406 Expect.identical(g3, x); // //# constInstance: continued 413 Expect.identical(g3, x); // //# constInstance: continued
407 F f = x.field; 414 F f = x.field;
408 Expect.equals("field", f.field); 415 Expect.equals("field", f.field);
409 Expect.identical(constF, f); // //# constInstance: continued 416 Expect.identical(constF, f); // //# constInstance: continued
410 }); 417 });
411 418
412 // Make sure objects in a map are serialized and deserialized in the correct 419 // Make sure objects in a map are serialized and deserialized in the correct
413 // order. 420 // order.
414 Map m = new Map(); 421 Map m = new Map();
(...skipping 28 matching lines...) Expand all
443 Function check = checks.removeFirst(); 450 Function check = checks.removeFirst();
444 check(msg); 451 check(msg);
445 if (checks.isEmpty) { 452 if (checks.isEmpty) {
446 completer.complete(); 453 completer.complete();
447 testPort.close(); 454 testPort.close();
448 } 455 }
449 }); 456 });
450 457
451 ReceivePort initialReplyPort = new ReceivePort(); 458 ReceivePort initialReplyPort = new ReceivePort();
452 Isolate 459 Isolate
453 .spawn(echoMain, [initialReplyPort.sendPort, testPort.sendPort]) 460 .spawn(echoMain, [initialReplyPort.sendPort, testPort.sendPort])
454 .then((_) => initialReplyPort.first) 461 .then((_) => initialReplyPort.first)
455 .then((SendPort ping) { 462 .then((SendPort ping) {
456 runTests(ping, checks); 463 runTests(ping, checks);
457 Expect.isTrue(checks.length > 0); 464 Expect.isTrue(checks.length > 0);
458 completer.future 465 completer.future.then((_) => ping.send("halt")).then((_) => asyncEnd());
459 .then((_) => ping.send("halt")) 466 });
460 .then((_) => asyncEnd());
461 });
462 } 467 }
OLDNEW
« no previous file with comments | « tests/isolate/issue_21398_parent_isolate2_test.dart ('k') | tests/isolate/simple_message_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698