Skip to content

Commit

Permalink
Fix method invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Waqar144 committed Jul 30, 2024
1 parent f3ca677 commit 4284dd1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/tools/objectinspector/methodsextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ void MethodsExtension::invokeMethod(Qt::ConnectionType connectionType)
return;
}

const QVector<MethodArgument> args = m_methodArgumentModel->arguments();
const QVector<MethodArgument> methodArgs = m_methodArgumentModel->arguments();
QVector<QGenericArgument> 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(
Expand Down
34 changes: 34 additions & 0 deletions tests/methodmodeltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
#include "baseprobetest.h"
#include "testhelpers.h"

#include "common/objectbroker.h"
#include <core/objectmethodmodel.h>
#include <ui/tools/objectinspector/clientmethodmodel.h>
#include <common/tools/objectinspector/methodmodel.h>
#include <common/tools/objectinspector/methodsextensioninterface.h>
#include <core/tools/objectinspector/methodsextension.h>

#include <3rdparty/qt/modeltest.h>

#include <QDebug>
#include <QItemSelectionModel>

#ifndef Q_MOC_RUN
#define MY_TAG
Expand Down Expand Up @@ -48,6 +52,15 @@ public slots:
}
#endif

void bumpI()
{
// printf("Bump Idx Called\n");
i++;
}

private:
int i = 0;

private slots:
void modelTest()
{
Expand Down Expand Up @@ -114,6 +127,27 @@ private slots:
QVERIFY(idx.sibling(idx.row(), i).data(Qt::ToolTipRole).toString().contains(toolTip));
}
}

void testInvokeMethod()
{
auto iface = ObjectBroker::object<MethodsExtensionInterface *>("com.kdab.GammaRay.ObjectInspector.methodsExtension");
auto model = ObjectBroker::model("com.kdab.GammaRay.ObjectInspector.methods");
auto selModel = ObjectBroker::selectionModel(model);

static_cast<MethodsExtension *>(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)
Expand Down

0 comments on commit 4284dd1

Please sign in to comment.