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