summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2014-08-16 11:38:30 +0200
committerOlivier Goffart <ogoffart@woboq.com>2014-10-30 13:29:15 +0100
commit8c77a7f77a8111bcbe51532f788679777910ebd5 (patch)
treec6e0b40eecaed820e0040531954d0725f4867381 /tests
parentd9e8571f4de47d3587de07aaff71eadff771f1e2 (diff)
Make Q_INVOKABLE work on Q_GADGET
Methods can be invoked with QMetaMethod::invokeOnGadget Change-Id: Id734868bb530b02587daf0f62bce01798ade2ac2 Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
index 1d39280afb..18de761e2a 100644
--- a/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
+++ b/tests/auto/corelib/kernel/qmetamethod/tst_qmetamethod.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -50,6 +51,8 @@ private slots:
void comparisonOperators();
void fromSignal();
+
+ void gadget();
};
struct CustomType { };
@@ -727,5 +730,51 @@ void tst_QMetaMethod::fromSignal()
#undef FROMSIGNAL_HELPER
}
+class MyGadget {
+ Q_GADGET
+public:
+ QString m_value;
+ Q_INVOKABLE void setValue(const QString &value) { m_value = value; }
+ Q_INVOKABLE QString getValue() { return m_value; }
+};
+
+void tst_QMetaMethod::gadget()
+{
+ int idx;
+
+ idx = MyGadget::staticMetaObject.indexOfMethod("setValue(QString)");
+ QVERIFY(idx >= 0);
+ QMetaMethod setValueMethod = MyGadget::staticMetaObject.method(idx);
+ QVERIFY(setValueMethod.isValid());
+
+ idx = MyGadget::staticMetaObject.indexOfMethod("getValue()");
+ QVERIFY(idx >= 0);
+ QMetaMethod getValueMethod = MyGadget::staticMetaObject.method(idx);
+ QVERIFY(getValueMethod.isValid());
+
+ {
+ MyGadget gadget;
+ QString string;
+
+ QVERIFY(getValueMethod.invokeOnGadget(&gadget, Q_RETURN_ARG(QString, string)));
+ QCOMPARE(string, gadget.m_value);
+
+ QVERIFY(setValueMethod.invokeOnGadget(&gadget, Q_ARG(QString, QLatin1String("hello"))));
+ QCOMPARE(gadget.m_value, QLatin1String("hello"));
+
+ QVERIFY(getValueMethod.invokeOnGadget(&gadget, Q_RETURN_ARG(QString, string)));
+ QCOMPARE(string, gadget.m_value);
+ }
+
+ {
+ // Call with null should not crash
+ MyGadget *gadget = Q_NULLPTR;
+ QString string;
+ QVERIFY(!setValueMethod.invokeOnGadget(gadget, Q_ARG(QString, QLatin1String("hi"))));
+ QVERIFY(!getValueMethod.invokeOnGadget(gadget, Q_RETURN_ARG(QString, string)));
+ }
+}
+
+
QTEST_MAIN(tst_QMetaMethod)
#include "tst_qmetamethod.moc"