8c1c2489254813c65dcd015b6c86a2e3ac797cb0
[profile/ivi/qtdeclarative.git] / tests / auto / quick / qquickflipable / tst_qquickflipable.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #include <qtest.h>
42 #include <QtQml/qqmlengine.h>
43 #include <QtQml/qqmlcomponent.h>
44 #include <QtQuick/qquickview.h>
45 #include <private/qquickflipable_p.h>
46 #include <private/qqmlvaluetype_p.h>
47 #include <QFontMetrics>
48 #include <QtQuick/private/qquickrectangle_p.h>
49 #include <math.h>
50 #include "../../shared/util.h"
51
52 class tst_qquickflipable : public QQmlDataTest
53 {
54     Q_OBJECT
55 public:
56
57 private slots:
58     void create();
59     void checkFrontAndBack();
60     void setFrontAndBack();
61     void flipFlipable();
62
63     // below here task issues
64     void QTBUG_9161_crash();
65     void QTBUG_8474_qgv_abort();
66
67 private:
68     QQmlEngine engine;
69 };
70
71 void tst_qquickflipable::create()
72 {
73     QQmlEngine engine;
74     QQmlComponent c(&engine, testFileUrl("test-flipable.qml"));
75     QQuickFlipable *obj = qobject_cast<QQuickFlipable*>(c.create());
76
77     QVERIFY(obj != 0);
78     delete obj;
79 }
80
81 void tst_qquickflipable::checkFrontAndBack()
82 {
83     QQmlEngine engine;
84     QQmlComponent c(&engine, testFileUrl("test-flipable.qml"));
85     QQuickFlipable *obj = qobject_cast<QQuickFlipable*>(c.create());
86
87     QVERIFY(obj != 0);
88     QVERIFY(obj->front() != 0);
89     QVERIFY(obj->back() != 0);
90     delete obj;
91 }
92
93 void tst_qquickflipable::setFrontAndBack()
94 {
95     QQmlEngine engine;
96     QQmlComponent c(&engine, testFileUrl("test-flipable.qml"));
97     QQuickFlipable *obj = qobject_cast<QQuickFlipable*>(c.create());
98
99     QVERIFY(obj != 0);
100     QVERIFY(obj->front() != 0);
101     QVERIFY(obj->back() != 0);
102
103     QString message = c.url().toString() + ":3:1: QML Flipable: front is a write-once property";
104     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
105     obj->setFront(new QQuickRectangle());
106
107     message = c.url().toString() + ":3:1: QML Flipable: back is a write-once property";
108     QTest::ignoreMessage(QtWarningMsg, qPrintable(message));
109     obj->setBack(new QQuickRectangle());
110     delete obj;
111 }
112
113 void tst_qquickflipable::flipFlipable()
114 {
115     QQmlEngine engine;
116     QQmlComponent c(&engine, testFileUrl("flip-flipable.qml"));
117     QQuickFlipable *obj = qobject_cast<QQuickFlipable*>(c.create());
118     QVERIFY(obj != 0);
119     QVERIFY(obj->side() == QQuickFlipable::Front);
120     obj->setProperty("flipped", QVariant(true));
121     QTRY_VERIFY(obj->side() == QQuickFlipable::Back);
122     QTRY_VERIFY(obj->side() == QQuickFlipable::Front);
123     QTRY_VERIFY(obj->side() == QQuickFlipable::Back);
124     delete obj;
125 }
126
127 void tst_qquickflipable::QTBUG_9161_crash()
128 {
129     QQuickView *canvas = new QQuickView;
130     canvas->setSource(testFileUrl("crash.qml"));
131     QQuickItem *root = canvas->rootObject();
132     QVERIFY(root != 0);
133     canvas->show();
134     delete canvas;
135 }
136
137 void tst_qquickflipable::QTBUG_8474_qgv_abort()
138 {
139     QQuickView *canvas = new QQuickView;
140     canvas->setSource(testFileUrl("flipable-abort.qml"));
141     QQuickItem *root = canvas->rootObject();
142     QVERIFY(root != 0);
143     canvas->show();
144     delete canvas;
145 }
146
147 QTEST_MAIN(tst_qquickflipable)
148
149 #include "tst_qquickflipable.moc"