| 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 "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
| 7 #include "platform/json.h" | 7 #include "platform/json.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| 11 #include "vm/dart_api_state.h" | 11 #include "vm/dart_api_state.h" |
| 12 #include "vm/thread.h" | 12 #include "vm/thread.h" |
| 13 #include "vm/unit_test.h" | 13 #include "vm/unit_test.h" |
| 14 #include "vm/verifier.h" | 14 #include "vm/verifier.h" |
| 15 | 15 |
| 16 namespace dart { | 16 namespace dart { |
| 17 | 17 |
| 18 DECLARE_FLAG(bool, enable_type_checks); | 18 DECLARE_FLAG(bool, enable_type_checks); |
| 19 | 19 |
| 20 // Only ia32 and x64 can run execution tests. | 20 #if defined(TARGET_ARCH_IA32) || \ |
| 21 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 21 defined(TARGET_ARCH_X64) || \ |
| 22 defined(TARGET_ARCH_ARM) |
| 22 | 23 |
| 23 TEST_CASE(ErrorHandleBasics) { | 24 TEST_CASE(ErrorHandleBasics) { |
| 24 const char* kScriptChars = | 25 const char* kScriptChars = |
| 25 "void testMain() {\n" | 26 "void testMain() {\n" |
| 26 " throw new Exception(\"bad news\");\n" | 27 " throw new Exception(\"bad news\");\n" |
| 27 "}\n"; | 28 "}\n"; |
| 28 | 29 |
| 29 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 30 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 30 | 31 |
| 31 Dart_Handle instance = Dart_True(); | 32 Dart_Handle instance = Dart_True(); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 Dart_Handle class1 = Api::NewHandle(isolate, Object::null_class()); | 209 Dart_Handle class1 = Api::NewHandle(isolate, Object::null_class()); |
| 209 Dart_Handle class2 = Api::NewHandle(isolate, Object::class_class()); | 210 Dart_Handle class2 = Api::NewHandle(isolate, Object::class_class()); |
| 210 | 211 |
| 211 EXPECT(Dart_IdentityEquals(class1, class1)); | 212 EXPECT(Dart_IdentityEquals(class1, class1)); |
| 212 | 213 |
| 213 EXPECT(!Dart_IdentityEquals(class1, class2)); | 214 EXPECT(!Dart_IdentityEquals(class1, class2)); |
| 214 } | 215 } |
| 215 } | 216 } |
| 216 | 217 |
| 217 | 218 |
| 218 // Only ia32 and x64 can run execution tests. | 219 #if defined(TARGET_ARCH_IA32) || \ |
| 219 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 220 defined(TARGET_ARCH_X64) || \ |
| 221 defined(TARGET_ARCH_ARM) |
| 220 | 222 |
| 221 TEST_CASE(ObjectEquals) { | 223 TEST_CASE(ObjectEquals) { |
| 222 bool equal = false; | 224 bool equal = false; |
| 223 Dart_Handle five = NewString("5"); | 225 Dart_Handle five = NewString("5"); |
| 224 Dart_Handle five_again = NewString("5"); | 226 Dart_Handle five_again = NewString("5"); |
| 225 Dart_Handle seven = NewString("7"); | 227 Dart_Handle seven = NewString("7"); |
| 226 | 228 |
| 227 // Same objects. | 229 // Same objects. |
| 228 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); | 230 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); |
| 229 EXPECT(equal); | 231 EXPECT(equal); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 double out1, out2; | 331 double out1, out2; |
| 330 Dart_Handle result = Dart_DoubleValue(val1, &out1); | 332 Dart_Handle result = Dart_DoubleValue(val1, &out1); |
| 331 EXPECT_VALID(result); | 333 EXPECT_VALID(result); |
| 332 EXPECT_EQ(kDoubleVal1, out1); | 334 EXPECT_EQ(kDoubleVal1, out1); |
| 333 result = Dart_DoubleValue(val2, &out2); | 335 result = Dart_DoubleValue(val2, &out2); |
| 334 EXPECT_VALID(result); | 336 EXPECT_VALID(result); |
| 335 EXPECT_EQ(kDoubleVal2, out2); | 337 EXPECT_EQ(kDoubleVal2, out2); |
| 336 } | 338 } |
| 337 | 339 |
| 338 | 340 |
| 339 // Only ia32 and x64 can run execution tests. | 341 #if defined(TARGET_ARCH_IA32) || \ |
| 340 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 342 defined(TARGET_ARCH_X64) || \ |
| 343 defined(TARGET_ARCH_ARM) |
| 341 | 344 |
| 342 TEST_CASE(NumberValues) { | 345 TEST_CASE(NumberValues) { |
| 343 // TODO(antonm): add various kinds of ints (smi, mint, bigint). | 346 // TODO(antonm): add various kinds of ints (smi, mint, bigint). |
| 344 const char* kScriptChars = | 347 const char* kScriptChars = |
| 345 "int getInt() { return 1; }\n" | 348 "int getInt() { return 1; }\n" |
| 346 "double getDouble() { return 1.0; }\n" | 349 "double getDouble() { return 1.0; }\n" |
| 347 "bool getBool() { return false; }\n" | 350 "bool getBool() { return false; }\n" |
| 348 "getNull() { return null; }\n"; | 351 "getNull() { return null; }\n"; |
| 349 Dart_Handle result; | 352 Dart_Handle result; |
| 350 // Create a test library and Load up a test script in it. | 353 // Create a test library and Load up a test script in it. |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 // Not a String. | 632 // Not a String. |
| 630 peer = NULL; | 633 peer = NULL; |
| 631 result = Dart_ExternalStringGetPeer(Dart_True(), &peer); | 634 result = Dart_ExternalStringGetPeer(Dart_True(), &peer); |
| 632 EXPECT(Dart_IsError(result)); | 635 EXPECT(Dart_IsError(result)); |
| 633 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be " | 636 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be " |
| 634 "of type String.", Dart_GetError(result)); | 637 "of type String.", Dart_GetError(result)); |
| 635 EXPECT(peer == NULL); | 638 EXPECT(peer == NULL); |
| 636 } | 639 } |
| 637 | 640 |
| 638 | 641 |
| 639 // Only ia32 and x64 can run execution tests. | 642 #if defined(TARGET_ARCH_IA32) || \ |
| 640 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 643 defined(TARGET_ARCH_X64) || \ |
| 644 defined(TARGET_ARCH_ARM) |
| 641 | 645 |
| 642 static void ExternalStringCallbackFinalizer(void* peer) { | 646 static void ExternalStringCallbackFinalizer(void* peer) { |
| 643 *static_cast<int*>(peer) *= 2; | 647 *static_cast<int*>(peer) *= 2; |
| 644 } | 648 } |
| 645 | 649 |
| 646 | 650 |
| 647 TEST_CASE(ExternalStringCallback) { | 651 TEST_CASE(ExternalStringCallback) { |
| 648 int peer8 = 40; | 652 int peer8 = 40; |
| 649 int peer16 = 41; | 653 int peer16 = 41; |
| 650 | 654 |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1536 // perturb the test. | 1540 // perturb the test. |
| 1537 class GCTestHelper : public AllStatic { | 1541 class GCTestHelper : public AllStatic { |
| 1538 public: | 1542 public: |
| 1539 static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) { | 1543 static void CollectNewSpace(Heap::ApiCallbacks api_callbacks) { |
| 1540 bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks); | 1544 bool invoke_api_callbacks = (api_callbacks == Heap::kInvokeApiCallbacks); |
| 1541 Isolate::Current()->heap()->new_space_->Scavenge(invoke_api_callbacks); | 1545 Isolate::Current()->heap()->new_space_->Scavenge(invoke_api_callbacks); |
| 1542 } | 1546 } |
| 1543 }; | 1547 }; |
| 1544 | 1548 |
| 1545 | 1549 |
| 1546 // Only ia32 and x64 can run execution tests. | 1550 #if defined(TARGET_ARCH_IA32) || \ |
| 1547 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 1551 defined(TARGET_ARCH_X64) || \ |
| 1552 defined(TARGET_ARCH_ARM) |
| 1548 | 1553 |
| 1549 TEST_CASE(WeakPersistentHandle) { | 1554 TEST_CASE(WeakPersistentHandle) { |
| 1550 Dart_Handle weak_new_ref = Dart_Null(); | 1555 Dart_Handle weak_new_ref = Dart_Null(); |
| 1551 EXPECT(Dart_IsNull(weak_new_ref)); | 1556 EXPECT(Dart_IsNull(weak_new_ref)); |
| 1552 | 1557 |
| 1553 Dart_Handle weak_old_ref = Dart_Null(); | 1558 Dart_Handle weak_old_ref = Dart_Null(); |
| 1554 EXPECT(Dart_IsNull(weak_old_ref)); | 1559 EXPECT(Dart_IsNull(weak_old_ref)); |
| 1555 | 1560 |
| 1556 { | 1561 { |
| 1557 Dart_EnterScope(); | 1562 Dart_EnterScope(); |
| (...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2574 | 2579 |
| 2575 UNIT_TEST_CASE(SetMessageCallbacks) { | 2580 UNIT_TEST_CASE(SetMessageCallbacks) { |
| 2576 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); | 2581 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); |
| 2577 Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback); | 2582 Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback); |
| 2578 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); | 2583 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); |
| 2579 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback()); | 2584 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback()); |
| 2580 Dart_ShutdownIsolate(); | 2585 Dart_ShutdownIsolate(); |
| 2581 } | 2586 } |
| 2582 | 2587 |
| 2583 | 2588 |
| 2584 // Only ia32 and x64 can run execution tests. | 2589 #if defined(TARGET_ARCH_IA32) || \ |
| 2585 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 2590 defined(TARGET_ARCH_X64) || \ |
| 2591 defined(TARGET_ARCH_ARM) |
| 2586 | 2592 |
| 2587 TEST_CASE(ClassTypedefsEtc) { | 2593 TEST_CASE(ClassTypedefsEtc) { |
| 2588 const char* kScriptChars = | 2594 const char* kScriptChars = |
| 2589 "class SomeClass {\n" | 2595 "class SomeClass {\n" |
| 2590 "}\n" | 2596 "}\n" |
| 2591 "typedef void SomeHandler(String a);\n"; | 2597 "typedef void SomeHandler(String a);\n"; |
| 2592 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2598 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2593 EXPECT_VALID(lib); | 2599 EXPECT_VALID(lib); |
| 2594 Dart_Handle normal_cls = Dart_GetClass(lib, NewString("SomeClass")); | 2600 Dart_Handle normal_cls = Dart_GetClass(lib, NewString("SomeClass")); |
| 2595 EXPECT_VALID(normal_cls); | 2601 EXPECT_VALID(normal_cls); |
| (...skipping 5042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7638 Dart_Handle result = Dart_Invoke(lib, | 7644 Dart_Handle result = Dart_Invoke(lib, |
| 7639 NewString("main"), | 7645 NewString("main"), |
| 7640 0, | 7646 0, |
| 7641 NULL); | 7647 NULL); |
| 7642 int64_t value = 0; | 7648 int64_t value = 0; |
| 7643 result = Dart_IntegerToInt64(result, &value); | 7649 result = Dart_IntegerToInt64(result, &value); |
| 7644 EXPECT_VALID(result); | 7650 EXPECT_VALID(result); |
| 7645 EXPECT_EQ(260, value); | 7651 EXPECT_EQ(260, value); |
| 7646 } | 7652 } |
| 7647 | 7653 |
| 7648 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 7654 #endif |
| 7649 | 7655 |
| 7650 } // namespace dart | 7656 } // namespace dart |
| OLD | NEW |