aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2011-07-26 10:34:53 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-26 06:29:54 +0200
commitdaf6a270888d2f70e57a838d0ba4adae954c3d22 (patch)
tree36eb0366bdfa11eb25ba050191040c55ad644a22 /tests
parent414b91ab7f11efaf89afb237d682507caec05eff (diff)
QDeclarativeView/QSGView SizeRootObjectToView still resizes view
Only resize view to object in SizeRootObjectToView if the view has not had a size set, i.e. at initial construction. Change-Id: Ic5ad3cbb3b071c3498047be893da2c7bf0957986 Fixes: QTBUG-15863 Reviewed-on: http://codereview.qt.nokia.com/2132 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qsgview/data/error1.qml5
-rw-r--r--tests/auto/declarative/qsgview/data/resizemodeitem.qml5
-rw-r--r--tests/auto/declarative/qsgview/qsgview.pro14
-rw-r--r--tests/auto/declarative/qsgview/tst_qsgview.cpp197
-rw-r--r--tests/auto/qtquick1/qdeclarativeview/tst_qdeclarativeview.cpp17
5 files changed, 238 insertions, 0 deletions
diff --git a/tests/auto/declarative/qsgview/data/error1.qml b/tests/auto/declarative/qsgview/data/error1.qml
new file mode 100644
index 0000000000..09df679555
--- /dev/null
+++ b/tests/auto/declarative/qsgview/data/error1.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+
+Rectangle {
+ nonExistentProperty: 5
+}
diff --git a/tests/auto/declarative/qsgview/data/resizemodeitem.qml b/tests/auto/declarative/qsgview/data/resizemodeitem.qml
new file mode 100644
index 0000000000..ed73009b26
--- /dev/null
+++ b/tests/auto/declarative/qsgview/data/resizemodeitem.qml
@@ -0,0 +1,5 @@
+import QtQuick 2.0
+Item {
+ width: 200
+ height: 200
+}
diff --git a/tests/auto/declarative/qsgview/qsgview.pro b/tests/auto/declarative/qsgview/qsgview.pro
new file mode 100644
index 0000000000..e6cb0785bb
--- /dev/null
+++ b/tests/auto/declarative/qsgview/qsgview.pro
@@ -0,0 +1,14 @@
+load(qttest_p4)
+contains(QT_CONFIG,declarative): QT += declarative gui
+macx:CONFIG -= app_bundle
+
+SOURCES += tst_qsgview.cpp
+
+symbian: {
+ importFiles.files = data
+ importFiles.path = .
+ DEPLOYMENT += importFiles
+} else {
+ DEFINES += SRCDIR=\\\"$$PWD\\\"
+}
+QT += core-private gui-private declarative-private
diff --git a/tests/auto/declarative/qsgview/tst_qsgview.cpp b/tests/auto/declarative/qsgview/tst_qsgview.cpp
new file mode 100644
index 0000000000..f2913cbd63
--- /dev/null
+++ b/tests/auto/declarative/qsgview/tst_qsgview.cpp
@@ -0,0 +1,197 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qtest.h>
+#include <QtTest/QSignalSpy>
+#include <QtDeclarative/qdeclarativecomponent.h>
+#include <QtDeclarative/qdeclarativecontext.h>
+#include <QtDeclarative/qsgview.h>
+#include <QtDeclarative/qsgitem.h>
+#include "../../../shared/util.h"
+
+#ifdef Q_OS_SYMBIAN
+// In Symbian OS test data is located in applications private dir
+#define SRCDIR "."
+#endif
+
+class tst_QSGView : public QObject
+
+{
+ Q_OBJECT
+public:
+ tst_QSGView();
+
+private slots:
+ void resizemodeitem();
+ void errors();
+};
+
+
+tst_QSGView::tst_QSGView()
+{
+}
+
+void tst_QSGView::resizemodeitem()
+{
+ QWidget window;
+ QSGView *canvas = new QSGView(&window);
+ QVERIFY(canvas);
+ canvas->setResizeMode(QSGView::SizeRootObjectToView);
+ QCOMPARE(QSize(0,0), canvas->initialSize());
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/resizemodeitem.qml"));
+ QSGItem* item = qobject_cast<QSGItem*>(canvas->rootObject());
+ QVERIFY(item);
+ window.show();
+
+ // initial size from root object
+ QCOMPARE(item->width(), 200.0);
+ QCOMPARE(item->height(), 200.0);
+ QCOMPARE(canvas->size(), QSize(200, 200));
+ QCOMPARE(canvas->size(), canvas->sizeHint());
+ QCOMPARE(canvas->size(), canvas->initialSize());
+
+ // size update from view
+ canvas->resize(QSize(80,100));
+ QCOMPARE(item->width(), 80.0);
+ QCOMPARE(item->height(), 100.0);
+ QCOMPARE(canvas->size(), QSize(80, 100));
+ QCOMPARE(canvas->size(), canvas->sizeHint());
+
+ canvas->setResizeMode(QSGView::SizeViewToRootObject);
+
+ // size update from view disabled
+ canvas->resize(QSize(60,80));
+ QCOMPARE(item->width(), 80.0);
+ QCOMPARE(item->height(), 100.0);
+ QCOMPARE(canvas->size(), QSize(60, 80));
+
+ // size update from root object
+ item->setWidth(250);
+ item->setHeight(350);
+ QCOMPARE(item->width(), 250.0);
+ QCOMPARE(item->height(), 350.0);
+ QTRY_COMPARE(canvas->size(), QSize(250, 350));
+ QCOMPARE(canvas->size(), QSize(250, 350));
+ QCOMPARE(canvas->size(), canvas->sizeHint());
+
+ // reset canvas
+ window.hide();
+ delete canvas;
+ canvas = new QSGView(&window);
+ QVERIFY(canvas);
+ canvas->setResizeMode(QSGView::SizeViewToRootObject);
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/resizemodeitem.qml"));
+ item = qobject_cast<QSGItem*>(canvas->rootObject());
+ QVERIFY(item);
+ window.show();
+
+ // initial size for root object
+ QCOMPARE(item->width(), 200.0);
+ QCOMPARE(item->height(), 200.0);
+ QCOMPARE(canvas->size(), canvas->sizeHint());
+ QCOMPARE(canvas->size(), canvas->initialSize());
+
+ // size update from root object
+ item->setWidth(80);
+ item->setHeight(100);
+ QCOMPARE(item->width(), 80.0);
+ QCOMPARE(item->height(), 100.0);
+ QTRY_COMPARE(canvas->size(), QSize(80, 100));
+ QCOMPARE(canvas->size(), QSize(80, 100));
+ QCOMPARE(canvas->size(), canvas->sizeHint());
+
+ // size update from root object disabled
+ canvas->setResizeMode(QSGView::SizeRootObjectToView);
+ item->setWidth(60);
+ item->setHeight(80);
+ QCOMPARE(canvas->width(), 80);
+ QCOMPARE(canvas->height(), 100);
+ QCOMPARE(QSize(item->width(), item->height()), canvas->sizeHint());
+
+ // size update from view
+ canvas->resize(QSize(200,300));
+ QCOMPARE(item->width(), 200.0);
+ QCOMPARE(item->height(), 300.0);
+ QCOMPARE(canvas->size(), QSize(200, 300));
+ QCOMPARE(canvas->size(), canvas->sizeHint());
+
+ delete canvas;
+
+ // if we set a specific size for the view then it should keep that size
+ // for SizeRootObjectToView mode.
+ canvas = new QSGView(&window);
+ canvas->resize(300, 300);
+ canvas->setResizeMode(QSGView::SizeRootObjectToView);
+ QCOMPARE(QSize(0,0), canvas->initialSize());
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/resizemodeitem.qml"));
+ item = qobject_cast<QSGItem*>(canvas->rootObject());
+ QVERIFY(item);
+ window.show();
+
+ // initial size from root object
+ QCOMPARE(item->width(), 300.0);
+ QCOMPARE(item->height(), 300.0);
+ QCOMPARE(canvas->size(), QSize(300, 300));
+ QCOMPARE(canvas->size(), canvas->sizeHint());
+ QCOMPARE(canvas->initialSize(), QSize(200, 200)); // initial object size
+
+ delete canvas;
+}
+
+static void silentErrorsMsgHandler(QtMsgType, const char *)
+{
+}
+
+void tst_QSGView::errors()
+{
+ QSGView *canvas = new QSGView;
+ QVERIFY(canvas);
+ QtMsgHandler old = qInstallMsgHandler(silentErrorsMsgHandler);
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/error1.qml"));
+ qInstallMsgHandler(old);
+ QVERIFY(canvas->status() == QSGView::Error);
+ QVERIFY(canvas->errors().count() == 1);
+ delete canvas;
+}
+
+
+QTEST_MAIN(tst_QSGView)
+
+#include "tst_qsgview.moc"
diff --git a/tests/auto/qtquick1/qdeclarativeview/tst_qdeclarativeview.cpp b/tests/auto/qtquick1/qdeclarativeview/tst_qdeclarativeview.cpp
index d98215126b..325071f489 100644
--- a/tests/auto/qtquick1/qdeclarativeview/tst_qdeclarativeview.cpp
+++ b/tests/auto/qtquick1/qdeclarativeview/tst_qdeclarativeview.cpp
@@ -192,6 +192,23 @@ void tst_QDeclarativeView::resizemodedeclarativeitem()
QCOMPARE(sceneResizedSpy2.count(), 3);
delete canvas;
+
+ canvas = new QDeclarativeView(&window);
+ canvas->resize(300, 300);
+ canvas->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+ QCOMPARE(QSize(0,0), canvas->initialSize());
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/resizemodedeclarativeitem.qml"));
+ declarativeItem = qobject_cast<QDeclarativeItem*>(canvas->rootObject());
+ QVERIFY(declarativeItem);
+ window.show();
+
+ // initial size from root object
+ QCOMPARE(declarativeItem->width(), 300.0);
+ QCOMPARE(declarativeItem->height(), 300.0);
+ QCOMPARE(canvas->size(), QSize(300, 300));
+ QCOMPARE(canvas->size(), canvas->sizeHint());
+ QCOMPARE(canvas->initialSize(), QSize(200, 200));
+ delete canvas;
}
void tst_QDeclarativeView::resizemodegraphicswidget()