mirror of
https://gitee.com/openharmony/arkcompiler_toolchain
synced 2025-02-17 07:38:22 +00:00
!805 Add debugger_impl.cpp Dispatch testcase
Merge pull request !805 from 叶江浩/yjh_br_coverage0806
This commit is contained in:
commit
197e93de81
@ -1241,6 +1241,313 @@ HWTEST_F_L0(DebuggerImplTest, DispatcherImplCallFunctionOn)
|
||||
protocolChannel = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SmartStepInto__001)
|
||||
{
|
||||
std::string outStrForCallbackCheck = "";
|
||||
std::function<void(const void*, const std::string &)> callback =
|
||||
[&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
|
||||
outStrForCallbackCheck = inStrOfReply;};
|
||||
ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
|
||||
auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
|
||||
auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
|
||||
outStrForCallbackCheck = inStrOfReply;};
|
||||
ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
|
||||
auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
|
||||
auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
|
||||
outStrForCallbackCheck = inStrOfReply;};
|
||||
ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
|
||||
auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
|
||||
debuggerImpl->SetDebuggerState(DebuggerState::PAUSED);
|
||||
auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
|
||||
outStrForCallbackCheck = inStrOfReply;};
|
||||
ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
|
||||
auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
|
||||
auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
|
||||
outStrForCallbackCheck = inStrOfReply;};
|
||||
ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
|
||||
auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
|
||||
auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
|
||||
outStrForCallbackCheck = inStrOfReply;};
|
||||
ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
|
||||
auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
|
||||
auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
|
||||
outStrForCallbackCheck = inStrOfReply;};
|
||||
ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
|
||||
auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
|
||||
auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
|
||||
outStrForCallbackCheck = inStrOfReply;};
|
||||
ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
|
||||
auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
|
||||
auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
|
||||
outStrForCallbackCheck = inStrOfReply;};
|
||||
ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
|
||||
auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
|
||||
auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(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<void(const void*, const std::string &)> callback =
|
||||
[&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
|
||||
outStrForCallbackCheck = inStrOfReply;};
|
||||
ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
|
||||
auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
|
||||
auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
|
||||
auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(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 = "";
|
||||
|
Loading…
x
Reference in New Issue
Block a user