/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_BREAKPOINT_TEST_H #define ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_BREAKPOINT_TEST_H #include "test/utils/test_util.h" namespace panda::ecmascript::tooling::test { class JsBreakpointTest : public TestEvents { public: JsBreakpointTest() { breakpoint = [this](const JSPtLocation &location) { ASSERT_TRUE(location.GetMethodId().IsValid()); ASSERT_LOCATION_EQ(location, location_); ++breakpointCounter_; TestUtil::SuspendUntilContinue(DebugEvent::BREAKPOINT, location); return true; }; loadModule = [this](std::string_view moduleName) { runtime_->Enable(); // 22: breakpointer line location_ = TestUtil::GetLocation(sourceFile_.c_str(), 22, 0, pandaFile_.c_str()); ASSERT_TRUE(location_.GetMethodId().IsValid()); TestUtil::SuspendUntilContinue(DebugEvent::LOAD_MODULE); ASSERT_EQ(moduleName, pandaFile_); ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); auto condFuncRef = FunctionRef::Undefined(vm_); auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); ASSERT_TRUE(ret); return true; }; scenario = [this]() { TestUtil::WaitForLoadModule(); TestUtil::Continue(); TestUtil::WaitForBreakpoint(location_); TestUtil::Continue(); TestUtil::WaitForBreakpoint(location_); TestUtil::Continue(); auto ret = debugInterface_->RemoveBreakpoint(location_); ASSERT_TRUE(ret); ASSERT_EXITED(); return true; }; vmDeath = [this]() { ASSERT_EQ(breakpointCounter_, 2U); // 2: break point counter return true; }; } std::pair GetEntryPoint() override { return {pandaFile_, entryPoint_}; } ~JsBreakpointTest() = default; private: std::string pandaFile_ = DEBUGGER_ABC_DIR "sample.abc"; std::string sourceFile_ = DEBUGGER_JS_DIR "sample.js"; std::string entryPoint_ = "_GLOBAL::func_main_0"; JSPtLocation location_ {nullptr, JSPtLocation::EntityId(0), 0}; size_t breakpointCounter_ = 0; }; std::unique_ptr GetJsBreakpointTest() { return std::make_unique(); } } // namespace panda::ecmascript::tooling::test #endif // ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_BREAKPOINT_TEST_H