OLD | NEW |
---|---|
1 // Copyright (c) 2012, 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 #include "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/globals.h" | 6 #include "vm/globals.h" |
7 #include "vm/isolate.h" | 7 #include "vm/isolate.h" |
8 #include "vm/unit_test.h" | 8 #include "vm/unit_test.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
11 | 11 |
12 UNIT_TEST_CASE(IsolateCurrent) { | 12 UNIT_TEST_CASE(IsolateCurrent) { |
13 Isolate* isolate = Isolate::Init(NULL); | 13 Isolate* isolate = Isolate::Init(NULL); |
14 EXPECT_EQ(isolate, Isolate::Current()); | 14 EXPECT_EQ(isolate, Isolate::Current()); |
15 isolate->Shutdown(); | 15 isolate->Shutdown(); |
16 EXPECT_EQ(reinterpret_cast<Isolate*>(NULL), Isolate::Current()); | 16 EXPECT_EQ(reinterpret_cast<Isolate*>(NULL), Isolate::Current()); |
17 delete isolate; | 17 delete isolate; |
18 } | 18 } |
19 | 19 |
20 | 20 |
21 // Test to ensure that an exception is thrown if no isolate creation | 21 // Test to ensure that an exception is thrown if no isolate creation |
22 // callback has been set by the embedder when an isolate is spawned. | 22 // callback has been set by the embedder when an isolate is spawned. |
23 TEST_CASE(IsolateSpawn) { | 23 TEST_CASE(IsolateSpawn) { |
24 const char* kScriptChars = | 24 const char* kScriptChars = |
25 "import 'dart:isolate';\n" | 25 "import 'dart:isolate';\n" |
26 "void entry(message) {}\n" | 26 "void entry(message) {}\n" |
27 "int testMain() {\n" | 27 "int testMain() {\n" |
28 " try {\n" | 28 " Isolate.spawn(entry, null);\n" |
29 " Isolate.spawn(entry, null);\n" | 29 // TODO(floitsch): the following code is only to bump the event loop |
30 " } catch (e) {\n" | 30 // so it executes asynchronous microtasks. |
31 " rethrow;\n" | 31 " var rp = new RawReceivePort();\n" |
32 " }\n" | 32 " rp.sendPort.send(null);\n" |
33 " return 0;\n" | 33 " rp.handler = (_) { rp.close(); };\n" |
34 "}\n"; | 34 "}\n"; |
35 | |
36 // Setup the internal library's 'internalPrint' function. | |
37 // Necessary because asynchronous errors use "print" to print their | |
38 // stack trace. | |
39 Dart_Handle url = NewString("dart:_collection-dev"); | |
40 DART_CHECK_VALID(url); | |
41 Dart_Handle internal_lib = Dart_LookupLibrary(url); | |
42 DART_CHECK_VALID(internal_lib); | |
43 Dart_Handle print = Dart_GetField(internal_lib, | |
44 NewString("_nullPrintClosure")); | |
Ivan Posva
2013/12/12 12:11:49
I think it would be better to not pollute the inte
floitsch
2013/12/12 21:08:37
Done.
| |
45 Dart_Handle result = Dart_SetField(internal_lib, | |
46 NewString("_printClosure"), | |
47 print); | |
48 | |
49 DART_CHECK_VALID(result); | |
50 | |
51 // Setup the 'scheduleImmediate' closure. | |
52 url = NewString("dart:isolate"); | |
53 DART_CHECK_VALID(url); | |
54 Dart_Handle isolate_lib = Dart_LookupLibrary(url); | |
55 DART_CHECK_VALID(isolate_lib); | |
56 Dart_Handle schedule_immediate_closure = | |
57 Dart_Invoke(isolate_lib, NewString("_getIsolateScheduleImmediateClosure"), | |
58 0, NULL); | |
59 Dart_Handle args[1]; | |
60 args[0] = schedule_immediate_closure; | |
61 DART_CHECK_VALID(Dart_Invoke( | |
62 internal_lib, NewString("setScheduleImmediateClosure"), 1, args)); | |
63 | |
64 | |
35 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 65 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
36 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 66 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
67 EXPECT(!Dart_IsError(result)); | |
68 // Run until all ports to isolate are closed. | |
69 result = Dart_RunLoop(); | |
37 EXPECT_ERROR(result, "Null callback specified for isolate creation"); | 70 EXPECT_ERROR(result, "Null callback specified for isolate creation"); |
38 EXPECT(Dart_ErrorHasException(result)); | 71 EXPECT(Dart_ErrorHasException(result)); |
39 Dart_Handle exception_result = Dart_ErrorGetException(result); | 72 Dart_Handle exception_result = Dart_ErrorGetException(result); |
40 EXPECT_VALID(exception_result); | 73 EXPECT_VALID(exception_result); |
41 } | 74 } |
42 | 75 |
43 } // namespace dart | 76 } // namespace dart |
OLD | NEW |