From dadbeb5dea22d6248dbfd4e2b582eab29b9f079d Mon Sep 17 00:00:00 2001 From: duning Date: Thu, 4 Jul 2024 10:51:34 +0800 Subject: [PATCH] add testcase https://gitee.com/openharmony/arkcompiler_toolchain/issues/IAAHIB Signed-off-by: duning Change-Id: Ie1525e3a821305d401bb44df40845c45314bd75e --- tooling/test/debugger_impl_test.cpp | 60 +++++++++++++++++++++++++ tooling/test/heapprofiler_impl_test.cpp | 40 +++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/tooling/test/debugger_impl_test.cpp b/tooling/test/debugger_impl_test.cpp index 25d9fd86..c9b7f8e6 100644 --- a/tooling/test/debugger_impl_test.cpp +++ b/tooling/test/debugger_impl_test.cpp @@ -50,6 +50,42 @@ protected: JSThread *thread {nullptr}; }; +HWTEST_F_L0(DebuggerImplTest, NotifyNativeOut__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()); + EXPECT_FALSE(debuggerImpl->NotifyNativeOut()); +} + +HWTEST_F_L0(DebuggerImplTest, NotifyNativeReturn) +{ + 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->NotifyNativeReturn(nullptr); +} + +HWTEST_F_L0(DebuggerImplTest, NotifyReturnNative) +{ + 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->NotifyReturnNative(); +} + HWTEST_F_L0(DebuggerImplTest, NotifyScriptParsed__001) { std::string outStrForCallbackCheck = ""; @@ -259,6 +295,30 @@ HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_EvaluateOnCallFrame__003) } } +HWTEST_F_L0(DebuggerImplTest, EvaluateOnCallFrame__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)); + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.enable", + "params":{ + "maxScriptsCacheSize":"NotIntValue", + "callFrameId":"0", + "expression":"the expression" + } + })"; + DispatchRequest request1(msg); + dispatcherImpl->EvaluateOnCallFrame(request1); +} + HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleBreakpoints__001) { std::string outStrForCallbackCheck = ""; diff --git a/tooling/test/heapprofiler_impl_test.cpp b/tooling/test/heapprofiler_impl_test.cpp index fe021a45..f7cc05a7 100644 --- a/tooling/test/heapprofiler_impl_test.cpp +++ b/tooling/test/heapprofiler_impl_test.cpp @@ -49,6 +49,46 @@ protected: JSThread *thread {nullptr}; }; +HWTEST_F_L0(HeapProfilerImplTest, StartTrackingHeapObjects) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, channel); + auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); + std::string msg = ""; + DispatchRequest request(msg); + dispatcherImpl->StartTrackingHeapObjects(request); + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"trackAllocations":0}})"; + DispatchRequest request1(msg); + dispatcherImpl->StartTrackingHeapObjects(request1); + if (channel) { + delete channel; + channel = nullptr; + } +} + +HWTEST_F_L0(HeapProfilerImplTest, StopTrackingHeapObjects) +{ + std::string result = ""; + std::function callback = + [&result]([[maybe_unused]] const void *ptr, const std::string &temp) {result = temp;}; + ProtocolChannel *channel = new ProtocolHandler(callback, ecmaVm); + auto tracing = std::make_unique(ecmaVm, channel); + auto dispatcherImpl = std::make_unique(channel, std::move(tracing)); + std::string msg = ""; + DispatchRequest request(msg); + dispatcherImpl->StopTrackingHeapObjects(request); + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"reportProgress":0}})"; + DispatchRequest request1(msg); + dispatcherImpl->StopTrackingHeapObjects(request1); + if (channel) { + delete channel; + channel = nullptr; + } +} + HWTEST_F_L0(HeapProfilerImplTest, AddInspectedHeapObject) { ProtocolChannel *channel = nullptr; -- Gitee