diff --git a/tooling/dynamic/agent/debugger_impl.cpp b/tooling/dynamic/agent/debugger_impl.cpp index dc691ef07729f950a9c115da777a38c54d044836..7c1fb2fa6a2e389d045657e6421dc468dc040518 100755 --- a/tooling/dynamic/agent/debugger_impl.cpp +++ b/tooling/dynamic/agent/debugger_impl.cpp @@ -608,12 +608,12 @@ std::optional DebuggerImpl::DispatcherImpl::Dispatch( break; } if (crossLanguageDebug) { - if (result != nullptr) { + if (result != nullptr && response.IsOk()) { return ReturnsValueToString(request.GetCallId(), result->ToJson()); } return ReturnsValueToString(request.GetCallId(), DispatchResponseToJson(response)); } - if (result) { + if (result != nullptr) { SendResponse(request, response, *result); } else { SendResponse(request, response); diff --git a/tooling/dynamic/test/debugger_impl_test.cpp b/tooling/dynamic/test/debugger_impl_test.cpp index b9ca3db279fe508a6088d3bc46e9146393d9e823..39ffee7bc90ce5dca03bf7afb2c2c847b8fe675f 100644 --- a/tooling/dynamic/test/debugger_impl_test.cpp +++ b/tooling/dynamic/test/debugger_impl_test.cpp @@ -784,6 +784,75 @@ HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetSymbolBreakpoints_002) } } +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetSymbolBreakpoints_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()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + ecmaVm->GetJsDebuggerManager()->SetDebugMode(true); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.setSymbolicBreakpoints", + "params":{ + "symbolicBreakpoints":[ + { + "functionName":"testDebug" + } + ] + } + })"; + DispatchRequest request(msg); + std::optional result = dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})"); + EXPECT_FALSE(result.has_value()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetSymbolBreakpoints_004) +{ + 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)); + ecmaVm->GetJsDebuggerManager()->SetDebugMode(true); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.setSymbolicBreakpoints", + "params":{ + "symbolicBreakpoints":[ + { + "functionName":"testDebug" + } + ] + } + })"; + DispatchRequest request(msg); + std::optional result = dispatcherImpl->Dispatch(request, true); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), ""); + EXPECT_STREQ(result.value().c_str(), R"({"id":0,"result":{}})"); + EXPECT_TRUE(result.has_value()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Resume__001) { std::string outStrForCallbackCheck = ""; @@ -1412,9 +1481,13 @@ HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpoint__0 } } -HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpointByUrl__001) +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpointByUrl__003) { - ProtocolChannel *protocolChannel = new ProtocolHandler(nullptr, ecmaVm); + 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)); @@ -1431,9 +1504,64 @@ HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpointByU } })"; DispatchRequest request(msg); - std::unique_ptr resPtr; - DispatchResponse response = dispatcherImpl->GetPossibleAndSetBreakpointByUrl(request, resPtr); - EXPECT_STREQ(response.GetMessage().c_str(), "GetPossibleAndSetBreakpointByUrl: debugger agent is not enabled"); + std::optional response = dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"GetPossibleAndSetBreakpointByUrl: debugger agent is not enabled"}})"); + EXPECT_FALSE(response.has_value()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpointByUrl__004) +{ + 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)); + + EXPECT_FALSE(ecmaVm->GetJsDebuggerManager()->IsDebugMode()); + + std::string msg1 = std::string() + + R"({ + "id":0, + "method":"Debugger.enable", + "params":{ + "maxScriptsCacheSize":1024, + "options":[ + "enableLaunchAccelerate" + ] + } + })"; + DispatchRequest request1(msg1); + dispatcherImpl->Dispatch(request1); + EXPECT_TRUE(ecmaVm->GetJsDebuggerManager()->IsDebugMode()); + + outStrForCallbackCheck = ""; + std::string msg2 = std::string() + + R"({ + "id":0, + "method":"Debugger.getPossibleAndSetBreakpointByUrl", + "params":{ + "locations":[ + { + "lineNumber":3, + "columnNumber":20, + "url":"Index.ets" + }] + } + })"; + DispatchRequest request2(msg2); + std::optional response = dispatcherImpl->Dispatch(request2, true); + EXPECT_TRUE(response.has_value()); + EXPECT_STREQ(response.value().c_str(), + R"({"id":0,"result":{"locations":[{"lineNumber":3,"columnNumber":20,"id":"invalid","scriptId":0}]}})"); + EXPECT_TRUE(outStrForCallbackCheck.empty()); if (protocolChannel) { delete protocolChannel; protocolChannel = nullptr;