• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_BREAKPOINT_ARROW_TEST_H
17 #define ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_BREAKPOINT_ARROW_TEST_H
18 
19 #include "test/utils/test_util.h"
20 
21 namespace panda::ecmascript::tooling::test {
22 class JsBreakpointArrowTest : public TestEvents {
23 public:
JsBreakpointArrowTest()24     JsBreakpointArrowTest()
25     {
26         breakpoint = [this](const JSPtLocation &location) {
27             ASSERT_TRUE(location.GetMethodId().IsValid());
28             ASSERT_LOCATION_EQ(location, location_);
29             ++breakpointCounter_;
30             TestUtil::SuspendUntilContinue(DebugEvent::BREAKPOINT, location);
31             return true;
32         };
33 
34         loadModule = [this](std::string_view moduleName) {
35             location_ = TestUtil::GetLocation(18, 0, pandaFile_.c_str()); // 18: breakpointer line
36             ASSERT_TRUE(location_.GetMethodId().IsValid());
37             TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE);
38             ASSERT_EQ(moduleName, pandaFile_);
39             ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_));
40             auto condFuncRef = FunctionRef::Undefined(vm_);
41             auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef);
42             ASSERT_TRUE(ret);
43             return true;
44         };
45 
46         scenario = [this]() {
47             TestUtil::WaitForLoadModule();
48             TestUtil::Continue();
49             TestUtil::WaitForBreakpoint(location_);
50             TestUtil::Continue();
51             auto ret = debugInterface_->RemoveBreakpoint(location_);
52             ASSERT_TRUE(ret);
53             ASSERT_EXITED();
54             return true;
55         };
56 
57         vmDeath = [this]() {
58             ASSERT_EQ(breakpointCounter_, 1U);  // 1: break point
59             return true;
60         };
61     }
62 
GetEntryPoint()63     std::pair<std::string, std::string> GetEntryPoint() override
64     {
65         return {pandaFile_, entryPoint_};
66     }
67     ~JsBreakpointArrowTest() = default;
68 
69 private:
70     std::string pandaFile_ = DEBUGGER_ABC_DIR "arrow_func.abc";
71     std::string entryPoint_ = "_GLOBAL::func_main_0";
72     JSPtLocation location_ {nullptr, JSPtLocation::EntityId(0), 0};
73     size_t breakpointCounter_ = 0;
74 };
75 
GetJsBreakpointArrowTest()76 std::unique_ptr<TestEvents> GetJsBreakpointArrowTest()
77 {
78     return std::make_unique<JsBreakpointArrowTest>();
79 }
80 }  // namespace panda::ecmascript::tooling::test
81 
82 #endif  // ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_BREAKPOINT_ARROW_TEST_H
83