From 4284dd1eb7dc0fd0ed79a5a1158b44b8f3e66a0b Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Tue, 30 Jul 2024 17:18:58 +0500 Subject: [PATCH] Fix method invocation --- .../objectinspector/methodsextension.cpp | 3 +- tests/methodmodeltest.cpp | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/core/tools/objectinspector/methodsextension.cpp b/core/tools/objectinspector/methodsextension.cpp index aaf6a20f40..0788a8c16e 100644 --- a/core/tools/objectinspector/methodsextension.cpp +++ b/core/tools/objectinspector/methodsextension.cpp @@ -133,7 +133,8 @@ void MethodsExtension::invokeMethod(Qt::ConnectionType connectionType) return; } - const QVector args = m_methodArgumentModel->arguments(); + const QVector methodArgs = m_methodArgumentModel->arguments(); + QVector args(methodArgs.begin(), methodArgs.end()); // TODO retrieve return value and add it to the log in case of success // TODO measure execution time and that to the log const bool result = method.invoke( diff --git a/tests/methodmodeltest.cpp b/tests/methodmodeltest.cpp index f3280503a7..895049feb3 100644 --- a/tests/methodmodeltest.cpp +++ b/tests/methodmodeltest.cpp @@ -14,13 +14,17 @@ #include "baseprobetest.h" #include "testhelpers.h" +#include "common/objectbroker.h" #include #include #include +#include +#include #include <3rdparty/qt/modeltest.h> #include +#include #ifndef Q_MOC_RUN #define MY_TAG @@ -48,6 +52,15 @@ public slots: } #endif + void bumpI() + { + // printf("Bump Idx Called\n"); + i++; + } + +private: + int i = 0; + private slots: void modelTest() { @@ -114,6 +127,27 @@ private slots: QVERIFY(idx.sibling(idx.row(), i).data(Qt::ToolTipRole).toString().contains(toolTip)); } } + + void testInvokeMethod() + { + auto iface = ObjectBroker::object("com.kdab.GammaRay.ObjectInspector.methodsExtension"); + auto model = ObjectBroker::model("com.kdab.GammaRay.ObjectInspector.methods"); + auto selModel = ObjectBroker::selectionModel(model); + + static_cast(iface)->setQObject(this); + + QVERIFY(model->rowCount() > 0); + + auto idx = searchContainsIndex(model, "bumpI()"); + QVERIFY(idx.isValid()); + + selModel->select(idx, QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect); + + iface->activateMethod(); + iface->invokeMethod(Qt::AutoConnection); + + QCOMPARE(i, 1); + } }; QTEST_MAIN(MethodModelTest)