From 3d3a2ef8b0b1c96c3104c4eead3bad322c0349e0 Mon Sep 17 00:00:00 2001 From: duning Date: Thu, 7 Nov 2024 10:37:16 +0800 Subject: [PATCH] add testcase add testcase Issue:https://gitee.com/openharmony/arkcompiler_toolchain/issues/IB2MNY Signed-off-by: duning Change-Id: I80cc1bdb1156cb719a6a535256f73a8e41f97490 --- tooling/test/debugger_impl_test.cpp | 639 ++++++++++++++++++++++++++++ 1 file changed, 639 insertions(+) diff --git a/tooling/test/debugger_impl_test.cpp b/tooling/test/debugger_impl_test.cpp index 0fbb8811..d41db837 100644 --- a/tooling/test/debugger_impl_test.cpp +++ b/tooling/test/debugger_impl_test.cpp @@ -52,6 +52,8 @@ private: }; } + + namespace panda::test { class DebuggerImplTest : public testing::Test { public: @@ -1783,6 +1785,643 @@ HWTEST_F_L0(DebuggerImplTest, CheckAndGenerateCondFunc__001) ASSERT_TRUE(debugger->DecodeAndCheckBase64(msg, dest)); } +HWTEST_F_L0(DebuggerImplTest, ConvertToLocal__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto debugger = std::make_unique(debuggerImpl); + Local taggedValue = debugger->ConvertToLocal(""); + ASSERT_TRUE(!taggedValue.IsEmpty()); + taggedValue = debugger->ConvertToLocal("false"); + ASSERT_TRUE(!taggedValue.IsEmpty()); + taggedValue = debugger->ConvertToLocal("true"); + ASSERT_TRUE(!taggedValue.IsEmpty()); + taggedValue = debugger->ConvertToLocal("undefined"); + ASSERT_TRUE(!taggedValue.IsEmpty()); + taggedValue = debugger->ConvertToLocal("\"test\""); + ASSERT_TRUE(!taggedValue.IsEmpty()); + taggedValue = debugger->ConvertToLocal("test"); + ASSERT_TRUE(taggedValue.IsEmpty()); + taggedValue = debugger->ConvertToLocal("1"); + ASSERT_TRUE(!taggedValue.IsEmpty()); +} +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpoint__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + ecmaVm->GetJsDebuggerManager()->SetDebugMode(true); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.getPossibleAndSetBreakpointByUrl", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"GetPossibleAndSetBreakpointByUrl: no pennding breakpoint exists"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpoint__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + ecmaVm->GetJsDebuggerManager()->SetDebugMode(true); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.getPossibleAndSetBreakpointByUrl", + "params":{ + "locations":[ + { + "lineNumber":3, + "columnNumber":20, + "url":"Index.ets" + }] + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"locations":[{"lineNumber":3,"columnNumber":20,"id":"invalid","scriptId":0}]}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_DropFrame__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + debuggerImpl->SetDebuggerState(DebuggerState::PAUSED); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.dropFrame", + "params":{ + "droppedDepth":3 + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"Not yet support dropping multiple frames"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, DispatcherImplCallFunctionOn) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + R"({"id":0,"method":"Debugger.callFunctionOn","params":{ + "callFrameId":"0", "functionDeclaration":0}})"; + DispatchRequest request(msg); + dispatcherImpl->CallFunctionOn(request); + ASSERT_TRUE(outStrForCallbackCheck.find("wrong params") != std::string::npos); + + msg = std::string() + R"({"id":0,"method":"Debugger.callFunctionOn","params":{ + "callFrameId":"0", "functionDeclaration":"test"}})"; + DispatchRequest request1(msg); + dispatcherImpl->CallFunctionOn(request1); + ASSERT_TRUE(outStrForCallbackCheck.find("Unsupport eval now") == std::string::npos); + if (protocolChannel != nullptr) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SmartStepInto__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.smartStepInto", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SmartStepInto__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.smartStepInto", + "params":{ + "lineNumber":0, + "url":"url_str", + "urlRegex":"urlRegex_str", + "scriptHash":"scriptHash_str", + "columnNumber":0, + "condition":"condition_str" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"Can only perform operation while paused"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SmartStepInto__003) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + debuggerImpl->SetDebuggerState(DebuggerState::PAUSED); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.smartStepInto", + "params":{ + "lineNumber":0, + "url":"url_str", + "urlRegex":"urlRegex_str", + "scriptHash":"scriptHash_str", + "columnNumber":0, + "condition":"condition_str" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"SetBreakpointByUrl: debugger agent is not enabled"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetNativeRange__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.setNativeRange", + "params":{ + "nativeRange":"" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetNativeRange__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.setNativeRange", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ResetSingleStepper__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.resetSingleStepper", + "params":{ + "resetSingleStepper":"test" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ResetSingleStepper__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.resetSingleStepper", + "params":{ + "resetSingleStepper":true + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ClientDisconnect) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.clientDisconnect", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"()"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_CallFunctionOn__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.callFunctionOn", + "params":{ + "callFrameId":"1", + "functionDeclaration":"test" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"Invalid callFrameId."}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_CallFunctionOn__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.callFunctionOn", + "params":{ + "callFrameId":"0", + "functionDeclaration":0 + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, NativeOutTest) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr jspthooks = std::make_unique(debuggerImpl.get()); + bool result1 = jspthooks->NativeOut(); + ASSERT_TRUE(!result1); + bool value = true; + debuggerImpl->SetNativeOutPause(value); + bool result2 = jspthooks->NativeOut(); + ASSERT_TRUE(result2); + ASSERT_NE(jspthooks, nullptr); +} + +HWTEST_F_L0(DebuggerImplTest, NotifyNativeReturn__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr json = PtJson::CreateObject(); + json->Add("enabled", false); + json->Add("mixedStackEnabled", false); + std::unique_ptr params = SetMixedDebugParams::Create(*json); + debuggerImpl->SetMixedDebugEnabled(*params); + debuggerImpl->NotifyNativeReturn(nullptr); + auto debugger = std::make_unique(debuggerImpl); + ASSERT_TRUE(!debugger->GetMixStackEnabled()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, NotifyNativeReturn__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr json = PtJson::CreateObject(); + json->Add("enabled", false); + json->Add("mixedStackEnabled", true); + std::unique_ptr params = SetMixedDebugParams::Create(*json); + debuggerImpl->SetMixedDebugEnabled(*params); + debuggerImpl->NotifyNativeReturn(nullptr); + auto debugger = std::make_unique(debuggerImpl); + ASSERT_TRUE(debugger->GetMixStackEnabled()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, NotifyReturnNative__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr json = PtJson::CreateObject(); + json->Add("enabled", false); + json->Add("mixedStackEnabled", true); + std::unique_ptr params = SetMixedDebugParams::Create(*json); + debuggerImpl->SetMixedDebugEnabled(*params); + debuggerImpl->NotifyReturnNative(); + auto debugger = std::make_unique(debuggerImpl); + ASSERT_TRUE(debugger->GetMixStackEnabled()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, NotifyReturnNative__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr json = PtJson::CreateObject(); + json->Add("enabled", false); + json->Add("mixedStackEnabled", false); + std::unique_ptr params = SetMixedDebugParams::Create(*json); + debuggerImpl->SetMixedDebugEnabled(*params); + debuggerImpl->NotifyReturnNative(); + auto debugger = std::make_unique(debuggerImpl); + ASSERT_TRUE(!debugger->GetMixStackEnabled()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, NotifyNativeCalling__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr json = PtJson::CreateObject(); + json->Add("enabled", false); + json->Add("mixedStackEnabled", false); + std::unique_ptr params = SetMixedDebugParams::Create(*json); + debuggerImpl->SetMixedDebugEnabled(*params); + debuggerImpl->NotifyNativeCalling(nullptr); + auto debugger = std::make_unique(debuggerImpl); + ASSERT_TRUE(!debugger->GetMixStackEnabled()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, NotifyNativeCalling__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + std::unique_ptr json = PtJson::CreateObject(); + json->Add("enabled", false); + json->Add("mixedStackEnabled", true); + std::unique_ptr params = SetMixedDebugParams::Create(*json); + debuggerImpl->SetMixedDebugEnabled(*params); + debuggerImpl->NotifyNativeCalling(nullptr); + auto debugger = std::make_unique(debuggerImpl); + ASSERT_TRUE(debugger->GetMixStackEnabled()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, CheckAndGenerateCondFunc__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto debugger = std::make_unique(debuggerImpl); + std::vector dest; + debugger->CheckAndGenerateCondFunc(""); + ASSERT_TRUE(!debugger->DecodeAndCheckBase64("", dest)); + std::string msg = "UEFOREEAAAAAAAAADAACAEgBAAAAAAAAAAAAAAIAAAA8AAAAAQAA"; + msg += "AEQBAAAAAAARAAAAAEAAABEAAAAkQAAAMQAAAB8AAAASAEAAAIAAABsAAAAAgAAAHQAAAD//////////"; + debugger->CheckAndGenerateCondFunc(msg); + ASSERT_TRUE(debugger->DecodeAndCheckBase64(msg, dest)); +} + HWTEST_F_L0(DebuggerImplTest, ConvertToLocal__001) { std::string outStrForCallbackCheck = ""; -- Gitee