OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013, 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 // Test starting isolate with static functions (and toplevel ones, for sanity). | |
6 | |
7 library static_function_test; | |
8 import 'dart:isolate'; | |
9 import 'dart:async'; | |
10 import 'static_function_lib.dart' as lib; | |
11 import '../../pkg/unittest/lib/unittest.dart'; | |
12 | |
13 void function(SendPort port) { port.send("TOP"); } | |
14 void _function(SendPort port) { port.send("_TOP"); } | |
15 | |
16 var staticClosure = (SendPort port) { port.send("WHAT?"); }; | |
17 get dynamicClosure => (SendPort port) { port.send("WHAT??"); }; | |
18 | |
19 class C { | |
20 static void function(SendPort port) { port.send("YES"); } | |
21 static void _function(SendPort port) { port.send("PRIVATE"); } | |
22 void instanceMethod(SendPort port) { port.send("INSTANCE WHAT?"); } | |
23 } | |
24 | |
25 class _C { | |
26 static void function(SendPort port) { port.send("_YES"); } | |
27 static void _function(SendPort port) { port.send("_PRIVATE"); } | |
28 } | |
29 | |
30 void spawnTest(name, function, response) { | |
31 test(name, () { | |
32 ReceivePort r = new ReceivePort(); | |
33 Isolate.spawn(function, r.sendPort); | |
34 r.listen(expectAsync1((v) { | |
35 expect(v, response); | |
36 r.close(); | |
37 })); | |
38 }); | |
39 } | |
40 | |
41 void throwsTest(name, function) { | |
42 test("throws on $name", () { | |
43 expect(() { Isolate.spawn(function, null); }, throws); | |
44 }); | |
45 } | |
46 | |
47 void main() { | |
48 // Sanity check. | |
49 spawnTest("function", function, "TOP"); | |
50 spawnTest("_function", _function, "_TOP"); | |
51 spawnTest("lib.function", lib.function, "LIBTOP"); | |
52 spawnTest("lib._function", lib.privateFunction, "_LIBTOP"); | |
53 | |
54 // Local static functions. | |
55 spawnTest("class.function", C.function, "YES"); | |
56 spawnTest("class._function", C._function, "PRIVATE"); | |
57 spawnTest("_class._function", _C.function, "_YES"); | |
58 spawnTest("_class._function", _C._function, "_PRIVATE"); | |
59 | |
60 // Imported static functions. | |
61 spawnTest("lib.class.function", lib.C.function, "LIB"); | |
62 spawnTest("lib.class._function", lib.C.privateFunction, "LIBPRIVATE"); | |
63 spawnTest("lib._class._function", lib.privateClassFunction, "_LIB"); | |
64 spawnTest("lib._class._function", lib.privateClassAndFunction, "_LIBPRIVATE"); | |
65 | |
66 // Negative tests | |
67 throwsTest("static closure", staticClosure); | |
Lasse Reichstein Nielsen
2013/11/12 07:34:05
This test, and the next one, fails in the VM.
I'll
| |
68 throwsTest("dynamic closure", dynamicClosure); | |
69 throwsTest("instance method", new C().instanceMethod); | |
70 } | |
OLD | NEW |