| 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/utils.h" | 7 #include "platform/utils.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_api_state.h" | 9 #include "vm/dart_api_state.h" |
| 10 #include "vm/thread.h" | 10 #include "vm/thread.h" |
| 11 #include "vm/unit_test.h" | 11 #include "vm/unit_test.h" |
| 12 #include "vm/verifier.h" | 12 #include "vm/verifier.h" |
| 13 | 13 |
| 14 namespace dart { | 14 namespace dart { |
| 15 | 15 |
| 16 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. | 16 // Only ia32 and x64 can run execution tests. |
| 17 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 17 | 18 |
| 18 TEST_CASE(ErrorHandles) { | 19 TEST_CASE(ErrorHandles) { |
| 19 const char* kScriptChars = | 20 const char* kScriptChars = |
| 20 "class TestClass {\n" | 21 "class TestClass {\n" |
| 21 " static void testMain() {\n" | 22 " static void testMain() {\n" |
| 22 " throw new Exception(\"bad news\");\n" | 23 " throw new Exception(\"bad news\");\n" |
| 23 " }\n" | 24 " }\n" |
| 24 "}\n"; | 25 "}\n"; |
| 25 | 26 |
| 26 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 27 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 108 |
| 108 EXPECT_VALID(Dart_IsSame(class1, class1, &same)); | 109 EXPECT_VALID(Dart_IsSame(class1, class1, &same)); |
| 109 EXPECT(same); | 110 EXPECT(same); |
| 110 | 111 |
| 111 EXPECT_VALID(Dart_IsSame(class1, class2, &same)); | 112 EXPECT_VALID(Dart_IsSame(class1, class2, &same)); |
| 112 EXPECT(!same); | 113 EXPECT(!same); |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 | 116 |
| 116 | 117 |
| 117 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. | 118 // Only ia32 and x64 can run execution tests. |
| 119 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 118 | 120 |
| 119 TEST_CASE(ObjectEquals) { | 121 TEST_CASE(ObjectEquals) { |
| 120 bool equal = false; | 122 bool equal = false; |
| 121 Dart_Handle five = Dart_NewString("5"); | 123 Dart_Handle five = Dart_NewString("5"); |
| 122 Dart_Handle five_again = Dart_NewString("5"); | 124 Dart_Handle five_again = Dart_NewString("5"); |
| 123 Dart_Handle seven = Dart_NewString("7"); | 125 Dart_Handle seven = Dart_NewString("7"); |
| 124 | 126 |
| 125 // Same objects. | 127 // Same objects. |
| 126 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); | 128 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); |
| 127 EXPECT(equal); | 129 EXPECT(equal); |
| 128 | 130 |
| 129 // Equal objects. | 131 // Equal objects. |
| 130 EXPECT_VALID(Dart_ObjectEquals(five, five_again, &equal)); | 132 EXPECT_VALID(Dart_ObjectEquals(five, five_again, &equal)); |
| 131 EXPECT(equal); | 133 EXPECT(equal); |
| 132 | 134 |
| 133 // Different objects. | 135 // Different objects. |
| 134 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal)); | 136 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal)); |
| 135 EXPECT(!equal); | 137 EXPECT(!equal); |
| 136 } | 138 } |
| 137 | 139 |
| 138 #endif | 140 #endif |
| 139 | 141 |
| 142 |
| 140 TEST_CASE(BooleanValues) { | 143 TEST_CASE(BooleanValues) { |
| 141 Dart_Handle str = Dart_NewString("test"); | 144 Dart_Handle str = Dart_NewString("test"); |
| 142 EXPECT(!Dart_IsBoolean(str)); | 145 EXPECT(!Dart_IsBoolean(str)); |
| 143 | 146 |
| 144 bool value = false; | 147 bool value = false; |
| 145 Dart_Handle result = Dart_BooleanValue(str, &value); | 148 Dart_Handle result = Dart_BooleanValue(str, &value); |
| 146 EXPECT(Dart_IsError(result)); | 149 EXPECT(Dart_IsError(result)); |
| 147 | 150 |
| 148 Dart_Handle val1 = Dart_NewBoolean(true); | 151 Dart_Handle val1 = Dart_NewBoolean(true); |
| 149 EXPECT(Dart_IsBoolean(val1)); | 152 EXPECT(Dart_IsBoolean(val1)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 double out1, out2; | 194 double out1, out2; |
| 192 Dart_Handle result = Dart_DoubleValue(val1, &out1); | 195 Dart_Handle result = Dart_DoubleValue(val1, &out1); |
| 193 EXPECT_VALID(result); | 196 EXPECT_VALID(result); |
| 194 EXPECT_EQ(kDoubleVal1, out1); | 197 EXPECT_EQ(kDoubleVal1, out1); |
| 195 result = Dart_DoubleValue(val2, &out2); | 198 result = Dart_DoubleValue(val2, &out2); |
| 196 EXPECT_VALID(result); | 199 EXPECT_VALID(result); |
| 197 EXPECT_EQ(kDoubleVal2, out2); | 200 EXPECT_EQ(kDoubleVal2, out2); |
| 198 } | 201 } |
| 199 | 202 |
| 200 | 203 |
| 201 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. | 204 // Only ia32 and x64 can run execution tests. |
| 205 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 202 | 206 |
| 203 TEST_CASE(NumberValues) { | 207 TEST_CASE(NumberValues) { |
| 204 // TODO(antonm): add various kinds of ints (smi, mint, bigint). | 208 // TODO(antonm): add various kinds of ints (smi, mint, bigint). |
| 205 const char* kScriptChars = | 209 const char* kScriptChars = |
| 206 "class NumberValuesHelper {\n" | 210 "class NumberValuesHelper {\n" |
| 207 " static int getInt() { return 1; }\n" | 211 " static int getInt() { return 1; }\n" |
| 208 " static double getDouble() { return 1.0; }\n" | 212 " static double getDouble() { return 1.0; }\n" |
| 209 " static bool getBool() { return false; }\n" | 213 " static bool getBool() { return false; }\n" |
| 210 " static getNull() { return null; }\n" | 214 " static getNull() { return null; }\n" |
| 211 "}\n"; | 215 "}\n"; |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 // Not a String. | 485 // Not a String. |
| 482 peer = NULL; | 486 peer = NULL; |
| 483 result = Dart_ExternalStringGetPeer(Dart_True(), &peer); | 487 result = Dart_ExternalStringGetPeer(Dart_True(), &peer); |
| 484 EXPECT(Dart_IsError(result)); | 488 EXPECT(Dart_IsError(result)); |
| 485 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be " | 489 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be " |
| 486 "of type String.", Dart_GetError(result)); | 490 "of type String.", Dart_GetError(result)); |
| 487 EXPECT(peer == NULL); | 491 EXPECT(peer == NULL); |
| 488 } | 492 } |
| 489 | 493 |
| 490 | 494 |
| 491 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. | 495 // Only ia32 and x64 can run execution tests. |
| 496 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 492 | 497 |
| 493 TEST_CASE(ListAccess) { | 498 TEST_CASE(ListAccess) { |
| 494 const char* kScriptChars = | 499 const char* kScriptChars = |
| 495 "class ListAccessTest {" | 500 "class ListAccessTest {" |
| 496 " ListAccessTest() {}" | 501 " ListAccessTest() {}" |
| 497 " static List testMain() {" | 502 " static List testMain() {" |
| 498 " List a = new List();" | 503 " List a = new List();" |
| 499 " a.add(10);" | 504 " a.add(10);" |
| 500 " a.add(20);" | 505 " a.add(20);" |
| 501 " a.add(30);" | 506 " a.add(30);" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 EXPECT_VALID(result); | 605 EXPECT_VALID(result); |
| 601 result = Dart_IntegerToInt64(result, &value); | 606 result = Dart_IntegerToInt64(result, &value); |
| 602 EXPECT_VALID(result); | 607 EXPECT_VALID(result); |
| 603 EXPECT_EQ(30, value); | 608 EXPECT_EQ(30, value); |
| 604 | 609 |
| 605 // Check if we get an exception when accessing beyond limit. | 610 // Check if we get an exception when accessing beyond limit. |
| 606 result = Dart_ListGetAt(ListAccessTestObj, 4); | 611 result = Dart_ListGetAt(ListAccessTestObj, 4); |
| 607 EXPECT(Dart_IsError(result)); | 612 EXPECT(Dart_IsError(result)); |
| 608 } | 613 } |
| 609 | 614 |
| 610 #endif // TARGET_ARCH_IA32. | 615 #endif |
| 611 | 616 |
| 612 | 617 |
| 613 // Unit test for entering a scope, creating a local handle and exiting | 618 // Unit test for entering a scope, creating a local handle and exiting |
| 614 // the scope. | 619 // the scope. |
| 615 UNIT_TEST_CASE(EnterExitScope) { | 620 UNIT_TEST_CASE(EnterExitScope) { |
| 616 TestIsolateScope __test_isolate__; | 621 TestIsolateScope __test_isolate__; |
| 617 | 622 |
| 618 Isolate* isolate = Isolate::Current(); | 623 Isolate* isolate = Isolate::Current(); |
| 619 EXPECT(isolate != NULL); | 624 EXPECT(isolate != NULL); |
| 620 ApiState* state = isolate->api_state(); | 625 ApiState* state = isolate->api_state(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 | 727 |
| 723 // Make sure that the value transferred. | 728 // Make sure that the value transferred. |
| 724 EXPECT(Dart_IsBoolean(obj2)); | 729 EXPECT(Dart_IsBoolean(obj2)); |
| 725 bool value = false; | 730 bool value = false; |
| 726 Dart_Handle result = Dart_BooleanValue(obj2, &value); | 731 Dart_Handle result = Dart_BooleanValue(obj2, &value); |
| 727 EXPECT_VALID(result); | 732 EXPECT_VALID(result); |
| 728 EXPECT(value); | 733 EXPECT(value); |
| 729 } | 734 } |
| 730 | 735 |
| 731 | 736 |
| 732 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. | 737 // Only ia32 and x64 can run execution tests. |
| 738 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 733 | 739 |
| 734 TEST_CASE(WeakPersistentHandle) { | 740 TEST_CASE(WeakPersistentHandle) { |
| 735 Dart_Handle weak_new_ref = Dart_Null(); | 741 Dart_Handle weak_new_ref = Dart_Null(); |
| 736 EXPECT(Dart_IsNull(weak_new_ref)); | 742 EXPECT(Dart_IsNull(weak_new_ref)); |
| 737 | 743 |
| 738 Dart_Handle weak_old_ref = Dart_Null(); | 744 Dart_Handle weak_old_ref = Dart_Null(); |
| 739 EXPECT(Dart_IsNull(weak_old_ref)); | 745 EXPECT(Dart_IsNull(weak_old_ref)); |
| 740 | 746 |
| 741 bool is_same; | 747 bool is_same; |
| 742 | 748 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 UNIT_TEST_CASE(SetMessageCallbacks) { | 1026 UNIT_TEST_CASE(SetMessageCallbacks) { |
| 1021 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); | 1027 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); |
| 1022 Dart_SetMessageCallbacks(&MyPostMessageCallback, &MyClosePortCallback); | 1028 Dart_SetMessageCallbacks(&MyPostMessageCallback, &MyClosePortCallback); |
| 1023 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); | 1029 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); |
| 1024 EXPECT_EQ(&MyPostMessageCallback, isolate->post_message_callback()); | 1030 EXPECT_EQ(&MyPostMessageCallback, isolate->post_message_callback()); |
| 1025 EXPECT_EQ(&MyClosePortCallback, isolate->close_port_callback()); | 1031 EXPECT_EQ(&MyClosePortCallback, isolate->close_port_callback()); |
| 1026 Dart_ShutdownIsolate(); | 1032 Dart_ShutdownIsolate(); |
| 1027 } | 1033 } |
| 1028 | 1034 |
| 1029 | 1035 |
| 1030 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. | 1036 // Only ia32 and x64 can run execution tests. |
| 1037 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 1031 | 1038 |
| 1032 TEST_CASE(FieldAccess) { | 1039 TEST_CASE(FieldAccess) { |
| 1033 const char* kScriptChars = | 1040 const char* kScriptChars = |
| 1034 "class Fields {\n" | 1041 "class Fields {\n" |
| 1035 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n" | 1042 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n" |
| 1036 " int fld1;\n" | 1043 " int fld1;\n" |
| 1037 " final int fld2;\n" | 1044 " final int fld2;\n" |
| 1038 " static int fld3;\n" | 1045 " static int fld3;\n" |
| 1039 " static final int fld4 = 10;\n" | 1046 " static final int fld4 = 10;\n" |
| 1040 "}\n" | 1047 "}\n" |
| (...skipping 1957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2998 } | 3005 } |
| 2999 } | 3006 } |
| 3000 | 3007 |
| 3001 // We should have received the expected number of interrupts. | 3008 // We should have received the expected number of interrupts. |
| 3002 EXPECT_EQ(kInterruptCount, interrupt_count); | 3009 EXPECT_EQ(kInterruptCount, interrupt_count); |
| 3003 | 3010 |
| 3004 // Give the spawned thread enough time to properly exit. | 3011 // Give the spawned thread enough time to properly exit. |
| 3005 Isolate::SetInterruptCallback(saved); | 3012 Isolate::SetInterruptCallback(saved); |
| 3006 } | 3013 } |
| 3007 | 3014 |
| 3008 #endif // TARGET_ARCH_IA32. | 3015 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 3009 | 3016 |
| 3010 } // namespace dart | 3017 } // namespace dart |
| OLD | NEW |