diff options
Diffstat (limited to 'tests/auto/qml/qqmlproperty')
-rw-r--r-- | tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp | 88 |
1 files changed, 87 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp index f8af13582e..c4b2325843 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -326,10 +326,16 @@ class PropertyObject : public QObject Q_PROPERTY(int propertyWithNotify READ propertyWithNotify WRITE setPropertyWithNotify NOTIFY oddlyNamedNotifySignal) Q_PROPERTY(MyQmlObject *qmlObject READ qmlObject) Q_PROPERTY(MyQObject *qObject READ qObject WRITE setQObject NOTIFY qObjectChanged) + Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty) + Q_PROPERTY(char charProperty READ charProperty WRITE setCharProperty) + Q_PROPERTY(QChar qcharProperty READ qcharProperty WRITE setQcharProperty) + Q_PROPERTY(QChar constQChar READ constQChar STORED false CONSTANT FINAL) + Q_PROPERTY(char constChar READ constChar STORED false CONSTANT FINAL) + Q_PROPERTY(int constInt READ constInt STORED false CONSTANT FINAL) Q_CLASSINFO("DefaultProperty", "defaultProperty") public: - PropertyObject() : m_resetProperty(9), m_qObject(0) {} + PropertyObject() : m_resetProperty(9), m_qObject(0), m_stringProperty("foo") {} int defaultProperty() { return 10; } QRect rectProperty() { return QRect(10, 10, 1, 209); } @@ -361,6 +367,18 @@ public: } } + QString stringProperty() const { return m_stringProperty;} + char charProperty() const { return m_charProperty; } + QChar qcharProperty() const { return m_qcharProperty; } + + QChar constQChar() const { return 0x25cf; /* Unicode: black circle */ } + char constChar() const { return 'A'; } + int constInt() const { return 123456; } + + void setStringProperty(QString arg) { m_stringProperty = arg; } + void setCharProperty(char arg) { m_charProperty = arg; } + void setQcharProperty(QChar arg) { m_qcharProperty = arg; } + signals: void clicked(); void oddlyNamedNotifySignal(); @@ -374,6 +392,9 @@ private: int m_propertyWithNotify; MyQmlObject m_qmlObject; MyQObject *m_qObject; + QString m_stringProperty; + char m_charProperty; + QChar m_qcharProperty; }; QML_DECLARE_TYPE(PropertyObject); @@ -1382,6 +1403,71 @@ void tst_qqmlproperty::write() QCOMPARE(o.url(), result); } + // Char/string-property + { + PropertyObject o; + QQmlProperty charProperty(&o, "charProperty"); + QQmlProperty qcharProperty(&o, "qcharProperty"); + QQmlProperty stringProperty(&o, "stringProperty"); + + const int black_circle = 0x25cf; + + QCOMPARE(charProperty.write(QString("foo")), false); + QCOMPARE(charProperty.write('Q'), true); + QCOMPARE(charProperty.read(), QVariant('Q')); + QCOMPARE(charProperty.write(QString("t")), true); + QCOMPARE(charProperty.read(), QVariant('t')); + + QCOMPARE(qcharProperty.write(QString("foo")), false); + QCOMPARE(qcharProperty.write('Q'), true); + QCOMPARE(qcharProperty.read(), QVariant('Q')); + QCOMPARE(qcharProperty.write(QString("t")), true); + QCOMPARE(qcharProperty.read(), QVariant('t')); + QCOMPARE(qcharProperty.write(QChar(black_circle)), true); + QCOMPARE(qcharProperty.read(), QVariant(QChar(black_circle))); + + QCOMPARE(o.stringProperty(), QString("foo")); // Default value + QCOMPARE(stringProperty.write(QString("bar")), true); + QCOMPARE(o.stringProperty(), QString("bar")); + QCOMPARE(stringProperty.write(QVariant(1234)), true); + QCOMPARE(stringProperty.read().toString(), QString::number(1234)); + QCOMPARE(stringProperty.write(QChar(black_circle)), true); + QCOMPARE(stringProperty.read(), QVariant(QString(QChar(black_circle)))); + + { // char -> QString + QQmlComponent component(&engine); + component.setData("import Test 1.0\nPropertyObject { stringProperty: constChar }", QUrl()); + PropertyObject *obj = qobject_cast<PropertyObject*>(component.create()); + QVERIFY(obj != 0); + if (obj) { + QQmlProperty stringProperty(obj, "stringProperty"); + QCOMPARE(stringProperty.read(), QVariant(QString(obj->constChar()))); + } + } + + { // QChar -> QString + QQmlComponent component(&engine); + component.setData("import Test 1.0\nPropertyObject { stringProperty: constQChar }", QUrl()); + PropertyObject *obj = qobject_cast<PropertyObject*>(component.create()); + QVERIFY(obj != 0); + if (obj) { + QQmlProperty stringProperty(obj, "stringProperty"); + QCOMPARE(stringProperty.read(), QVariant(QString(obj->constQChar()))); + } + } + + { // int -> QString + QQmlComponent component(&engine); + component.setData("import Test 1.0\nPropertyObject { stringProperty: constInt }", QUrl()); + PropertyObject *obj = qobject_cast<PropertyObject*>(component.create()); + QVERIFY(obj != 0); + if (obj) { + QQmlProperty stringProperty(obj, "stringProperty"); + QCOMPARE(stringProperty.read(), QVariant(QString::number(obj->constInt()))); + } + } + } + // VariantMap-property QVariantMap vm; vm.insert("key", "value"); |