diff options
Diffstat (limited to 'tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp')
-rw-r--r-- | tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp index f296d9e..ef99173 100644 --- a/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp +++ b/tests/auto/declarative/qdeclarativeviewer/tst_qdeclarativeviewer.cpp @@ -43,7 +43,14 @@ #include <QtDeclarative/qdeclarativeengine.h> #include <QtDeclarative/qdeclarativeview.h> #include <QtDeclarative/qdeclarativeitem.h> +#include "../../../shared/util.h" #include "qmlruntime.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_QDeclarativeViewer : public QObject @@ -54,6 +61,11 @@ public: private slots: void orientation(); + void loading(); + void fileBrowser(); + void resizing(); + void paths(); + void slowMode(); private: QDeclarativeEngine engine; @@ -75,6 +87,10 @@ void tst_QDeclarativeViewer::orientation() QVERIFY(rootItem); window.show(); + QApplication::setActiveWindow(&window); + QTest::qWaitForWindowShown(&window); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&window)); + QCOMPARE(rootItem->width(), 200.0); QCOMPARE(rootItem->height(), 300.0); QCOMPARE(viewer->view()->size(), QSize(200, 300)); @@ -103,6 +119,200 @@ void tst_QDeclarativeViewer::orientation() QCOMPARE(viewer->size(), viewer->sizeHint()); } +void tst_QDeclarativeViewer::loading() +{ + QDeclarativeViewer *viewer = new QDeclarativeViewer(); + QVERIFY(viewer); + viewer->setSizeToView(true); + viewer->open(SRCDIR "/data/orientation.qml"); + QVERIFY(viewer->view()); + QVERIFY(viewer->menuBar()); + QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(viewer->view()->rootObject()); + QVERIFY(rootItem); + viewer->show(); + + QApplication::setActiveWindow(viewer); + QTest::qWaitForWindowShown(viewer); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(viewer)); + + // initial size + QTRY_COMPARE(rootItem->width(), 200.0); + QTRY_COMPARE(rootItem->height(), 300.0); + QCOMPARE(viewer->view()->size(), QSize(200, 300)); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); + QCOMPARE(viewer->size(), QSize(200, 300+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), viewer->sizeHint()); + + viewer->resize(QSize(400, 500)); + qApp->processEvents(); + + // window resized + QTRY_COMPARE(rootItem->width(), 400.0); + QTRY_COMPARE(rootItem->height(), 500.0-viewer->menuBar()->height()); + QCOMPARE(viewer->view()->size(), QSize(400, 500-viewer->menuBar()->height())); + QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(400, 500-viewer->menuBar()->height())); + QCOMPARE(viewer->size(), QSize(400, 500)); + QCOMPARE(viewer->size(), viewer->sizeHint()); + + viewer->reload(); + rootItem = qobject_cast<QDeclarativeItem*>(viewer->view()->rootObject()); + QVERIFY(rootItem); + + // reload cause the window to return back to initial size + QTRY_COMPARE(rootItem->width(), 200.0); + QTRY_COMPARE(rootItem->height(), 300.0); + QCOMPARE(viewer->view()->size(), QSize(200, 300)); + QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); + QCOMPARE(viewer->size(), QSize(200, 300+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), viewer->sizeHint()); + + viewer->resize(QSize(400, 500)); + qApp->processEvents(); + + // window resized again + QTRY_COMPARE(rootItem->width(), 400.0); + QTRY_COMPARE(rootItem->height(), 500.0-viewer->menuBar()->height()); + QCOMPARE(viewer->view()->size(), QSize(400, 500-viewer->menuBar()->height())); + QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(400, 500-viewer->menuBar()->height())); + QCOMPARE(viewer->size(), QSize(400, 500)); + QCOMPARE(viewer->size(), viewer->sizeHint()); + + viewer->open(SRCDIR "/data/orientation.qml"); + rootItem = qobject_cast<QDeclarativeItem*>(viewer->view()->rootObject()); + QVERIFY(rootItem); + + // open also causes the window to return back to initial size + QTRY_COMPARE(rootItem->width(), 200.0); + QTRY_COMPARE(rootItem->height(), 300.0); + QCOMPARE(viewer->view()->size(), QSize(200, 300)); + QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); + QCOMPARE(viewer->size(), QSize(200, 300+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), viewer->sizeHint()); +} + +void tst_QDeclarativeViewer::fileBrowser() +{ + QDeclarativeViewer *viewer = new QDeclarativeViewer(); + QVERIFY(viewer); + viewer->setUseNativeFileBrowser(false); + viewer->openFile(); + viewer->show(); + + QApplication::setActiveWindow(viewer); + QTest::qWaitForWindowShown(viewer); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(viewer)); + + // Browser.qml successfully loaded + QDeclarativeItem* browserItem = qobject_cast<QDeclarativeItem*>(viewer->view()->rootObject()); + QVERIFY(viewer->view()); + QVERIFY(viewer->menuBar()); + QVERIFY(browserItem); + + // load something + viewer->open(SRCDIR "/data/orientation.qml"); + QVERIFY(viewer->view()); + QVERIFY(viewer->menuBar()); + QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(viewer->view()->rootObject()); + QVERIFY(rootItem); + QVERIFY(browserItem != rootItem); + + // go back to Browser.qml + viewer->openFile(); + browserItem = qobject_cast<QDeclarativeItem*>(viewer->view()->rootObject()); + QVERIFY(viewer->view()); + QVERIFY(viewer->menuBar()); + QVERIFY(browserItem); +} + +void tst_QDeclarativeViewer::resizing() +{ + QDeclarativeViewer *viewer = new QDeclarativeViewer(); + QVERIFY(viewer); + viewer->open(SRCDIR "/data/orientation.qml"); + QVERIFY(viewer->view()); + QVERIFY(viewer->menuBar()); + QDeclarativeItem* rootItem = qobject_cast<QDeclarativeItem*>(viewer->view()->rootObject()); + QVERIFY(rootItem); + viewer->show(); + + QApplication::setActiveWindow(viewer); + QTest::qWaitForWindowShown(viewer); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(viewer)); + + // initial size + QCOMPARE(rootItem->width(), 200.0); + QCOMPARE(rootItem->height(), 300.0); + QCOMPARE(viewer->view()->size(), QSize(200, 300)); + QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(200, 300)); + QCOMPARE(viewer->size(), QSize(200, 300+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), viewer->sizeHint()); + + viewer->setSizeToView(false); + + // size view to root object + rootItem->setWidth(100); + rootItem->setHeight(200); + qApp->processEvents(); + + QCOMPARE(rootItem->width(), 100.0); + QCOMPARE(rootItem->height(), 200.0); + QCOMPARE(viewer->view()->size(), QSize(100, 200)); + QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(100, 200)); + QCOMPARE(viewer->size(), QSize(100, 200+viewer->menuBar()->height())); + QCOMPARE(viewer->size(), viewer->sizeHint()); + + // do not size root object to view + viewer->resize(QSize(150,250)); + QCOMPARE(rootItem->width(), 100.0); + QCOMPARE(rootItem->height(), 200.0); + + viewer->setSizeToView(true); + + // size root object to view + viewer->resize(QSize(250,350)); + qApp->processEvents(); + + QTRY_COMPARE(rootItem->width(), 250.0); + QTRY_COMPARE(rootItem->height(), 350.0-viewer->menuBar()->height()); + QCOMPARE(viewer->view()->size(), QSize(250, 350-viewer->menuBar()->height())); + QCOMPARE(viewer->view()->initialSize(), QSize(200, 300)); + QCOMPARE(viewer->view()->sceneRect().size(), QSizeF(250, 350-viewer->menuBar()->height())); + QCOMPARE(viewer->size(), QSize(250, 350)); + QCOMPARE(viewer->size(), viewer->sizeHint()); + + // do not size view to root object + rootItem->setWidth(100); + rootItem->setHeight(200); + QTRY_COMPARE(viewer->size(), QSize(250, 350)); +} + +void tst_QDeclarativeViewer::paths() +{ + QDeclarativeViewer *viewer = new QDeclarativeViewer(); + QVERIFY(viewer); + + viewer->addLibraryPath("miscImportPath"); + viewer->view()->engine()->importPathList().contains("miscImportPath"); + + viewer->addPluginPath("miscPluginPath"); + viewer->view()->engine()->pluginPathList().contains("miscPluginPath"); +} + +void tst_QDeclarativeViewer::slowMode() +{ + QDeclarativeViewer *viewer = new QDeclarativeViewer(); + QVERIFY(viewer); + + viewer->setSlowMode(true); + viewer->setSlowMode(false); +} + QTEST_MAIN(tst_QDeclarativeViewer) #include "tst_qdeclarativeviewer.moc" |