summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2014-08-03 13:37:01 +0200
committerOlivier Goffart <ogoffart@woboq.com>2014-10-30 13:29:10 +0100
commitd9e8571f4de47d3587de07aaff71eadff771f1e2 (patch)
treed79c9b0b23d0f0092f94331a17d7cea46fb6f097 /tests/auto
parentae981f224de9d2a24bfb1547e2049b6ccd9fc4ac (diff)
Be able to read and write properties to Q_GADGET
Change-Id: Ic12f465d31459748ca08ac8c457fd61a5773e2e2 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp
index 5cac80191c..941abf9039 100644
--- a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp
+++ b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.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,7 @@ private slots:
void hasStdCppSet();
void isConstant();
void isFinal();
+ void gadget();
public:
enum EnumType { EnumType1 };
@@ -103,5 +105,32 @@ void tst_QMetaProperty::isFinal()
QVERIFY(!prop.isFinal());
}
+class MyGadget {
+ Q_GADGET
+ Q_PROPERTY(QString value READ getValue WRITE setValue RESET resetValue)
+public:
+ QString m_value;
+ void setValue(const QString &value) { m_value = value; }
+ QString getValue() { return m_value; }
+ void resetValue() { m_value = QLatin1Literal("reset"); }
+};
+
+void tst_QMetaProperty::gadget()
+{
+ const QMetaObject *mo = &MyGadget::staticMetaObject;
+ QMetaProperty valueProp = mo->property(mo->indexOfProperty("value"));
+ QVERIFY(valueProp.isValid());
+ {
+ MyGadget g;
+ QString hello = QLatin1Literal("hello");
+ QVERIFY(valueProp.writeOnGadget(&g, hello));
+ QCOMPARE(g.m_value, QLatin1String("hello"));
+ QCOMPARE(valueProp.readOnGadget(&g), QVariant(hello));
+ QVERIFY(valueProp.resetOnGadget(&g));
+ QCOMPARE(valueProp.readOnGadget(&g), QVariant(QLatin1String("reset")));
+ }
+}
+
+
QTEST_MAIN(tst_QMetaProperty)
#include "tst_qmetaproperty.moc"