1
2 /*
3 * Copyright (c) 2021 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "base/pt_params.h"
18 #include "base/pt_returns.h"
19 #include "base/pt_script.h"
20 #include "debugger_service.h"
21 #include "dispatcher.h"
22
23 #include "ecmascript/debugger/js_debugger.h"
24 #include "ecmascript/js_array.h"
25 #include "ecmascript/js_tagged_value-inl.h"
26 #include "ecmascript/object_factory.h"
27 #include "ecmascript/tests/test_helper.h"
28
29 using namespace panda::ecmascript;
30 using namespace panda::ecmascript::tooling;
31
32 namespace panda::test {
33 class DebuggerScriptTest : public testing::Test {
34 public:
SetUpTestCase()35 static void SetUpTestCase()
36 {
37 GTEST_LOG_(INFO) << "SetUpTestCase";
38 }
39
TearDownTestCase()40 static void TearDownTestCase()
41 {
42 GTEST_LOG_(INFO) << "TearDownCase";
43 }
44
SetUp()45 void SetUp() override
46 {
47 TestHelper::CreateEcmaVMWithScope(ecmaVm, thread, scope);
48 }
49
TearDown()50 void TearDown() override
51 {
52 TestHelper::DestroyEcmaVMWithScope(ecmaVm, scope);
53 }
54
55 protected:
56 EcmaVM *ecmaVm {nullptr};
57 EcmaHandleScope *scope {nullptr};
58 JSThread *thread {nullptr};
59 };
60
HWTEST_F_L0(DebuggerScriptTest,ScriptIdTest)61 HWTEST_F_L0(DebuggerScriptTest, ScriptIdTest)
62 {
63 std::unique_ptr<PtScript> script = std::make_unique<PtScript>(1, "name_1", "url_1", "source_1");
64 script->SetScriptId(100);
65 ASSERT_EQ(script->GetScriptId(), 100);
66 }
67
HWTEST_F_L0(DebuggerScriptTest,FileNameTest)68 HWTEST_F_L0(DebuggerScriptTest, FileNameTest)
69 {
70 std::unique_ptr<PtScript> script = std::make_unique<PtScript>(1, "name_1", "url_1", "source_1");
71 script->SetFileName("xx");
72 ASSERT_EQ(script->GetFileName(), "xx");
73 }
74
HWTEST_F_L0(DebuggerScriptTest,UrlTest)75 HWTEST_F_L0(DebuggerScriptTest, UrlTest)
76 {
77 std::unique_ptr<PtScript> script = std::make_unique<PtScript>(1, "name_1", "url_1", "source_1");
78 script->SetUrl("121");
79 ASSERT_EQ(script->GetUrl(), "121");
80 }
81
HWTEST_F_L0(DebuggerScriptTest,HashTest)82 HWTEST_F_L0(DebuggerScriptTest, HashTest)
83 {
84 std::unique_ptr<PtScript> script = std::make_unique<PtScript>(1, "name_1", "url_1", "source_1");
85 script->SetHash("111");
86 ASSERT_EQ(script->GetHash(), "111");
87 }
88
HWTEST_F_L0(DebuggerScriptTest,ScriptSourceTest)89 HWTEST_F_L0(DebuggerScriptTest, ScriptSourceTest)
90 {
91 std::unique_ptr<PtScript> script = std::make_unique<PtScript>(1, "name_1", "url_1", "source_1");
92 script->SetScriptSource("a=1");
93 ASSERT_EQ(script->GetScriptSource(), "a=1");
94 }
95
HWTEST_F_L0(DebuggerScriptTest,SourceMapUrlTest)96 HWTEST_F_L0(DebuggerScriptTest, SourceMapUrlTest)
97 {
98 std::unique_ptr<PtScript> script = std::make_unique<PtScript>(1, "name_1", "url_1", "source_1");
99 script->SetSourceMapUrl("192");
100 ASSERT_EQ(script->GetSourceMapUrl(), "192");
101 }
102
HWTEST_F_L0(DebuggerScriptTest,EndLineTest)103 HWTEST_F_L0(DebuggerScriptTest, EndLineTest)
104 {
105 std::unique_ptr<PtScript> script = std::make_unique<PtScript>(1, "name_1", "url_1", "source_1");
106 script->SetEndLine(200);
107 ASSERT_EQ(script->GetEndLine(), 200);
108 }
109 } // namespace panda::test