OLD | NEW |
| (Empty) |
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 | |
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 '../../pkg/unittest/lib/unittest.dart'; | |
11 | |
12 main() { | |
13 test("complex messages are serialized correctly", () { | |
14 var box = new MessageBox(); | |
15 IsolateSink remote = streamSpawnFunction(logMessages); | |
16 remote.add(1); | |
17 remote.add("Hello"); | |
18 remote.add("World"); | |
19 remote.add(const [null, 1, 2, 3, 4]); | |
20 remote.add(const [1, 2.0, true, false, 0xffffffffff]); | |
21 remote.add(const ["Hello", "World", 0xffffffffff]); | |
22 remote.add(box.sink); | |
23 remote.close(); | |
24 box.stream.single.then((message) { | |
25 expect(message, 7); | |
26 }); | |
27 }); | |
28 } | |
29 | |
30 | |
31 void logMessages() { | |
32 int count = 0; | |
33 IsolateSink replySink; | |
34 | |
35 stream.listen((message) { | |
36 switch (count) { | |
37 case 0: | |
38 expect(message, 1); | |
39 break; | |
40 case 1: | |
41 expect(message, "Hello"); | |
42 break; | |
43 case 2: | |
44 expect(message, "World"); | |
45 break; | |
46 case 3: | |
47 expect(message.length, 5); | |
48 expect(message[0], null); | |
49 expect(message[1], 1); | |
50 expect(message[2], 2); | |
51 expect(message[3], 3); | |
52 expect(message[4], 4); | |
53 break; | |
54 case 4: | |
55 expect(message.length, 5); | |
56 expect(message[0], 1); | |
57 expect(message[1], 2.0); | |
58 expect(message[2], true); | |
59 expect(message[3], false); | |
60 expect(message[4], 0xffffffffff); | |
61 break; | |
62 case 5: | |
63 expect(message.length, 3); | |
64 expect(message[0], "Hello"); | |
65 expect(message[1], "World"); | |
66 expect(message[2], 0xffffffffff); | |
67 break; | |
68 case 6: | |
69 replySink = message; | |
70 break; | |
71 } | |
72 count++; | |
73 }, | |
74 onDone: () { | |
75 replySink.add(count); | |
76 replySink.close(); | |
77 }); | |
78 } | |
OLD | NEW |