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

Side by Side Diff: tests/isolate/isolate_complex_messages_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
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 isolate communication with 5 // Dart test program for testing isolate communication with
6 // complex messages. 6 // complex messages.
7 7
8 #library('IsolateComplexMessagesTest'); 8 #library('IsolateComplexMessagesTest');
9 #import('dart:isolate'); 9 #import('dart:isolate');
10 #import('../../lib/unittest/unittest.dart'); 10 #import('../../lib/unittest/unittest.dart');
11 11
12 main() { 12 main() {
13 test("complex messages are serialized correctly", () { 13 test("complex messages are serialized correctly", () {
14 new LogIsolate().spawn().then(expectAsync1((SendPort remote) { 14 SendPort remote = spawnFunction(logMessages);
15 15 remote.send(1, null);
16 remote.send(1, null); 16 remote.send("Hello", null);
17 remote.send("Hello", null); 17 remote.send("World", null);
18 remote.send("World", null); 18 remote.send(const [null, 1, 2, 3, 4], null);
19 remote.send(const [null, 1, 2, 3, 4], null); 19 remote.send(const [1, 2.0, true, false, 0xffffffffff], null);
20 remote.send(const [1, 2.0, true, false, 0xffffffffff], null); 20 remote.send(const ["Hello", "World", 0xffffffffff], null);
21 remote.send(const ["Hello", "World", 0xffffffffff], null); 21 // Shutdown the LogRunner.
22 // Shutdown the LogRunner. 22 remote.call(-1).then(expectAsync1((int message) {
23 remote.call(-1).then(expectAsync1((int message) { 23 Expect.equals(6, message);
24 Expect.equals(6, message);
25 }));
26 })); 24 }));
27 }); 25 });
28 } 26 }
29 27
30 28
31 class LogIsolate extends Isolate { 29 void logMessages() {
32 LogIsolate() : super() { } 30 int count = 0;
33 31
34 void main() { 32 port.receive((var message, SendPort replyTo) {
35 int count = 0; 33 if (message == -1) {
36 34 port.close();
37 this.port.receive((var message, SendPort replyTo) { 35 replyTo.send(count, null);
38 if (message == -1) { 36 } else {
39 this.port.close(); 37 switch (count) {
40 replyTo.send(count, null); 38 case 0:
41 } else { 39 Expect.equals(1, message);
42 switch (count) { 40 break;
43 case 0: 41 case 1:
44 Expect.equals(1, message); 42 Expect.equals("Hello", message);
45 break; 43 break;
46 case 1: 44 case 2:
47 Expect.equals("Hello", message); 45 Expect.equals("World", message);
48 break; 46 break;
49 case 2: 47 case 3:
50 Expect.equals("World", message); 48 Expect.equals(5, message.length);
51 break; 49 Expect.equals(null, message[0]);
52 case 3: 50 Expect.equals(1, message[1]);
53 Expect.equals(5, message.length); 51 Expect.equals(2, message[2]);
54 Expect.equals(null, message[0]); 52 Expect.equals(3, message[3]);
55 Expect.equals(1, message[1]); 53 Expect.equals(4, message[4]);
56 Expect.equals(2, message[2]); 54 break;
57 Expect.equals(3, message[3]); 55 case 4:
58 Expect.equals(4, message[4]); 56 Expect.equals(5, message.length);
59 break; 57 Expect.equals(1, message[0]);
60 case 4: 58 Expect.equals(2.0, message[1]);
61 Expect.equals(5, message.length); 59 Expect.equals(true, message[2]);
62 Expect.equals(1, message[0]); 60 Expect.equals(false, message[3]);
63 Expect.equals(2.0, message[1]); 61 Expect.equals(0xffffffffff, message[4]);
64 Expect.equals(true, message[2]); 62 break;
65 Expect.equals(false, message[3]); 63 case 5:
66 Expect.equals(0xffffffffff, message[4]); 64 Expect.equals(3, message.length);
67 break; 65 Expect.equals("Hello", message[0]);
68 case 5: 66 Expect.equals("World", message[1]);
69 Expect.equals(3, message.length); 67 Expect.equals(0xffffffffff, message[2]);
70 Expect.equals("Hello", message[0]); 68 break;
71 Expect.equals("World", message[1]);
72 Expect.equals(0xffffffffff, message[2]);
73 break;
74 }
75 count++;
76 } 69 }
77 }); 70 count++;
78 } 71 }
72 });
79 } 73 }
OLDNEW
« no previous file with comments | « tests/isolate/isolate3_negative_test.dart ('k') | tests/isolate/isolate_import_negative_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698