summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qmlengine/tst_qmlengine.cpp
blob: 8c050cbe92e80c8971c34d2b54019f4dcec1bc63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <qtest.h>
#include <QtDeclarative/qml.h>
#include <QtDeclarative/QmlComponent>
#include <QtDeclarative/QmlEngine>

#include <QtCore/QDebug>
#include <QtCore/QFile>
#include <QtCore/QUrl>

class tst_qmlengine : public QObject
{
    Q_OBJECT
public:
    tst_qmlengine() {}

private slots:
    void valueTypeFunctions();

private:
    QmlEngine engine;
};

class MyTypeObject : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QPoint pointProperty READ pointProperty WRITE setPointProperty);
    Q_PROPERTY(QPointF pointFProperty READ pointFProperty WRITE setPointFProperty);
    Q_PROPERTY(QSize sizeProperty READ sizeProperty WRITE setSizeProperty);
    Q_PROPERTY(QSizeF sizeFProperty READ sizeFProperty WRITE setSizeFProperty);
    Q_PROPERTY(QRect rectProperty READ rectProperty WRITE setRectProperty NOTIFY rectPropertyChanged);
    Q_PROPERTY(QRectF rectFProperty READ rectFProperty WRITE setRectFProperty);
    
public:
    MyTypeObject() {}

    QPoint pointPropertyValue;
    QPoint pointProperty() const {
       return pointPropertyValue;
    }
    void setPointProperty(const QPoint &v) {
        pointPropertyValue = v;
    }

    QPointF pointFPropertyValue;
    QPointF pointFProperty() const {
       return pointFPropertyValue;
    }
    void setPointFProperty(const QPointF &v) {
        pointFPropertyValue = v;
    }

    QSize sizePropertyValue;
    QSize sizeProperty() const {
       return sizePropertyValue;
    }
    void setSizeProperty(const QSize &v) {
        sizePropertyValue = v;
    }

    QSizeF sizeFPropertyValue;
    QSizeF sizeFProperty() const {
       return sizeFPropertyValue;
    }
    void setSizeFProperty(const QSizeF &v) {
        sizeFPropertyValue = v;
    }

    QRect rectPropertyValue;
    QRect rectProperty() const {
       return rectPropertyValue;
    }
    void setRectProperty(const QRect &v) {
        rectPropertyValue = v;
    }

    QRectF rectFPropertyValue;
    QRectF rectFProperty() const {
       return rectFPropertyValue;
    }
    void setRectFProperty(const QRectF &v) {
        rectFPropertyValue = v;
    }

};
QML_DECLARE_TYPE(MyTypeObject);
QML_DEFINE_TYPE(Test, 1, 0, 0, MyTypeObject, MyTypeObject);

void tst_qmlengine::valueTypeFunctions()
{
    QmlComponent component(&engine, SRCDIR "/functions.qml");
    MyTypeObject *obj = qobject_cast<MyTypeObject*>(component.create());
    QCOMPARE(obj->rectProperty(), QRect(0,0,100,100));
    QCOMPARE(obj->rectFProperty(), QRectF(0,0.5,100,99.5));
}

QTEST_MAIN(tst_qmlengine)

#include "tst_qmlengine.moc"