a30980f251f2b62dcbfd4edc31f75c222b70098e
[profile/ivi/qtdeclarative.git] / tests / auto / qtquick2 / qquickflipable / tst_qquickflipable.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 #include <qtest.h>
42 #include <QtDeclarative/qdeclarativeengine.h>
43 #include <QtDeclarative/qdeclarativecomponent.h>
44 #include <QtQuick/qquickview.h>
45 #include <private/qquickflipable_p.h>
46 #include <private/qdeclarativevaluetype_p.h>
47 #include <QFontMetrics>
48 #include <QtQuick/private/qquickrectangle_p.h>
49 #include <math.h>
50 #include <QtOpenGL/QGLShaderProgram>
51 #include "../../shared/util.h"
52
53 class tst_qquickflipable : public QDeclarativeDataTest
54 {
55     Q_OBJECT
56 public:
57
58 private slots:
59     void create();
60     void checkFrontAndBack();
61     void setFrontAndBack();
62
63     // below here task issues
64     void QTBUG_9161_crash();
65     void QTBUG_8474_qgv_abort();
66
67 private:
68     QDeclarativeEngine engine;
69 };
70
71 void tst_qquickflipable::create()
72 {
73     QDeclarativeEngine engine;
74     QDeclarativeComponent 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     QDeclarativeEngine engine;
84     QDeclarativeComponent 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     QDeclarativeEngine engine;
96     QDeclarativeComponent 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::QTBUG_9161_crash()
114 {
115     QQuickView *canvas = new QQuickView;
116     canvas->setSource(testFileUrl("crash.qml"));
117     QQuickItem *root = canvas->rootObject();
118     QVERIFY(root != 0);
119     canvas->show();
120     delete canvas;
121 }
122
123 void tst_qquickflipable::QTBUG_8474_qgv_abort()
124 {
125     QQuickView *canvas = new QQuickView;
126     canvas->setSource(testFileUrl("flipable-abort.qml"));
127     QQuickItem *root = canvas->rootObject();
128     QVERIFY(root != 0);
129     canvas->show();
130     delete canvas;
131 }
132
133 QTEST_MAIN(tst_qquickflipable)
134
135 #include "tst_qquickflipable.moc"