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_debugger_api.h" | 5 #include "include/dart_debugger_api.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "vm/dart_api_impl.h" | 7 #include "vm/dart_api_impl.h" |
8 #include "vm/thread.h" | 8 #include "vm/thread.h" |
9 #include "vm/unit_test.h" | 9 #include "vm/unit_test.h" |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 static void LoadScript(const char* source) { | 22 static void LoadScript(const char* source) { |
23 script_lib = TestCase::LoadTestScript(source, NULL); | 23 script_lib = TestCase::LoadTestScript(source, NULL); |
24 EXPECT_VALID(script_lib); | 24 EXPECT_VALID(script_lib); |
25 } | 25 } |
26 | 26 |
27 | 27 |
28 static void SetBreakpointAtEntry(const char* cname, const char* fname) { | 28 static void SetBreakpointAtEntry(const char* cname, const char* fname) { |
29 ASSERT(script_lib != NULL); | 29 ASSERT(script_lib != NULL); |
30 ASSERT(!Dart_IsError(script_lib)); | 30 ASSERT(!Dart_IsError(script_lib)); |
31 ASSERT(Dart_IsLibrary(script_lib)); | 31 ASSERT(Dart_IsLibrary(script_lib)); |
32 Dart_Breakpoint bpt; | |
33 Dart_Handle res = Dart_SetBreakpointAtEntry(script_lib, | 32 Dart_Handle res = Dart_SetBreakpointAtEntry(script_lib, |
34 NewString(cname), | 33 NewString(cname), |
35 NewString(fname), | 34 NewString(fname)); |
36 &bpt); | 35 EXPECT(Dart_IsInteger(res)); |
37 EXPECT_TRUE(res); | |
38 } | 36 } |
39 | 37 |
40 | 38 |
41 static Dart_Handle Invoke(const char* func_name) { | 39 static Dart_Handle Invoke(const char* func_name) { |
42 ASSERT(script_lib != NULL); | 40 ASSERT(script_lib != NULL); |
43 ASSERT(!Dart_IsError(script_lib)); | 41 ASSERT(!Dart_IsError(script_lib)); |
44 ASSERT(Dart_IsLibrary(script_lib)); | 42 ASSERT(Dart_IsLibrary(script_lib)); |
45 return Dart_Invoke(script_lib, NewString(func_name), 0, NULL); | 43 return Dart_Invoke(script_lib, NewString(func_name), 0, NULL); |
46 } | 44 } |
47 | 45 |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 // locates it at the token position of the keyword 'class'. | 989 // locates it at the token position of the keyword 'class'. |
992 func = test_lib.LookupFunctionInSource(script_url, 1); | 990 func = test_lib.LookupFunctionInSource(script_url, 1); |
993 EXPECT(!func.IsNull()); | 991 EXPECT(!func.IsNull()); |
994 EXPECT_STREQ("A.", String::Handle(func.name()).ToCString()); | 992 EXPECT_STREQ("A.", String::Handle(func.name()).ToCString()); |
995 | 993 |
996 func = test_lib.LookupFunctionInSource(script_url, 6); | 994 func = test_lib.LookupFunctionInSource(script_url, 6); |
997 EXPECT(func.IsNull()); | 995 EXPECT(func.IsNull()); |
998 func = test_lib.LookupFunctionInSource(script_url, 10); | 996 func = test_lib.LookupFunctionInSource(script_url, 10); |
999 EXPECT(func.IsNull()); | 997 EXPECT(func.IsNull()); |
1000 | 998 |
1001 Dart_Handle libs = Dart_GetLibraryURLs(); | 999 Dart_Handle libs = Dart_GetLibraryIds(); |
1002 EXPECT(Dart_IsList(libs)); | 1000 EXPECT(Dart_IsList(libs)); |
1003 intptr_t num_libs; | 1001 intptr_t num_libs; |
1004 Dart_ListLength(libs, &num_libs); | 1002 Dart_ListLength(libs, &num_libs); |
1005 EXPECT(num_libs > 0); | 1003 EXPECT(num_libs > 0); |
1006 for (int i = 0; i < num_libs; i++) { | 1004 for (int i = 0; i < num_libs; i++) { |
1007 Dart_Handle lib_url = Dart_ListGetAt(libs, i); | 1005 Dart_Handle lib_id = Dart_ListGetAt(libs, i); |
1008 EXPECT(Dart_IsString(lib_url)); | 1006 EXPECT(Dart_IsInteger(lib_id)); |
| 1007 int64_t id = 0; |
| 1008 Dart_IntegerToInt64(lib_id, &id); |
| 1009 Dart_Handle lib_url = Dart_GetLibraryURL(id); |
1009 char const* chars; | 1010 char const* chars; |
1010 Dart_StringToCString(lib_url, &chars); | 1011 Dart_StringToCString(lib_url, &chars); |
1011 OS::Print("Lib %d: %s\n", i, chars); | 1012 OS::Print("Lib %d: %s\n", i, chars); |
1012 | 1013 |
1013 Dart_Handle scripts = Dart_GetScriptURLs(lib_url); | 1014 Dart_Handle scripts = Dart_GetScriptURLs(lib_url); |
1014 EXPECT(Dart_IsList(scripts)); | 1015 EXPECT(Dart_IsList(scripts)); |
1015 intptr_t num_scripts; | 1016 intptr_t num_scripts; |
1016 Dart_ListLength(scripts, &num_scripts); | 1017 Dart_ListLength(scripts, &num_scripts); |
1017 EXPECT(num_scripts >= 0); | 1018 EXPECT(num_scripts >= 0); |
1018 for (int i = 0; i < num_scripts; i++) { | 1019 for (int i = 0; i < num_scripts; i++) { |
1019 Dart_Handle script_url = Dart_ListGetAt(scripts, i); | 1020 Dart_Handle script_url = Dart_ListGetAt(scripts, i); |
1020 char const* chars; | 1021 char const* chars; |
1021 Dart_StringToCString(script_url, &chars); | 1022 Dart_StringToCString(script_url, &chars); |
1022 OS::Print(" script %d: '%s'\n", i + 1, chars); | 1023 OS::Print(" script %d: '%s'\n", i + 1, chars); |
1023 } | 1024 } |
1024 } | 1025 } |
1025 | 1026 |
1026 Dart_Handle lib_url = NewString(TestCase::url()); | 1027 Dart_Handle lib_url = NewString(TestCase::url()); |
1027 Dart_Handle source = Dart_ScriptGetSource((num_libs - 1), lib_url); | 1028 Dart_Handle source = Dart_ScriptGetSource((num_libs - 1), lib_url); |
1028 EXPECT(Dart_IsString(source)); | 1029 EXPECT(Dart_IsString(source)); |
1029 char const* source_chars; | 1030 char const* source_chars; |
1030 Dart_StringToCString(source, &source_chars); | 1031 Dart_StringToCString(source, &source_chars); |
1031 OS::Print("\n=== source: ===\n%s", source_chars); | 1032 OS::Print("\n=== source: ===\n%s", source_chars); |
1032 EXPECT_STREQ(kScriptChars, source_chars); | 1033 EXPECT_STREQ(kScriptChars, source_chars); |
1033 } | 1034 } |
1034 | 1035 |
1035 | 1036 |
1036 TEST_CASE(GetLibraryURLs) { | |
1037 const char* kScriptChars = | |
1038 "main() {" | |
1039 " return 12345;" | |
1040 "}"; | |
1041 | |
1042 Dart_Handle lib_list = Dart_GetLibraryURLs(); | |
1043 EXPECT_VALID(lib_list); | |
1044 EXPECT(Dart_IsList(lib_list)); | |
1045 Dart_Handle list_as_string = Dart_ToString(lib_list); | |
1046 const char* list_cstr = ""; | |
1047 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr)); | |
1048 EXPECT_NOTSUBSTRING(TestCase::url(), list_cstr); | |
1049 | |
1050 // Load a script. | |
1051 Dart_Handle url = NewString(TestCase::url()); | |
1052 Dart_Handle source = NewString(kScriptChars); | |
1053 EXPECT_VALID(Dart_LoadScript(url, source, 0, 0)); | |
1054 | |
1055 lib_list = Dart_GetLibraryURLs(); | |
1056 EXPECT_VALID(lib_list); | |
1057 EXPECT(Dart_IsList(lib_list)); | |
1058 list_as_string = Dart_ToString(lib_list); | |
1059 list_cstr = ""; | |
1060 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr)); | |
1061 EXPECT_SUBSTRING(TestCase::url(), list_cstr); | |
1062 } | |
1063 | |
1064 | |
1065 static Dart_IsolateId test_isolate_id = ILLEGAL_ISOLATE_ID; | 1037 static Dart_IsolateId test_isolate_id = ILLEGAL_ISOLATE_ID; |
1066 static int verify_callback = 0; | 1038 static int verify_callback = 0; |
1067 static void TestIsolateID(Dart_IsolateId isolate_id, Dart_IsolateEvent kind) { | 1039 static void TestIsolateID(Dart_IsolateId isolate_id, Dart_IsolateEvent kind) { |
1068 if (kind == kCreated) { | 1040 if (kind == kCreated) { |
1069 EXPECT(test_isolate_id == ILLEGAL_ISOLATE_ID); | 1041 EXPECT(test_isolate_id == ILLEGAL_ISOLATE_ID); |
1070 test_isolate_id = isolate_id; | 1042 test_isolate_id = isolate_id; |
1071 Dart_Isolate isolate = Dart_GetIsolate(isolate_id); | 1043 Dart_Isolate isolate = Dart_GetIsolate(isolate_id); |
1072 EXPECT(isolate == Dart_CurrentIsolate()); | 1044 EXPECT(isolate == Dart_CurrentIsolate()); |
1073 verify_callback |= 0x1; // Register create callback. | 1045 verify_callback |= 0x1; // Register create callback. |
1074 } else if (kind == kInterrupted) { | 1046 } else if (kind == kInterrupted) { |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 | 1517 |
1546 Dart_Handle retval = Invoke("main"); | 1518 Dart_Handle retval = Invoke("main"); |
1547 EXPECT(Dart_IsError(retval)); | 1519 EXPECT(Dart_IsError(retval)); |
1548 EXPECT(Dart_IsUnhandledExceptionError(retval)); | 1520 EXPECT(Dart_IsUnhandledExceptionError(retval)); |
1549 EXPECT_EQ(1, breakpoint_hit_counter); | 1521 EXPECT_EQ(1, breakpoint_hit_counter); |
1550 } | 1522 } |
1551 | 1523 |
1552 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 1524 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
1553 | 1525 |
1554 } // namespace dart | 1526 } // namespace dart |
OLD | NEW |