MCPcopy Create free account
hub / github.com/KDE/kdevelop / testQObjectCommandHandler

Method testQObjectCommandHandler

plugins/debuggercommon/tests/test_micommand.cpp:119–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117}
118
119void TestMICommand::testQObjectCommandHandler()
120{
121 KDevMI::MI::UserCommand command(KDevMI::MI::NonMI, "command");
122 command.setToken(1);
123
124 // set the handler and invoke
125 auto recordsHandled = 0;
126 auto resultHandler = std::make_unique<TestCommandResultHandler>(recordsHandled);
127 command.setHandler(resultHandler.get(), &TestCommandResultHandler::handleResult);
128
129 KDevMI::MI::ResultRecord resultRecord1("reason");
130 bool success = command.invokeHandler(resultRecord1);
131
132 // check
133 QVERIFY(success);
134 QCOMPARE(recordsHandled, 1);
135
136 // set the same resultHandler again, delete it, and verify that invoking does not crash
137 command.setHandler(resultHandler.get(), &TestCommandResultHandler::handleResult);
138 resultHandler.reset();
139
140 const KDevMI::MI::ResultRecord resultRecord2("reason");
141 success = command.invokeHandler(resultRecord2);
142
143 // setHandler() created an internal handler wrapper that still exists, hence the invocation succeeds
144 QVERIFY(success);
145 // the TestCommandResultHandler instance was destroyed before the invocation, so recordsHandled is unchanged
146 QCOMPARE(recordsHandled, 1);
147
148 // invoke once more, this time without a handler (each invocation resets the command's handler to nullptr)
149 success = command.invokeHandler(resultRecord2);
150
151 // invoking a null handler fails
152 QVERIFY(!success);
153 QCOMPARE(recordsHandled, 1);
154}
155
156
157QTEST_GUILESS_MAIN(TestMICommand)

Callers

nothing calls this directly

Calls 5

setTokenMethod · 0.80
setHandlerMethod · 0.60
getMethod · 0.45
invokeHandlerMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected