OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Test starting isolate with static functions (and toplevel ones, for sanity). | 5 // Test starting isolate with static functions (and toplevel ones, for sanity). |
6 | 6 |
7 library static_function_test; | 7 library static_function_test; |
8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 import 'static_function_lib.dart' as lib; | 10 import 'static_function_lib.dart' as lib; |
11 import '../../pkg/unittest/lib/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 12 import 'remote_unittest_helper.dart'; |
12 | 13 |
13 void function(SendPort port) { port.send("TOP"); } | 14 void function(SendPort port) { port.send("TOP"); } |
14 void _function(SendPort port) { port.send("_TOP"); } | 15 void _function(SendPort port) { port.send("_TOP"); } |
15 | 16 |
16 // A closure created at top-level (not inside a method), but not by a top-level | 17 // A closure created at top-level (not inside a method), but not by a top-level |
17 // function declaration. | 18 // function declaration. |
18 var staticClosure = (SendPort port) { port.send("WHAT?"); }; | 19 var staticClosure = (SendPort port) { port.send("WHAT?"); }; |
19 | 20 |
20 // An unnamed closure created inside a function. | 21 // An unnamed closure created inside a function. |
21 get dynamicClosure => (SendPort port) { port.send("WHAT??"); }; | 22 get dynamicClosure => (SendPort port) { port.send("WHAT??"); }; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 })); | 69 })); |
69 }); | 70 }); |
70 } | 71 } |
71 | 72 |
72 void throwsTest(name, function) { | 73 void throwsTest(name, function) { |
73 test("throws on $name", () { | 74 test("throws on $name", () { |
74 expect(() { Isolate.spawn(function, null); }, throws); | 75 expect(() { Isolate.spawn(function, null); }, throws); |
75 }); | 76 }); |
76 } | 77 } |
77 | 78 |
78 void main() { | 79 void main([args, port]) { |
| 80 if (testRemote(main, port)) return; |
79 // Sanity check. | 81 // Sanity check. |
80 spawnTest("function", function, "TOP"); | 82 spawnTest("function", function, "TOP"); |
81 spawnTest("_function", _function, "_TOP"); | 83 spawnTest("_function", _function, "_TOP"); |
82 spawnTest("lib.function", lib.function, "LIBTOP"); | 84 spawnTest("lib.function", lib.function, "LIBTOP"); |
83 spawnTest("lib._function", lib.privateFunction, "_LIBTOP"); | 85 spawnTest("lib._function", lib.privateFunction, "_LIBTOP"); |
84 | 86 |
85 // Local static functions. | 87 // Local static functions. |
86 spawnTest("class.function", C.function, "YES"); | 88 spawnTest("class.function", C.function, "YES"); |
87 spawnTest("class._function", C._function, "PRIVATE"); | 89 spawnTest("class._function", C._function, "PRIVATE"); |
88 spawnTest("_class._function", _C.function, "_YES"); | 90 spawnTest("_class._function", _C.function, "_YES"); |
89 spawnTest("_class._function", _C._function, "_PRIVATE"); | 91 spawnTest("_class._function", _C._function, "_PRIVATE"); |
90 | 92 |
91 // Imported static functions. | 93 // Imported static functions. |
92 spawnTest("lib.class.function", lib.C.function, "LIB"); | 94 spawnTest("lib.class.function", lib.C.function, "LIB"); |
93 spawnTest("lib.class._function", lib.C.privateFunction, "LIBPRIVATE"); | 95 spawnTest("lib.class._function", lib.C.privateFunction, "LIBPRIVATE"); |
94 spawnTest("lib._class._function", lib.privateClassFunction, "_LIB"); | 96 spawnTest("lib._class._function", lib.privateClassFunction, "_LIB"); |
95 spawnTest("lib._class._function", lib.privateClassAndFunction, "_LIBPRIVATE"); | 97 spawnTest("lib._class._function", lib.privateClassAndFunction, "_LIBPRIVATE"); |
96 | 98 |
97 // Negative tests | 99 // Negative tests |
98 throwsTest("static closure", staticClosure); | 100 throwsTest("static closure", staticClosure); |
99 throwsTest("dynamic closure", dynamicClosure); | 101 throwsTest("dynamic closure", dynamicClosure); |
100 throwsTest("named dynamic closure", namedDynamicClosure); | 102 throwsTest("named dynamic closure", namedDynamicClosure); |
101 throwsTest("instance closure", new C().instanceClosure); | 103 throwsTest("instance closure", new C().instanceClosure); |
102 throwsTest("initializer closure", new C().constructorInitializerClosure); | 104 throwsTest("initializer closure", new C().constructorInitializerClosure); |
103 throwsTest("constructor closure", new C().constructorBodyClosure); | 105 throwsTest("constructor closure", new C().constructorBodyClosure); |
104 throwsTest("named constructor closure", new C().namedConstructorBodyClosure); | 106 throwsTest("named constructor closure", new C().namedConstructorBodyClosure); |
105 throwsTest("instance method", new C().instanceMethod); | 107 throwsTest("instance method", new C().instanceMethod); |
106 } | 108 } |
OLD | NEW |