1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #include <QtTest/QSignalSpy>
43 #include <QtDeclarative/qdeclarativecomponent.h>
44 #include <QtDeclarative/qdeclarativecontext.h>
45 #include <QtDeclarative/qsgview.h>
46 #include <QtDeclarative/qsgitem.h>
47 #include "../shared/util.h"
48 #include "../../../shared/util.h"
49 #include <QtGui/QWindow>
50 #include <QtCore/QDebug>
52 class tst_QSGView : public QObject
59 void resizemodeitem();
64 tst_QSGView::tst_QSGView()
68 void tst_QSGView::resizemodeitem()
71 window.setGeometry(0, 0, 400, 400);
73 QSGView *canvas = new QSGView(&window);
75 canvas->setResizeMode(QSGView::SizeRootObjectToView);
76 QCOMPARE(QSize(0,0), canvas->initialSize());
77 canvas->setSource(QUrl::fromLocalFile(TESTDATA("resizemodeitem.qml")));
78 QSGItem* item = qobject_cast<QSGItem*>(canvas->rootObject());
84 // initial size from root object
85 QCOMPARE(item->width(), 200.0);
86 QCOMPARE(item->height(), 200.0);
87 QCOMPARE(canvas->size(), QSize(200, 200));
88 QCOMPARE(canvas->size(), canvas->sizeHint());
89 QCOMPARE(canvas->size(), canvas->initialSize());
91 // size update from view
92 canvas->resize(QSize(80,100));
95 QCOMPARE(item->width(), 80.0);
96 QCOMPARE(item->height(), 100.0);
97 QCOMPARE(canvas->size(), QSize(80, 100));
98 QCOMPARE(canvas->size(), canvas->sizeHint());
100 canvas->setResizeMode(QSGView::SizeViewToRootObject);
102 // size update from view disabled
103 canvas->resize(QSize(60,80));
104 QCOMPARE(item->width(), 80.0);
105 QCOMPARE(item->height(), 100.0);
107 QCOMPARE(canvas->size(), QSize(60, 80));
109 // size update from root object
111 item->setHeight(350);
112 QCOMPARE(item->width(), 250.0);
113 QCOMPARE(item->height(), 350.0);
114 QTRY_COMPARE(canvas->size(), QSize(250, 350));
115 QCOMPARE(canvas->size(), QSize(250, 350));
116 QCOMPARE(canvas->size(), canvas->sizeHint());
121 canvas = new QSGView(&window);
123 canvas->setResizeMode(QSGView::SizeViewToRootObject);
124 canvas->setSource(QUrl::fromLocalFile(TESTDATA("resizemodeitem.qml")));
125 item = qobject_cast<QSGItem*>(canvas->rootObject());
131 // initial size for root object
132 QCOMPARE(item->width(), 200.0);
133 QCOMPARE(item->height(), 200.0);
134 QCOMPARE(canvas->size(), canvas->sizeHint());
135 QCOMPARE(canvas->size(), canvas->initialSize());
137 // size update from root object
139 item->setHeight(100);
140 QCOMPARE(item->width(), 80.0);
141 QCOMPARE(item->height(), 100.0);
142 QTRY_COMPARE(canvas->size(), QSize(80, 100));
143 QCOMPARE(canvas->size(), QSize(80, 100));
144 QCOMPARE(canvas->size(), canvas->sizeHint());
146 // size update from root object disabled
147 canvas->setResizeMode(QSGView::SizeRootObjectToView);
150 QCOMPARE(canvas->width(), 80);
151 QCOMPARE(canvas->height(), 100);
152 QCOMPARE(QSize(item->width(), item->height()), canvas->sizeHint());
154 // size update from view
155 canvas->resize(QSize(200,300));
157 QCOMPARE(item->width(), 200.0);
158 QCOMPARE(item->height(), 300.0);
159 QCOMPARE(canvas->size(), QSize(200, 300));
160 QCOMPARE(canvas->size(), canvas->sizeHint());
165 // if we set a specific size for the view then it should keep that size
166 // for SizeRootObjectToView mode.
167 canvas = new QSGView(&window);
168 canvas->resize(300, 300);
169 canvas->setResizeMode(QSGView::SizeRootObjectToView);
170 QCOMPARE(QSize(0,0), canvas->initialSize());
171 canvas->setSource(QUrl::fromLocalFile(TESTDATA("resizemodeitem.qml")));
172 canvas->resize(300, 300);
173 item = qobject_cast<QSGItem*>(canvas->rootObject());
180 // initial size from root object
181 QEXPECT_FAIL("", "QTBUG-22019", Abort);
182 QCOMPARE(item->width(), 300.0);
183 QCOMPARE(item->height(), 300.0);
184 QCOMPARE(canvas->size(), QSize(300, 300));
185 QCOMPARE(canvas->size(), canvas->sizeHint());
186 QCOMPARE(canvas->initialSize(), QSize(200, 200)); // initial object size
191 static void silentErrorsMsgHandler(QtMsgType, const char *)
195 void tst_QSGView::errors()
197 QSGView *canvas = new QSGView;
199 QtMsgHandler old = qInstallMsgHandler(silentErrorsMsgHandler);
200 canvas->setSource(QUrl::fromLocalFile(TESTDATA("error1.qml")));
201 qInstallMsgHandler(old);
202 QVERIFY(canvas->status() == QSGView::Error);
203 QVERIFY(canvas->errors().count() == 1);
208 QTEST_MAIN(tst_QSGView)
210 #include "tst_qsgview.moc"