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 runtime_->Enable();
36 // 18: breakpointer line
37 location_ = TestUtil::GetLocation(sourceFile_.c_str(), 18, 0, pandaFile_.c_str());
38 ASSERT_TRUE(location_.GetMethodId().IsValid());
39 TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE);
40 ASSERT_EQ(moduleName, pandaFile_);
41 ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_));
42 auto condFuncRef = FunctionRef::Undefined(vm_);
43 auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef);
44 ASSERT_TRUE(ret);
45 return true;
46 };
47
48 scenario = [this]() {
49 TestUtil::WaitForLoadModule();
50 TestUtil::Continue();
51 TestUtil::WaitForBreakpoint(location_);
52 TestUtil::Continue();
53 auto ret = debugInterface_->RemoveBreakpoint(location_);
54 ASSERT_TRUE(ret);
55 ASSERT_EXITED();
56 return true;
57 };
58
59 vmDeath = [this]() {
60 ASSERT_EQ(breakpointCounter_, 1U); // 1: break point
61 return true;
62 };
63 }
64
GetEntryPoint()65 std::pair<std::string, std::string> GetEntryPoint() override
66 {
67 return {pandaFile_, entryPoint_};
68 }
69 ~JsBreakpointArrowTest() = default;
70
71 private:
72 std::string pandaFile_ = DEBUGGER_ABC_DIR "arrow_func.abc";
73 std::string sourceFile_ = DEBUGGER_JS_DIR "arrow_func.js";
74 std::string entryPoint_ = "_GLOBAL::func_main_0";
75 JSPtLocation location_ {nullptr, JSPtLocation::EntityId(0), 0};
76 size_t breakpointCounter_ = 0;
77 };
78
GetJsBreakpointArrowTest()79 std::unique_ptr<TestEvents> GetJsBreakpointArrowTest()
80 {
81 return std::make_unique<JsBreakpointArrowTest>();
82 }
83 } // namespace panda::ecmascript::tooling::test
84
85 #endif // ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_BREAKPOINT_ARROW_TEST_H
86