diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-03-19 12:29:32 +0100 |
---|---|---|
committer | Kent Hansen <kent.hansen@nokia.com> | 2012-03-19 12:37:03 +0100 |
commit | 4821058f10118be55a541ad39e25ec9165cca3b3 (patch) | |
tree | 167973e3c68fc442b0e37d6f628f3fdbe759f15a /tests/auto/quick | |
parent | 83f11e33745180e9370d484cbcedd0bac020c9dd (diff) | |
parent | 26d5f2e833f0e3686aaa27e695bbfab5fbd808ad (diff) |
Merge master into api_changes
Conflicts:
src/qml/debugger/qqmlenginedebugservice.cpp
src/qml/qml/v8/qv8qobjectwrapper.cpp
src/quick/util/qquickimageprovider.cpp
tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
Change-Id: Ie78ba2fabd32f4812bcae9dbdd66ed289dc11dcb
Diffstat (limited to 'tests/auto/quick')
29 files changed, 1436 insertions, 144 deletions
diff --git a/tests/auto/quick/examples/tst_examples.cpp b/tests/auto/quick/examples/tst_examples.cpp index c29da570c3..9a2a800cfd 100644 --- a/tests/auto/quick/examples/tst_examples.cpp +++ b/tests/auto/quick/examples/tst_examples.cpp @@ -62,6 +62,7 @@ class tst_examples : public QObject Q_OBJECT public: tst_examples(); + ~tst_examples(); private slots: void init(); @@ -81,9 +82,11 @@ private: QStringList findQmlFiles(const QDir &); QQmlEngine engine; + + QQuickCanvas *canvas; }; -tst_examples::tst_examples() +tst_examples::tst_examples() : canvas(0) { // Add files to exclude here excludedFiles << "doc/src/snippets/qml/listmodel.qml"; //Just a ListModel, no root QQuickItem @@ -110,6 +113,15 @@ tst_examples::tst_examples() excludedDirs << "demos/flickr"; excludedDirs << "demos/photoviewer"; #endif + + // QTBUG-24034 - don't run customparticle examples + excludedDirs << "demos/flickr"; + excludedDirs << "examples/particles/customparticle"; +} + +tst_examples::~tst_examples() +{ + delete canvas; } void tst_examples::init() @@ -252,13 +264,16 @@ void tst_examples::sgexamples() component.completeCreate(); QVERIFY(root); - QQuickCanvas canvas; - root->setParentItem(canvas.rootItem()); + if (!canvas) { + canvas = new QQuickCanvas(); + canvas->resize(240, 320); + canvas->show(); + QTest::qWaitForWindowShown(canvas); + } + root->setParentItem(canvas->rootItem()); component.completeCreate(); - canvas.show(); - - QTest::qWaitForWindowShown(&canvas); + qApp->processEvents(); } void tst_examples::sgsnippets_data() @@ -293,13 +308,16 @@ void tst_examples::sgsnippets() component.completeCreate(); QVERIFY(root); - QQuickCanvas canvas; - root->setParentItem(canvas.rootItem()); + if (!canvas) { + canvas = new QQuickCanvas(); + canvas->resize(240, 320); + canvas->show(); + QTest::qWaitForWindowShown(canvas); + } + root->setParentItem(canvas->rootItem()); component.completeCreate(); - canvas.show(); - - QTest::qWaitForWindowShown(&canvas); + qApp->processEvents(); } QTEST_MAIN(tst_examples) diff --git a/tests/auto/quick/qquickanimationcontroller/data/tst_coloranimation.qml b/tests/auto/quick/qquickanimationcontroller/data/tst_coloranimation.qml new file mode 100755 index 0000000000..92e27b9945 --- /dev/null +++ b/tests/auto/quick/qquickanimationcontroller/data/tst_coloranimation.qml @@ -0,0 +1,38 @@ +import QtQuick 2.0 +import QtTest 1.0 + +Rectangle { + id:container + width:50 + height:50 + + Rectangle {id:rect; x:0; y:0; color:"red"; width:10; height:10} + AnimationController { + id:colorAnimationcontroller + progress:1 + animation: ColorAnimation {id:anim; target: rect; property:"color"; to:"#FFFFFF"; from:"#000000"; duration: 1000} + } + + TestCase { + name:"AnimationController" + when:windowShown + function test_colorAnimation() { + colorAnimationcontroller.progress = 0; + compare(rect.color.toString(), "#000000"); + colorAnimationcontroller.progress = 0.5; + compare(rect.color.toString(), "#7f7f7f"); + + // <=0 -> 0 + colorAnimationcontroller.progress = -1; + compare(rect.color, "#000000"); + + //>=1 -> 1 + colorAnimationcontroller.progress = 1.1; + compare(rect.color.toString(), "#ffffff"); + + //make sure the progress can be set backward + colorAnimationcontroller.progress = 0.5; + compare(rect.color, "#7f7f7f"); + } + } +}
\ No newline at end of file diff --git a/tests/auto/quick/qquickanimationcontroller/data/tst_parallelanimation.qml b/tests/auto/quick/qquickanimationcontroller/data/tst_parallelanimation.qml new file mode 100644 index 0000000000..1a17a1a908 --- /dev/null +++ b/tests/auto/quick/qquickanimationcontroller/data/tst_parallelanimation.qml @@ -0,0 +1,63 @@ +import QtQuick 2.0 +import QtTest 1.0 + +Rectangle { + id:container + width:100 + height:100 + + Rectangle {id:rect; x:0; y:0; color:"red"; width:10; height:10} + AnimationController { + id:controller + progress:0 + animation: ParallelAnimation { + id:anim + NumberAnimation { target: rect; property: "x"; from:0; to: 50; duration: 1000 } + NumberAnimation { target: rect; property: "y"; from:0; to: 100; duration: 1000 } + NumberAnimation { target: rect; property: "height"; from:10; to: 50; duration: 1000 } + NumberAnimation { target: rect; property: "width"; from:10; to: 50; duration: 1000 } + ColorAnimation {target:rect; property:"color"; from:"red"; to:"blue"; duration:1000 } + } + } + + TestCase { + name:"AnimationController" + when:windowShown + function test_parallelAnimation_data() { + //FIXME:the commented lines fail on MAC OS X + return [ + {tag:"0.1",progress:0.1, x:5, y:10, color:"#e50019", width:14, height:14}, + //{tag:"0.2",progress:0.2, x:10, y:20, color:"#cb0033", width:18, height:18}, + {tag:"0.30000000000000004",progress:0.30000000000000004, x:15, y:30, color:"#b2004c", width:22, height:22}, + //{tag:"0.4",progress:0.4, x:20, y:40, color:"#980066", width:26, height:26}, + {tag:"0.5",progress:0.5, x:25, y:50, color:"#7f007f", width:30, height:30}, + {tag:"0.6",progress:0.59999999, x:29.95, y:59.9, color:"#660098", width:33.96, height:33.96}, + {tag:"0.7",progress:0.69999999, x:34.949999999999996, y:69.89999999999999, color:"#4c00b2", width:37.96, height:37.96}, + {tag:"0.7999999999999999",progress:0.7999999999999999, x:39.95, y:79.9, color:"#3300cb", width:41.96, height:41.96}, + {tag:"0.8999999999999999",progress:0.8999999999999999, x:44.95, y:89.9, color:"#1900e5", width:45.96, height:45.96}, + {tag:"0.9999999999999999",progress:0.9999999999999999, x:49.95, y:99.9, color:"#0000fe", width:49.96, height:49.96}, + {tag:"1",progress:1, x:50, y:100, color:"#0000ff", width:50, height:50}, + {tag:"0.9",progress:0.9, x:45, y:90, color:"#1900e5", width:46, height:46}, + //{tag:"0.8",progress:0.8, x:40, y:80, color:"#3200cc", width:42, height:42}, + {tag:"0.7000000000000001",progress:0.7000000000000001, x:35, y:70, color:"#4c00b2", width:38, height:38}, + //{tag:"0.6000000000000001",progress:0.6000000000000001, x:30, y:60, color:"#660098", width:34, height:34}, + {tag:"0.5000000000000001",progress:0.5000000000000001, x:25, y:50, color:"#7f007f", width:30, height:30}, + //{tag:"0.40000000000000013",progress:0.40000000000000013, x:20, y:40, color:"#980066", width:26, height:26}, + {tag:"0.30000000000000016",progress:0.30000000000000016, x:15, y:30, color:"#b2004c", width:22, height:22}, + //{tag:"0.20000000000000015",progress:0.19999999999999999, x:10, y:20, color:"#cb0033", width:18, height:18}, + {tag:"0.10000000000000014",progress:0.10000000000000014, x:5, y:10, color:"#e50019", width:14, height:14}, + {tag:"1.3877787807814457e-16",progress:1.3877787807814457e-16, x:0, y:0, color:"#ff0000", width:10, height:10}, + {tag:"0",progress:0, x:0, y:0, color:"#ff0000", width:10, height:10}, + {tag:"0.1",progress:0.1, x:5, y:10, color:"#e50019", width:14, height:14} + ]; + } + function test_parallelAnimation(row) { + controller.progress = row.progress; + compare(rect.x, row.x); + compare(rect.y, row.y); + compare(rect.width, row.width); + compare(rect.height, row.height); + compare(rect.color.toString(), row.color); + } + } +} diff --git a/tests/auto/quick/qquickanimationcontroller/data/tst_sequentialanimation.qml b/tests/auto/quick/qquickanimationcontroller/data/tst_sequentialanimation.qml new file mode 100644 index 0000000000..59671f5145 --- /dev/null +++ b/tests/auto/quick/qquickanimationcontroller/data/tst_sequentialanimation.qml @@ -0,0 +1,65 @@ +import QtQuick 2.0 +import QtTest 1.0 + +Rectangle { + id:container + width:100 + height:100 + + Rectangle {id:rect; x:0; y:0; color:"red"; width:10; height:10} + AnimationController { + id:controller + progress:0 + animation: SequentialAnimation { + id:anim + NumberAnimation { target: rect; property: "x"; from:0; to: 50; duration: 1000 } + NumberAnimation { target: rect; property: "y"; from:0; to: 100; duration: 1000 } + NumberAnimation { target: rect; property: "height"; from:10; to: 50; duration: 1000 } + NumberAnimation { target: rect; property: "width"; from:10; to: 50; duration: 1000 } + ColorAnimation {target:rect; property:"color"; from:"red"; to:"blue"; duration:1000 } + } + } + + + TestCase { + name:"AnimationController" + when:windowShown + function test_sequentialAnimation_data() { + return [ + {tag:"0.1",progress:0.1, x:25, y:0, color:"#ff0000", width:10, height:10}, + {tag:"0.2",progress:0.2, x:50, y:0, color:"#ff0000", width:10, height:10}, + {tag:"0.30000000000000004",progress:0.30000000000000004, x:50, y:50, color:"#ff0000", width:10, height:10}, + {tag:"0.4",progress:0.4, x:50, y:100, color:"#ff0000", width:10, height:10}, + {tag:"0.5",progress:0.5, x:50, y:100, color:"#ff0000", width:10, height:30}, + {tag:"0.6",progress:0.5999999999999, x:50, y:100, color:"#ff0000", width:10, height:49.96}, + {tag:"0.7",progress:0.6999999999999, x:50, y:100, color:"#ff0000", width:29.96, height:50}, + {tag:"0.7999999999999999",progress:0.7999999999999999, x:50, y:100, color:"#ff0000", width:49.96, height:50}, + {tag:"0.8999999999999999",progress:0.8999999999999999, x:50, y:100, color:"#7f007f", width:50, height:50}, + {tag:"0.9999999999999999",progress:0.9999999999999999, x:50, y:100, color:"#0000fe", width:50, height:50}, + {tag:"1",progress:1, x:50, y:100, color:"#0000ff", width:50, height:50}, + {tag:"0.9",progress:0.9, x:50, y:100, color:"#7f007f", width:50, height:50}, + {tag:"0.8",progress:0.8, x:50, y:100, color:"#ff0000", width:50, height:50}, + {tag:"0.7000000000000001",progress:0.7000000000000001, x:50, y:100, color:"#ff0000", width:30, height:50}, + {tag:"0.6000000000000001",progress:0.6000000000000001, x:50, y:100, color:"#ff0000", width:10, height:50}, + {tag:"0.5000000000000001",progress:0.5000000000000001, x:50, y:100, color:"#ff0000", width:10, height:30}, + {tag:"0.40000000000000013",progress:0.40000000000000013, x:50, y:100, color:"#ff0000", width:10, height:10}, + {tag:"0.30000000000000016",progress:0.30000000000000016, x:50, y:50, color:"#ff0000", width:10, height:10}, + {tag:"0.20000000000000015",progress:0.20000000000000015, x:50, y:0, color:"#ff0000", width:10, height:10}, + {tag:"0.10000000000000014",progress:0.10000000000000014, x:25, y:0, color:"#ff0000", width:10, height:10}, + {tag:"1.3877787807814457e-16",progress:1.3877787807814457e-16, x:0, y:0, color:"#ff0000", width:10, height:10}, + {tag:"0",progress:0, x:0, y:0, color:"#ff0000", width:10, height:10}, + {tag:"0.1",progress:0.1, x:25, y:0, color:"#ff0000", width:10, height:10}, + {tag:"0.2",progress:0.2, x:50, y:0, color:"#ff0000", width:10, height:10} + + ]; + } + function test_sequentialAnimation(row) { + controller.progress = row.progress; + compare(rect.x, row.x); + compare(rect.y, row.y); + compare(rect.width, row.width); + compare(rect.height, row.height); + compare(rect.color.toString(), row.color); + } + } +} diff --git a/tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp b/tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp index 3a27d179c5..7250504e73 100644 --- a/tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp +++ b/tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp @@ -698,7 +698,7 @@ void tst_qquickcanvas::headless() canvas->show(); QTest::qWaitForWindowShown(canvas); - QCOMPARE(initialized.size(), 1); + QTRY_COMPARE(initialized.size(), 1); QVERIFY(canvas->openglContext() != 0); // Verify that the visual output is the same diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index a2ecadf33a..4b157a434b 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -585,7 +585,7 @@ void tst_qquickflickable::flickVelocity() QQuickFlickablePrivate *fp = QQuickFlickablePrivate::get(flickable); bool boosted = false; for (int i = 0; i < 6; ++i) { - flick(canvas, QPoint(20,390), QPoint(20, 50), 200); + flick(canvas, QPoint(20,390), QPoint(20, 50), 100); boosted |= fp->flickBoost > 1.0; } QVERIFY(boosted); diff --git a/tests/auto/quick/qquickfontloader/qquickfontloader.pro b/tests/auto/quick/qquickfontloader/qquickfontloader.pro index 2eeb286e61..3e52b6fe7b 100644 --- a/tests/auto/quick/qquickfontloader/qquickfontloader.pro +++ b/tests/auto/quick/qquickfontloader/qquickfontloader.pro @@ -13,3 +13,5 @@ TESTDATA = data/* CONFIG += parallel_test QT += core-private gui-private qml-private quick-private network testlib + +win32:CONFIG += insignificant_test # QTBUG-24782 diff --git a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp index d8f368cf3e..f99c26803d 100644 --- a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp +++ b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp @@ -116,7 +116,7 @@ void tst_qquickfontloader::namedFont() void tst_qquickfontloader::localFont() { - QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"" + testFile("tarzeau_ocr_a.ttf") + "\" }"; + QString componentStr = "import QtQuick 2.0\nFontLoader { source: \"" + testFileUrl("tarzeau_ocr_a.ttf").toString() + "\" }"; QQmlComponent component(&engine); component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QQuickFontLoader *fontObject = qobject_cast<QQuickFontLoader*>(component.create()); diff --git a/tests/auto/quick/qquickgridview/data/headerfooter.qml b/tests/auto/quick/qquickgridview/data/headerfooter.qml new file mode 100644 index 0000000000..322cfed388 --- /dev/null +++ b/tests/auto/quick/qquickgridview/data/headerfooter.qml @@ -0,0 +1,31 @@ +import QtQuick 2.0 + +GridView { + id: view + property bool horizontal: false + property bool rtl: false + width: 240 + height: 320 + + model: testModel + + flow: horizontal ? GridView.TopToBottom : GridView.LeftToRight + header: Rectangle { + objectName: "header" + width: horizontal ? 20 : view.width + height: horizontal ? view.height : 20 + color: "red" + } + footer: Rectangle { + objectName: "footer" + width: horizontal ? 30 : view.width + height: horizontal ? view.height : 30 + color: "blue" + } + + cellWidth: 80; + cellHeight: 80; + + delegate: Text { width: 80; height: 80; text: index + "(" + x + ")" } + layoutDirection: rtl ? Qt.RightToLeft : Qt.LeftToRight +} diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index 7d004915a6..88ed94d8bc 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -64,6 +64,8 @@ Q_DECLARE_METATYPE(QQuickGridView::Flow) using namespace QQuickViewTestUtil; using namespace QQuickVisualTestUtil; +#define SHARE_VIEWS + class tst_QQuickGridView : public QQmlDataTest { Q_OBJECT @@ -71,6 +73,7 @@ public: tst_QQuickGridView(); private slots: + void init(); void items(); void changed(); void inserted(); @@ -110,6 +113,7 @@ private slots: void footer_data(); void header(); void header_data(); + void headerFooter(); void resizeViewAndRepaint(); void changeColumnCount(); void indexAt_itemAt_data(); @@ -149,10 +153,53 @@ private: void matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes); void matchItemsAndIndexes(const QVariantMap &items, const QaimModel &model, const QList<int> &expectedIndexes); void matchItemLists(const QVariantList &itemLists, const QList<QQuickItem *> &expectedItems); + +#ifdef SHARE_VIEWS + QQuickView *getView() { + if (m_view) { + if (QString(QTest::currentTestFunction()) != testForView) { + delete m_view; + m_view = 0; + } else { + m_view->setSource(QUrl()); + return m_view; + } + } + + testForView = QTest::currentTestFunction(); + m_view = createView(); + return m_view; + } + void releaseView(QQuickView *view) { + Q_ASSERT(view == m_view); + m_view->setSource(QUrl()); + } +#else + QQuickView *getView() { + return createView(); + } + void releaseView(QQuickView *view) { + delete view; + } +#endif + + QQuickView *m_view; + QString testForView; }; -tst_QQuickGridView::tst_QQuickGridView() +tst_QQuickGridView::tst_QQuickGridView() : m_view(0) +{ +} + +void tst_QQuickGridView::init() { +#ifdef SHARE_VIEWS + if (m_view && QString(QTest::currentTestFunction()) != testForView) { + testForView = QString(); + delete m_view; + m_view = 0; + } +#endif } void tst_QQuickGridView::items() @@ -334,7 +381,7 @@ void tst_QQuickGridView::inserted_more() for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("testRightToLeft", QVariant(false)); @@ -393,7 +440,7 @@ void tst_QQuickGridView::inserted_more() QCOMPARE(number->text(), model.number(i)); } - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::inserted_more_data() @@ -502,7 +549,7 @@ void tst_QQuickGridView::insertBeforeVisible() QFETCH(int, cacheBuffer); QQuickText *name; - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QaimModel model; for (int i = 0; i < 30; i++) @@ -560,7 +607,7 @@ void tst_QQuickGridView::insertBeforeVisible() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::insertBeforeVisible_data() @@ -741,7 +788,7 @@ void tst_QQuickGridView::removed_more() QQuickText *name; QQuickText *number; - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QaimModel model; for (int i = 0; i < 30; i++) @@ -798,7 +845,7 @@ void tst_QQuickGridView::removed_more() QTRY_COMPARE(number->text(), model.number(i)); } - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::removed_more_data() @@ -934,7 +981,7 @@ void tst_QQuickGridView::addOrRemoveBeforeVisible() QFETCH(bool, doAdd); QFETCH(qreal, newTopContentY); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); canvas->show(); QaimModel model; @@ -1000,7 +1047,7 @@ void tst_QQuickGridView::addOrRemoveBeforeVisible() QTRY_VERIFY(item->y() == (i/3)*60 + newTopContentY); } - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::addOrRemoveBeforeVisible_data() @@ -1061,7 +1108,7 @@ void tst_QQuickGridView::moved() QQuickText *name; QQuickText *number; - QScopedPointer<QQuickView> canvas(createView()); + QQuickView *canvas = getView(); QaimModel model; for (int i = 0; i < 30; i++) @@ -1116,6 +1163,8 @@ void tst_QQuickGridView::moved() if (item == currentItem) QTRY_COMPARE(gridview->currentIndex(), i); } + + releaseView(canvas); } void tst_QQuickGridView::moved_data() @@ -1279,7 +1328,7 @@ void tst_QQuickGridView::multipleChanges() QFETCH(int, newCount); QFETCH(int, newCurrentIndex); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QaimModel model; for (int i = 0; i < startCount; i++) @@ -1347,7 +1396,7 @@ void tst_QQuickGridView::multipleChanges() QTRY_COMPARE(number->text(), model.number(i)); } - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::multipleChanges_data() @@ -2778,7 +2827,7 @@ void tst_QQuickGridView::footer() QFETCH(QPointF, firstDelegatePos); QFETCH(QPointF, resizeContentPos); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); canvas->show(); QaimModel model; @@ -2876,7 +2925,7 @@ void tst_QQuickGridView::footer() footer->setWidth(40); QTRY_COMPARE(QPointF(gridview->contentX(), gridview->contentY()), resizeContentPos); - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::footer_data() @@ -2948,7 +2997,7 @@ void tst_QQuickGridView::header() for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); canvas->rootContext()->setContextProperty("testModel", &model); canvas->rootContext()->setContextProperty("initialViewWidth", 240); canvas->rootContext()->setContextProperty("initialViewHeight", 320); @@ -3016,12 +3065,12 @@ void tst_QQuickGridView::header() header->setWidth(40); QTRY_COMPARE(QPointF(gridview->contentX(), gridview->contentY()), resizeContentPos); - delete canvas; + releaseView(canvas); // QTBUG-21207 header should become visible if view resizes from initial empty size - canvas = createView(); + canvas = getView(); canvas->rootContext()->setContextProperty("testModel", &model); canvas->rootContext()->setContextProperty("initialViewWidth", 240); canvas->rootContext()->setContextProperty("initialViewHeight", 320); @@ -3040,7 +3089,7 @@ void tst_QQuickGridView::header() QTRY_COMPARE(gridview->headerItem()->pos(), initialHeaderPos); QCOMPARE(QPointF(gridview->contentX(), gridview->contentY()), initialContentPos); - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::header_data() @@ -3096,6 +3145,151 @@ void tst_QQuickGridView::header_data() << QPointF(-(240 - 40), 0); } +class GVAccessor : public QQuickGridView +{ +public: + qreal minY() const { return minYExtent(); } + qreal maxY() const { return maxYExtent(); } + qreal minX() const { return minXExtent(); } + qreal maxX() const { return maxXExtent(); } +}; + +void tst_QQuickGridView::headerFooter() +{ + { + // Vertical + QQuickView *canvas = createView(); + + QmlListModel model; + QQmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(testFileUrl("headerfooter.qml")); + qApp->processEvents(); + + QQuickGridView *gridview = qobject_cast<QQuickGridView*>(canvas->rootObject()); + QTRY_VERIFY(gridview != 0); + + QQuickItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); + + QQuickItem *header = findItem<QQuickItem>(contentItem, "header"); + QVERIFY(header); + QCOMPARE(header->y(), -header->height()); + + QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer"); + QVERIFY(footer); + QCOMPARE(footer->y(), 0.); + + QCOMPARE(static_cast<GVAccessor*>(gridview)->minY(), header->height()); + QCOMPARE(static_cast<GVAccessor*>(gridview)->maxY(), header->height()); + + delete canvas; + } + { + // Horizontal + QQuickView *canvas = createView(); + + QmlListModel model; + QQmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(testFileUrl("headerfooter.qml")); + canvas->rootObject()->setProperty("horizontal", true); + qApp->processEvents(); + + QQuickGridView *gridview = qobject_cast<QQuickGridView*>(canvas->rootObject()); + QTRY_VERIFY(gridview != 0); + + QQuickItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); + + QQuickItem *header = findItem<QQuickItem>(contentItem, "header"); + QVERIFY(header); + QCOMPARE(header->x(), -header->width()); + + QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer"); + QVERIFY(footer); + QCOMPARE(footer->x(), 0.); + + QCOMPARE(static_cast<GVAccessor*>(gridview)->minX(), header->width()); + QCOMPARE(static_cast<GVAccessor*>(gridview)->maxX(), header->width()); + + delete canvas; + } + { + // Horizontal RTL + QQuickView *canvas = createView(); + + QmlListModel model; + QQmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(testFileUrl("headerfooter.qml")); + canvas->rootObject()->setProperty("horizontal", true); + canvas->rootObject()->setProperty("rtl", true); + qApp->processEvents(); + + QQuickGridView *gridview = qobject_cast<QQuickGridView*>(canvas->rootObject()); + QTRY_VERIFY(gridview != 0); + + QQuickItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); + + QQuickItem *header = findItem<QQuickItem>(contentItem, "header"); + QVERIFY(header); + QCOMPARE(header->x(), 0.); + + QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer"); + QVERIFY(footer); + QCOMPARE(footer->x(), -footer->width()); + + QCOMPARE(static_cast<GVAccessor*>(gridview)->minX(), 240. - header->width()); + QCOMPARE(static_cast<GVAccessor*>(gridview)->maxX(), 240. - header->width()); + + delete canvas; + } + { + // Reset model + QQuickView *canvas = createView(); + + QaimModel model; + for (int i = 0; i < 6; i++) + model.addItem("Item" + QString::number(i), ""); + QQmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(testFileUrl("headerfooter.qml")); + qApp->processEvents(); + + QQuickGridView *gridview = qobject_cast<QQuickGridView*>(canvas->rootObject()); + QTRY_VERIFY(gridview != 0); + + QQuickItem *contentItem = gridview->contentItem(); + QTRY_VERIFY(contentItem != 0); + + QQuickItem *header = findItem<QQuickItem>(contentItem, "header"); + QVERIFY(header); + QCOMPARE(header->y(), -header->height()); + + QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer"); + QVERIFY(footer); + QCOMPARE(footer->y(), 80.*2); + + model.reset(); + + header = findItem<QQuickItem>(contentItem, "header"); + QVERIFY(header); + QCOMPARE(header->y(), -header->height()); + + footer = findItem<QQuickItem>(contentItem, "footer"); + QVERIFY(footer); + QCOMPARE(footer->y(), 80.*2); + + delete canvas; + } +} + void tst_QQuickGridView::resizeViewAndRepaint() { QQuickView *canvas = createView(); @@ -3244,7 +3438,7 @@ void tst_QQuickGridView::indexAt_itemAt() QFETCH(qreal, y); QFETCH(int, index); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QaimModel model; model.addItem("Fred", "12345"); @@ -3279,7 +3473,7 @@ void tst_QQuickGridView::indexAt_itemAt() QCOMPARE(gridview->indexAt(x, y), index); QVERIFY(gridview->itemAt(x, y) == item); - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::onAdd() @@ -3290,7 +3484,7 @@ void tst_QQuickGridView::onAdd() const int delegateWidth = 50; const int delegateHeight = 100; QaimModel model; - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); canvas->setGeometry(0,0,5 * delegateWidth, 5 * delegateHeight); // just ensure all items fit // these initial items should not trigger GridView.onAdd @@ -3321,7 +3515,7 @@ void tst_QQuickGridView::onAdd() for (int i=0; i<items.count(); i++) QCOMPARE(result[i].toString(), items[i].first); - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::onAdd_data() @@ -3354,7 +3548,7 @@ void tst_QQuickGridView::onRemove() for (int i=0; i<initialItemCount; i++) model.addItem(QString("value %1").arg(i), "dummy value"); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("delegateWidth", delegateWidth); @@ -3366,7 +3560,7 @@ void tst_QQuickGridView::onRemove() QTRY_COMPARE(model.count(), qobject_cast<QQuickGridView*>(canvas->rootObject())->count()); QCOMPARE(object->property("removedDelegateCount"), QVariant(removeCount)); - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::onRemove_data() @@ -3602,7 +3796,7 @@ void tst_QQuickGridView::snapToRow() QFETCH(qreal, endExtent); QFETCH(qreal, startExtent); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); canvas->setSource(testFileUrl("snapToRow.qml")); canvas->show(); @@ -3653,7 +3847,7 @@ void tst_QQuickGridView::snapToRow() else QCOMPARE(gridview->contentX(), startExtent); - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::snapOneRow_data() @@ -3697,7 +3891,7 @@ void tst_QQuickGridView::snapOneRow() QFETCH(qreal, endExtent); QFETCH(qreal, startExtent); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); canvas->setSource(testFileUrl("snapOneRow.qml")); canvas->show(); @@ -3765,7 +3959,7 @@ void tst_QQuickGridView::snapOneRow() QCOMPARE(currentIndexSpy.count(), 6); } - delete canvas; + releaseView(canvas); } @@ -3846,7 +4040,7 @@ void tst_QQuickGridView::populateTransitions() model.addItem("item" + QString::number(i), ""); } - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); canvas->rootContext()->setContextProperty("testModel", &model); canvas->rootContext()->setContextProperty("usePopulateTransition", usePopulateTransition); canvas->rootContext()->setContextProperty("dynamicallyPopulate", dynamicallyPopulate); @@ -3944,7 +4138,7 @@ void tst_QQuickGridView::populateTransitions() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::populateTransitions_data() @@ -3984,7 +4178,7 @@ void tst_QQuickGridView::addTransitions() QaimModel model_targetItems_transitionFrom; QaimModel model_displacedItems_transitionVia; - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("model_targetItems_transitionFrom", &model_targetItems_transitionFrom); @@ -4080,7 +4274,7 @@ void tst_QQuickGridView::addTransitions() QCOMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::addTransitions_data() @@ -4189,7 +4383,7 @@ void tst_QQuickGridView::moveTransitions() QaimModel model_targetItems_transitionVia; QaimModel model_displacedItems_transitionVia; - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("model_targetItems_transitionVia", &model_targetItems_transitionVia); @@ -4277,7 +4471,7 @@ void tst_QQuickGridView::moveTransitions() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::moveTransitions_data() @@ -4395,7 +4589,7 @@ void tst_QQuickGridView::removeTransitions() QaimModel model_targetItems_transitionTo; QaimModel model_displacedItems_transitionVia; - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("model_targetItems_transitionTo", &model_targetItems_transitionTo); @@ -4492,7 +4686,7 @@ void tst_QQuickGridView::removeTransitions() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::removeTransitions_data() @@ -4599,7 +4793,7 @@ void tst_QQuickGridView::displacedTransitions() QPointF moveDisplaced_transitionVia(50, -100); QPointF removeDisplaced_transitionVia(150, 100); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("model_displaced_transitionVia", &model_displaced_transitionVia); @@ -4709,7 +4903,7 @@ void tst_QQuickGridView::displacedTransitions() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::displacedTransitions_data() @@ -4822,7 +5016,7 @@ void tst_QQuickGridView::multipleTransitions() for (int i = 0; i < initialCount; i++) model.addItem("Original item" + QString::number(i), ""); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("addTargets_transitionFrom", addTargets_transitionFrom); @@ -4924,7 +5118,7 @@ void tst_QQuickGridView::multipleTransitions() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); } void tst_QQuickGridView::multipleTransitions_data() @@ -5138,7 +5332,7 @@ void tst_QQuickGridView::asynchronous() QQmlIncubationController controller; canvas->engine()->setIncubationController(&controller); - canvas->setSource(testFile("asyncloader.qml")); + canvas->setSource(testFileUrl("asyncloader.qml")); QQuickItem *rootObject = qobject_cast<QQuickItem*>(canvas->rootObject()); QVERIFY(rootObject); diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp index eda56fa789..be815d8973 100644 --- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp @@ -369,11 +369,11 @@ void tst_qquickimage::svg() QQuickImage *obj = qobject_cast<QQuickImage*>(component.create()); QVERIFY(obj != 0); QCOMPARE(obj->width(), 300.0); - QCOMPARE(obj->height(), 300.0); + QCOMPARE(obj->height(), 273.0); obj->setSourceSize(QSize(200,200)); QCOMPARE(obj->width(), 200.0); - QCOMPARE(obj->height(), 200.0); + QCOMPARE(obj->height(), 182.0); delete obj; } diff --git a/tests/auto/quick/qquickitem/data/multipleFocusClears.qml b/tests/auto/quick/qquickitem/data/multipleFocusClears.qml new file mode 100644 index 0000000000..f68a8901ab --- /dev/null +++ b/tests/auto/quick/qquickitem/data/multipleFocusClears.qml @@ -0,0 +1,18 @@ +import QtQuick 2.0 + +Rectangle { + width: 200 + height: 200 + + FocusScope { + id: focusScope + anchors.fill: parent + + TextInput { + anchors.centerIn: parent + text: "Some text" + onActiveFocusChanged: if (!activeFocus) focusScope.focus = false + Component.onCompleted: forceActiveFocus() + } + } +} diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp index 7a589a48cd..9fdfa78559 100644 --- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp @@ -138,6 +138,7 @@ private slots: void scopedFocus(); void addedToCanvas(); void changeParent(); + void multipleFocusClears(); void constructor(); void setParentItem(); @@ -675,6 +676,16 @@ void tst_qquickitem::changeParent() } +void tst_qquickitem::multipleFocusClears() +{ + //Multiple clears of focus inside a focus scope shouldn't crash. QTBUG-24714 + QQuickView *view = new QQuickView; + view->setSource(testFileUrl("multipleFocusClears.qml")); + view->show(); + ensureFocus(view); + QTRY_VERIFY(QGuiApplication::focusWindow() == view); +} + void tst_qquickitem::constructor() { QQuickItem *root = new QQuickItem; diff --git a/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro b/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro index 9ffdbe7454..20fddb9410 100644 --- a/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro +++ b/tests/auto/quick/qquickitemlayer/qquickitemlayer.pro @@ -27,10 +27,4 @@ OTHER_FILES += \ data/ItemEffect.qml \ data/RectangleEffect.qml - - - - - - - +win32:CONFIG += insignificant_test # QTBUG-24787 diff --git a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp index 44d0d6d09c..4847dd3d1c 100644 --- a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp +++ b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp @@ -53,10 +53,10 @@ class tst_QQuickItemLayer: public QQmlDataTest public: tst_QQuickItemLayer(); - QImage runTest(const QString &url) + QImage runTest(const QString &fileName) { QQuickView view; - view.setSource(QUrl(url)); + view.setSource(testFileUrl(fileName)); view.show(); QTest::qWaitForWindowShown(&view); @@ -135,7 +135,7 @@ void tst_QQuickItemLayer::layerSmooth() { if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0)) QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly."); - QImage fb = runTest(testFile("Smooth.qml")); + QImage fb = runTest("Smooth.qml"); QCOMPARE(fb.pixel(0, 0), qRgb(0xff, 0, 0)); QCOMPARE(fb.pixel(fb.width() - 1, 0), qRgb(0, 0, 0xff)); @@ -154,7 +154,7 @@ void tst_QQuickItemLayer::layerEnabled() { if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0)) QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly."); - QImage fb = runTest(testFile("Enabled.qml")); + QImage fb = runTest("Enabled.qml"); // Verify the banding QCOMPARE(fb.pixel(0, 0), fb.pixel(0, 1)); // Verify the gradient @@ -170,7 +170,7 @@ void tst_QQuickItemLayer::layerMipmap() { if (m_isMesaSoftwareRasterizer) QSKIP("Mipmapping does not work with the Mesa Software Rasterizer."); - QImage fb = runTest(testFile("Mipmap.qml")); + QImage fb = runTest("Mipmap.qml"); QVERIFY(fb.pixel(0, 0) != 0xff000000); QVERIFY(fb.pixel(0, 0) != 0xffffffff); } @@ -184,7 +184,7 @@ void tst_QQuickItemLayer::layerEffect() { if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0)) QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly."); - QImage fb = runTest(testFile("Effect.qml")); + QImage fb = runTest("Effect.qml"); QCOMPARE(fb.pixel(0, 0), qRgb(0xff, 0, 0)); QCOMPARE(fb.pixel(fb.width() - 1, 0), qRgb(0, 0xff, 0)); } @@ -199,7 +199,7 @@ void tst_QQuickItemLayer::layerSourceRect() if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0)) QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly."); - QImage fb = runTest(testFile("SourceRect.qml")); + QImage fb = runTest("SourceRect.qml"); // Check that the edges are converted to blue QCOMPARE(fb.pixel(0, 0), qRgb(0, 0, 0xff)); @@ -219,7 +219,7 @@ void tst_QQuickItemLayer::layerIsTextureProvider() { if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0)) QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly."); - QImage fb = runTest(testFile("TextureProvider.qml")); + QImage fb = runTest("TextureProvider.qml"); QCOMPARE(fb.pixel(0, 0), qRgb(0xff, 0, 0)); QCOMPARE(fb.pixel(fb.width() - 1, 0), qRgb(0, 0xff, 0)); } @@ -257,7 +257,7 @@ void tst_QQuickItemLayer::layerVisibility() QFETCH(qreal, opacity); QQuickView view; - view.setSource(testFile("Visible.qml")); + view.setSource(testFileUrl("Visible.qml")); QQuickItem *child = view.rootItem()->childItems().at(0); child->setProperty("layerVisible", visible); @@ -303,7 +303,7 @@ void tst_QQuickItemLayer::layerZOrder() QFETCH(bool, effect); QQuickView view; - view.setSource(testFile("ZOrder.qml")); + view.setSource(testFileUrl("ZOrder.qml")); QQuickItem *child = view.rootItem()->childItems().at(0); child->setProperty("layerEffect", effect); @@ -338,7 +338,7 @@ void tst_QQuickItemLayer::changeZOrder() QFETCH(bool, effect); QQuickView view; - view.setSource(testFile("ZOrderChange.qml")); + view.setSource(testFileUrl("ZOrderChange.qml")); QQuickItem *child = view.rootItem()->childItems().at(0); child->setProperty("layerEnabled", layered); @@ -388,20 +388,20 @@ void tst_QQuickItemLayer::changeZOrder() void tst_QQuickItemLayer::toggleLayerAndEffect() { // This test passes if it doesn't crash. - runTest(testFile("ToggleLayerAndEffect.qml")); + runTest("ToggleLayerAndEffect.qml"); } void tst_QQuickItemLayer::disableLayer() { // This test passes if it doesn't crash. - runTest(testFile("DisableLayer.qml")); + runTest("DisableLayer.qml"); } void tst_QQuickItemLayer::changeSamplerName() { if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0)) QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly."); - QImage fb = runTest(testFile("SamplerNameChange.qml")); + QImage fb = runTest("SamplerNameChange.qml"); QCOMPARE(fb.pixel(0, 0), qRgb(0, 0, 0xff)); } @@ -409,7 +409,7 @@ void tst_QQuickItemLayer::itemEffect() { if (m_isMesaSoftwareRasterizer && m_mesaVersion < QT_VERSION_CHECK(7, 11, 0)) QSKIP("Mesa Software Rasterizer below version 7.11 does not render this test correctly."); - QImage fb = runTest(testFile("ItemEffect.qml")); + QImage fb = runTest("ItemEffect.qml"); QCOMPARE(fb.pixel(0, 0), qRgb(0xff, 0, 0)); QCOMPARE(fb.pixel(199, 0), qRgb(0xff, 0, 0)); QCOMPARE(fb.pixel(0, 199), qRgb(0, 0, 0xff)); @@ -418,7 +418,7 @@ void tst_QQuickItemLayer::itemEffect() void tst_QQuickItemLayer::rectangleEffect() { - QImage fb = runTest(testFile("RectangleEffect.qml")); + QImage fb = runTest("RectangleEffect.qml"); QCOMPARE(fb.pixel(0, 0), qRgb(0, 0xff, 0)); QCOMPARE(fb.pixel(199, 0), qRgb(0, 0xff, 0)); QCOMPARE(fb.pixel(0, 199), qRgb(0, 0xff, 0)); diff --git a/tests/auto/quick/qquicklistview/data/headerfooter.qml b/tests/auto/quick/qquicklistview/data/headerfooter.qml index 8e8463d645..4c3eeca328 100644 --- a/tests/auto/quick/qquicklistview/data/headerfooter.qml +++ b/tests/auto/quick/qquicklistview/data/headerfooter.qml @@ -6,6 +6,8 @@ ListView { property bool rtl: false width: 240 height: 320 + + model: testModel orientation: horizontal ? ListView.Horizontal : ListView.Vertical header: Rectangle { diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 1a494183a8..202f5164af 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -63,6 +63,8 @@ Q_DECLARE_METATYPE(QQuickListView::Orientation) using namespace QQuickViewTestUtil; using namespace QQuickVisualTestUtil; +#define SHARE_VIEWS + class tst_QQuickListView : public QQmlDataTest { Q_OBJECT @@ -70,6 +72,7 @@ public: tst_QQuickListView(); private slots: + void init(); // Test both QListModelInterface and QAbstractItemModel model types void qListModelInterface_items(); void qListModelInterface_package_items(); @@ -206,6 +209,38 @@ private: void inserted_more_data(); void removed_more_data(); void moved_data(); + +#ifdef SHARE_VIEWS + QQuickView *getView() { + if (m_view) { + if (QString(QTest::currentTestFunction()) != testForView) { + delete m_view; + m_view = 0; + } else { + m_view->setSource(QUrl()); + return m_view; + } + } + + testForView = QTest::currentTestFunction(); + m_view = createView(); + return m_view; + } + void releaseView(QQuickView *view) { + Q_ASSERT(view == m_view); + m_view->setSource(QUrl()); + } +#else + QQuickView *getView() { + return createView(); + } + void releaseView(QQuickView *view) { + delete view; + } +#endif + + QQuickView *m_view; + QString testForView; }; class TestObject : public QObject @@ -247,10 +282,21 @@ public: int mCacheBuffer; }; -tst_QQuickListView::tst_QQuickListView() +tst_QQuickListView::tst_QQuickListView() : m_view(0) { } +void tst_QQuickListView::init() +{ +#ifdef SHARE_VIEWS + if (m_view && QString(QTest::currentTestFunction()) != testForView) { + testForView = QString(); + delete m_view; + m_view = 0; + } +#endif +} + template <class T> void tst_QQuickListView::items(const QUrl &source, bool forceLayout) { @@ -486,7 +532,7 @@ void tst_QQuickListView::inserted_more() for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); @@ -544,7 +590,7 @@ void tst_QQuickListView::inserted_more() QTRY_COMPARE(number->text(), model.number(i)); } - delete canvas; + releaseView(canvas); delete testObject; } @@ -635,7 +681,7 @@ void tst_QQuickListView::insertBeforeVisible() QFETCH(int, cacheBuffer); QQuickText *name; - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QmlListModel model; for (int i = 0; i < 30; i++) @@ -696,7 +742,7 @@ void tst_QQuickListView::insertBeforeVisible() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); delete testObject; } @@ -914,7 +960,7 @@ void tst_QQuickListView::removed_more(const QUrl &source) QQuickText *name; QQuickText *number; - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); T model; for (int i = 0; i < 30; i++) @@ -976,7 +1022,7 @@ void tst_QQuickListView::removed_more(const QUrl &source) QTRY_COMPARE(number->text(), model.number(i)); } - delete canvas; + releaseView(canvas); delete testObject; } @@ -1136,7 +1182,7 @@ void tst_QQuickListView::moved(const QUrl &source) QQuickText *name; QQuickText *number; - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); T model; for (int i = 0; i < 30; i++) @@ -1201,7 +1247,7 @@ void tst_QQuickListView::moved(const QUrl &source) QTRY_COMPARE(listview->currentIndex(), i); } - delete canvas; + releaseView(canvas); delete testObject; } @@ -1363,7 +1409,7 @@ void tst_QQuickListView::multipleChanges() QFETCH(int, newCount); QFETCH(int, newCurrentIndex); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QmlListModel model; for (int i = 0; i < startCount; i++) @@ -1435,7 +1481,7 @@ void tst_QQuickListView::multipleChanges() } delete testObject; - delete canvas; + releaseView(canvas); } void tst_QQuickListView::multipleChanges_data() @@ -2136,6 +2182,23 @@ void tst_QQuickListView::sectionsPositioning() QTRY_VERIFY(item = findVisibleChild(contentItem, "sect_aaa")); // inline label restored QCOMPARE(item->y(), 0.); + // if an empty model is set the header/footer should be cleaned up + canvas->rootObject()->setProperty("sectionPositioning", QVariant(int(QQuickViewSection::InlineLabels | QQuickViewSection::CurrentLabelAtStart | QQuickViewSection::NextLabelAtEnd))); + QTRY_VERIFY(findVisibleChild(contentItem, "sect_aaa")); // section header + QTRY_VERIFY(findVisibleChild(contentItem, "sect_new")); // section footer + QmlListModel model1; + ctxt->setContextProperty("testModel", &model1); + QTRY_VERIFY(!findVisibleChild(contentItem, "sect_aaa")); // section header + QTRY_VERIFY(!findVisibleChild(contentItem, "sect_new")); // section footer + + // clear model - header/footer should be cleaned up + ctxt->setContextProperty("testModel", &model); + QTRY_VERIFY(findVisibleChild(contentItem, "sect_aaa")); // section header + QTRY_VERIFY(findVisibleChild(contentItem, "sect_new")); // section footer + model.clear(); + QTRY_VERIFY(!findVisibleChild(contentItem, "sect_aaa")); // section header + QTRY_VERIFY(!findVisibleChild(contentItem, "sect_new")); // section footer + delete canvas; } @@ -2189,7 +2252,7 @@ void tst_QQuickListView::currentIndex_delayedItemCreation() { QFETCH(bool, setCurrentToZero); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); // test currentIndexChanged() is emitted even if currentIndex = 0 on start up // (since the currentItem will have changed and that shares the same index) @@ -2207,7 +2270,7 @@ void tst_QQuickListView::currentIndex_delayedItemCreation() QCOMPARE(listview->currentIndex(), 0); QTRY_COMPARE(spy.count(), 1); - delete canvas; + releaseView(canvas); } void tst_QQuickListView::currentIndex_delayedItemCreation_data() @@ -3030,7 +3093,7 @@ void tst_QQuickListView::header() for (int i = 0; i < 30; i++) model.addItem("Item" + QString::number(i), ""); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); canvas->rootContext()->setContextProperty("testModel", &model); canvas->rootContext()->setContextProperty("initialViewWidth", 240); canvas->rootContext()->setContextProperty("initialViewHeight", 320); @@ -3092,12 +3155,12 @@ void tst_QQuickListView::header() QVERIFY(item); QCOMPARE(item->pos(), firstDelegatePos); - delete canvas; + releaseView(canvas); // QTBUG-21207 header should become visible if view resizes from initial empty size - canvas = createView(); + canvas = getView(); canvas->rootContext()->setContextProperty("testModel", &model); canvas->rootContext()->setContextProperty("initialViewWidth", 0.0); canvas->rootContext()->setContextProperty("initialViewHeight", 0.0); @@ -3116,8 +3179,7 @@ void tst_QQuickListView::header() QTRY_COMPARE(listview->headerItem()->pos(), initialHeaderPos); QCOMPARE(QPointF(listview->contentX(), listview->contentY()), initialContentPos); - - delete canvas; + releaseView(canvas); } void tst_QQuickListView::header_data() @@ -3212,7 +3274,7 @@ void tst_QQuickListView::footer() QFETCH(QPointF, changedContentPos); QFETCH(QPointF, resizeContentPos); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QmlListModel model; for (int i = 0; i < 3; i++) @@ -3306,7 +3368,7 @@ void tst_QQuickListView::footer() footer->setWidth(40); QTRY_COMPARE(QPointF(listview->contentX(), listview->contentY()), resizeContentPos); - delete canvas; + releaseView(canvas); } void tst_QQuickListView::footer_data() @@ -3467,6 +3529,45 @@ void tst_QQuickListView::headerFooter() delete canvas; } + { + // Reset model + QQuickView *canvas = createView(); + + QaimModel model; + for (int i = 0; i < 4; i++) + model.addItem("Item" + QString::number(i), ""); + QQmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(testFileUrl("headerfooter.qml")); + qApp->processEvents(); + + QQuickListView *listview = qobject_cast<QQuickListView*>(canvas->rootObject()); + QTRY_VERIFY(listview != 0); + + QQuickItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem != 0); + + QQuickItem *header = findItem<QQuickItem>(contentItem, "header"); + QVERIFY(header); + QCOMPARE(header->y(), -header->height()); + + QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer"); + QVERIFY(footer); + QCOMPARE(footer->y(), 30.*4); + + model.reset(); + + header = findItem<QQuickItem>(contentItem, "header"); + QVERIFY(header); + QCOMPARE(header->y(), -header->height()); + + footer = findItem<QQuickItem>(contentItem, "footer"); + QVERIFY(footer); + QCOMPARE(footer->y(), 30.*4); + + delete canvas; + } } void tst_QQuickListView::resizeView() @@ -3835,7 +3936,7 @@ void tst_QQuickListView::indexAt_itemAt() QFETCH(qreal, y); QFETCH(int, index); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QmlListModel model; for (int i = 0; i < 30; i++) @@ -3866,7 +3967,7 @@ void tst_QQuickListView::indexAt_itemAt() QCOMPARE(listview->indexAt(x,y), index); QVERIFY(listview->itemAt(x,y) == item); - delete canvas; + releaseView(canvas); delete testObject; } @@ -3963,7 +4064,7 @@ void tst_QQuickListView::onRemove() for (int i=0; i<initialItemCount; i++) model.addItem(QString("value %1").arg(i), "dummy value"); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("delegateHeight", delegateHeight); @@ -3976,7 +4077,7 @@ void tst_QQuickListView::onRemove() QCOMPARE(object->property("removedDelegateCount"), QVariant(removeCount)); - delete canvas; + releaseView(canvas); } void tst_QQuickListView::onRemove_data() @@ -4189,7 +4290,7 @@ void tst_QQuickListView::marginsResize() QFETCH(qreal, start); QFETCH(qreal, end); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); canvas->setSource(testFileUrl("margins2.qml")); canvas->show(); @@ -4222,7 +4323,7 @@ void tst_QQuickListView::marginsResize() else QTRY_COMPARE(listview->contentX(), start); - delete canvas; + releaseView(canvas); } void tst_QQuickListView::marginsResize_data() @@ -4278,7 +4379,7 @@ void tst_QQuickListView::snapToItem() QFETCH(qreal, endExtent); QFETCH(qreal, startExtent); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); canvas->setSource(testFileUrl("snapToItem.qml")); canvas->show(); @@ -4329,7 +4430,7 @@ void tst_QQuickListView::snapToItem() else QCOMPARE(listview->contentX(), startExtent); - delete canvas; + releaseView(canvas); } void tst_QQuickListView::qListModelInterface_items() @@ -4620,7 +4721,7 @@ void tst_QQuickListView::snapOneItem() QSKIP("QTBUG-24338"); #endif - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); canvas->setSource(testFileUrl("snapOneItem.qml")); canvas->show(); @@ -4688,7 +4789,7 @@ void tst_QQuickListView::snapOneItem() QCOMPARE(currentIndexSpy.count(), 6); } - delete canvas; + releaseView(canvas); } void tst_QQuickListView::unrequestedVisibility() @@ -4873,7 +4974,7 @@ void tst_QQuickListView::populateTransitions() model.addItem("item" + QString::number(i), ""); } - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); canvas->rootContext()->setContextProperty("testModel", &model); canvas->rootContext()->setContextProperty("testObject", new TestObject(canvas->rootContext())); canvas->rootContext()->setContextProperty("usePopulateTransition", usePopulateTransition); @@ -4971,7 +5072,7 @@ void tst_QQuickListView::populateTransitions() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); } void tst_QQuickListView::populateTransitions_data() @@ -5011,7 +5112,7 @@ void tst_QQuickListView::addTransitions() QaimModel model_targetItems_transitionFrom; QaimModel model_displacedItems_transitionVia; - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); TestObject *testObject = new TestObject; ctxt->setContextProperty("testModel", &model); @@ -5109,7 +5210,7 @@ void tst_QQuickListView::addTransitions() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); delete testObject; } @@ -5206,7 +5307,7 @@ void tst_QQuickListView::moveTransitions() QaimModel model_targetItems_transitionVia; QaimModel model_displacedItems_transitionVia; - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); TestObject *testObject = new TestObject; ctxt->setContextProperty("testModel", &model); @@ -5294,7 +5395,7 @@ void tst_QQuickListView::moveTransitions() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); delete testObject; } @@ -5409,7 +5510,7 @@ void tst_QQuickListView::removeTransitions() QaimModel model_targetItems_transitionTo; QaimModel model_displacedItems_transitionVia; - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); TestObject *testObject = new TestObject; ctxt->setContextProperty("testModel", &model); @@ -5508,7 +5609,7 @@ void tst_QQuickListView::removeTransitions() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); delete testObject; } @@ -5608,7 +5709,7 @@ void tst_QQuickListView::displacedTransitions() QPointF moveDisplaced_transitionVia(50, -100); QPointF removeDisplaced_transitionVia(150, 100); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); TestObject *testObject = new TestObject(canvas); ctxt->setContextProperty("testModel", &model); @@ -5720,7 +5821,7 @@ void tst_QQuickListView::displacedTransitions() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); } void tst_QQuickListView::displacedTransitions_data() @@ -5832,7 +5933,7 @@ void tst_QQuickListView::multipleTransitions() for (int i = 0; i < initialCount; i++) model.addItem("Original item" + QString::number(i), ""); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); TestObject *testObject = new TestObject; ctxt->setContextProperty("testModel", &model); @@ -5924,7 +6025,7 @@ void tst_QQuickListView::multipleTransitions() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); delete testObject; } @@ -5996,7 +6097,7 @@ void tst_QQuickListView::multipleDisplaced() for (int i = 0; i < 30; i++) model.addItem("Original item" + QString::number(i), ""); - QQuickView *canvas = createView(); + QQuickView *canvas = getView(); QQmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); ctxt->setContextProperty("testObject", new TestObject(canvas)); @@ -6033,7 +6134,7 @@ void tst_QQuickListView::multipleDisplaced() QTRY_COMPARE(name->text(), model.name(i)); } - delete canvas; + releaseView(canvas); } QList<int> tst_QQuickListView::toIntList(const QVariantList &list) diff --git a/tests/auto/quick/qquickloader/data/TestComponent.2.qml b/tests/auto/quick/qquickloader/data/TestComponent.2.qml new file mode 100644 index 0000000000..d6e99028b5 --- /dev/null +++ b/tests/auto/quick/qquickloader/data/TestComponent.2.qml @@ -0,0 +1,592 @@ +import QtQuick 2.0 + +Item { + id: root + objectName: "root" + property int zero: 0 + + Item { + id: c1 + objectName: "c1" + property int one: zero + 1 + + Item { + id: c1c1 + objectName: "c1c1" + property bool two: c2c1c1.two + } + + Item { + id: c1c2 + objectName: "c1c2" + property string three: "three" + + Rectangle { + id: c1c2c3 + objectName: "c1c2c3" + property alias othercolor: c2c1.color + color: if (c2c1.color == Qt.rgba(0,0,1)) Qt.rgba(1,0,0); else Qt.rgba(0,1,0); + } + } + } + + Item { + id: c2 + objectName: "c2" + property string two: "two" + + Rectangle { + id: c2c1 + objectName: "c2c1" + property string three: "2" + c1c2.three + color: "blue" + + MouseArea { + id: c2c1c1 + objectName: "c2c1c1" + property bool two: false + onClicked: two = !two + } + + Item { + id: c2c1c2 + objectName: "c2c1c2" + property string three: "1" + parent.three + } + } + } + + Item { + id: c3 + objectName: "c3" + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + } + + property alias c1one: c1.one + property bool success: true + Component.onCompleted: { + // test state after initial bindings evaluation + if (zero != 0) success = false; + if (c1.one != 1) success = false; + if (c1c1.two != false) success = false; + if (c1c2.three != "three") success = false; + if (c1c2c3.color != Qt.rgba(1,0,0)) success = false; + if (c2.two != "two") success = false; + if (c2c1.three != "2three") success = false; + if (c2c1.color != Qt.rgba(0,0,1)) success = false; + if (c2c1c1.two != false) success = false; + if (c2c1c2.three != "12three") success = false; + if (c3.children.length != 500) success = false; + + // now retrigger bindings evaluation + root.zero = 5; + if (c1.one != 6) success = false; + c2c1c1.two = true; + if (c1c1.two != true) success = false; + c1c2.three = "3"; + if (c2c1.three != "23") success = false; + if (c2c1c2.three != "123") success = false; + c2c1.color = Qt.rgba(1,0,0); + if (c1c2c3.color != Qt.rgba(0,1,0)) success = false; + if (c1c2c3.othercolor != Qt.rgba(1,0,0)) success = false; + } +} diff --git a/tests/auto/quick/qquickloader/data/TestComponent.qml b/tests/auto/quick/qquickloader/data/TestComponent.qml new file mode 100644 index 0000000000..81ea07cb88 --- /dev/null +++ b/tests/auto/quick/qquickloader/data/TestComponent.qml @@ -0,0 +1,89 @@ +import QtQuick 2.0 + +Item { + id: root + objectName: "root" + property int zero: 0 + property int one: 1 + + Item { + id: c1 + objectName: "c1" + property int one: zero + parent.one + + Item { + id: c1c1 + objectName: "c1c1" + property bool two: c2c1c1.two + } + + Item { + id: c1c2 + objectName: "c1c2" + property string three: "three" + + Rectangle { + id: c1c2c3 + objectName: "c1c2c3" + property alias othercolor: c2c1.color + color: if (c2c1.color == Qt.rgba(0,0,1)) Qt.rgba(1,0,0); else Qt.rgba(0,1,0); + } + } + } + + Item { + id: c2 + objectName: "c2" + property string two: "two" + + Rectangle { + id: c2c1 + objectName: "c2c1" + property string three: "2" + c1c2.three + color: "blue" + + MouseArea { + id: c2c1c1 + objectName: "c2c1c1" + property bool two: false + onClicked: two = !two + } + + Item { + id: c2c1c2 + objectName: "c2c1c2" + property string three: "1" + parent.three + } + } + } + + property alias c1one: c1.one + property bool success: true + Component.onCompleted: { + // test state after initial bindings evaluation + if (zero != 0) success = false; + if (c1.one != 1) success = false; + if (c1c1.two != false) success = false; + if (c1c2.three != "three") success = false; + if (c1c2c3.color != Qt.rgba(1,0,0)) success = false; + if (c2.two != "two") success = false; + if (c2c1.three != "2three") success = false; + if (c2c1.color != Qt.rgba(0,0,1)) success = false; + if (c2c1c1.two != false) success = false; + if (c2c1c2.three != "12three") success = false; + + // now retrigger bindings evaluation + root.zero = 5; + if (c1.one != 6) success = false; + root.one = 50; + if (c1.one != 55) success = false; + c2c1c1.two = true; + if (c1c1.two != true) success = false; + c1c2.three = "3"; + if (c2c1.three != "23") success = false; + if (c2c1c2.three != "123") success = false; + c2c1.color = Qt.rgba(1,0,0); + if (c1c2c3.color != Qt.rgba(0,1,0)) success = false; + if (c1c2c3.othercolor != Qt.rgba(1,0,0)) success = false; + } +} diff --git a/tests/auto/quick/qquickloader/data/simultaneous.qml b/tests/auto/quick/qquickloader/data/simultaneous.qml new file mode 100644 index 0000000000..cab6498863 --- /dev/null +++ b/tests/auto/quick/qquickloader/data/simultaneous.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 + +Rectangle { + width: 400; height: 400 + + function loadComponents() { + asyncLoader.source = "TestComponent.2.qml" + syncLoader.source = "TestComponent.qml" + } + + Loader { + id: asyncLoader + objectName: "asyncLoader" + asynchronous: true + } + + Loader { + id: syncLoader + objectName: "syncLoader" + asynchronous: false + } +} diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp index 77d0c29220..bdf47fa9e9 100644 --- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp +++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp @@ -56,13 +56,21 @@ class PeriodicIncubationController : public QObject, { public: PeriodicIncubationController() { + incubated = false; startTimer(16); } + bool incubated; + protected: virtual void timerEvent(QTimerEvent *) { incubateFor(15); } + + virtual void incubatingObjectCountChanged(int count) { + if (count) + incubated = true; + } }; class tst_QQuickLoader : public QQmlDataTest @@ -102,6 +110,7 @@ private slots: void asynchronous_data(); void asynchronous(); void asynchronous_clear(); + void simultaneousSyncAsync(); void parented(); void sizeBound(); @@ -481,7 +490,7 @@ void tst_QQuickLoader::failNetworkRequest() QTRY_VERIFY(loader->status() == QQuickLoader::Error); QVERIFY(loader->item() == 0); - QCOMPARE(loader->progress(), 0.0); + QCOMPARE(loader->progress(), 1.0); QCOMPARE(loader->property("did_load").toInt(), 123); QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 0); @@ -644,7 +653,7 @@ void tst_QQuickLoader::initialPropertyValues_data() << (QVariantList() << 2 << 0); QTest::newRow("set source with initial property values specified, active = false") << testFileUrl("initialPropertyValues.3.qml") - << (QStringList() << QString(QLatin1String("file://") + testFileUrl("initialPropertyValues.3.qml").toLocalFile() + QLatin1String(":16: TypeError: Cannot read property 'canary' of null"))) + << (QStringList() << QString(testFileUrl("initialPropertyValues.3.qml").toString() + QLatin1String(":16: TypeError: Cannot read property 'canary' of null"))) << (QStringList()) << (QVariantList()); @@ -856,7 +865,7 @@ void tst_QQuickLoader::asynchronous_data() QTest::newRow("Valid component") << testFileUrl("BigComponent.qml") << QStringList(); - QTest::newRow("Non-existant component") << testFileUrl("IDoNotExist.qml") + QTest::newRow("Non-existent component") << testFileUrl("IDoNotExist.qml") << (QStringList() << QString(testFileUrl("IDoNotExist.qml").toString() + ": File not found")); QTest::newRow("Invalid component") << testFileUrl("InvalidSourceComponent.qml") @@ -870,6 +879,8 @@ void tst_QQuickLoader::asynchronous() if (!engine.incubationController()) engine.setIncubationController(new PeriodicIncubationController); + PeriodicIncubationController *controller = static_cast<PeriodicIncubationController*>(engine.incubationController()); + controller->incubated = false; QQmlComponent component(&engine, testFileUrl("asynchronous.qml")); QQuickItem *root = qobject_cast<QQuickItem*>(component.create()); QVERIFY(root); @@ -881,19 +892,20 @@ void tst_QQuickLoader::asynchronous() QTest::ignoreMessage(QtWarningMsg, warning.toUtf8().constData()); QVERIFY(!loader->item()); + QCOMPARE(loader->progress(), 0.0); root->setProperty("comp", qmlFile.toString()); QMetaObject::invokeMethod(root, "loadComponent"); QVERIFY(!loader->item()); if (expectedWarnings.isEmpty()) { QCOMPARE(loader->status(), QQuickLoader::Loading); - QCOMPARE(engine.incubationController()->incubatingObjectCount(), 1); - + QVERIFY(!controller->incubated); // asynchronous compilation means not immediately compiled/incubating. + QTRY_VERIFY(controller->incubated); // but should start incubating once compilation is complete. QTRY_VERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(loader->status(), QQuickLoader::Ready); } else { - QCOMPARE(loader->progress(), 1.0); + QTRY_COMPARE(loader->progress(), 1.0); QTRY_COMPARE(loader->status(), QQuickLoader::Error); } @@ -943,6 +955,37 @@ void tst_QQuickLoader::asynchronous_clear() QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); } +void tst_QQuickLoader::simultaneousSyncAsync() +{ + if (!engine.incubationController()) + engine.setIncubationController(new PeriodicIncubationController); + PeriodicIncubationController *controller = static_cast<PeriodicIncubationController*>(engine.incubationController()); + controller->incubated = false; + QQmlComponent component(&engine, testFileUrl("simultaneous.qml")); + QQuickItem *root = qobject_cast<QQuickItem*>(component.create()); + QVERIFY(root); + + QQuickLoader *asyncLoader = root->findChild<QQuickLoader*>("asyncLoader"); + QQuickLoader *syncLoader = root->findChild<QQuickLoader*>("syncLoader"); + QVERIFY(asyncLoader); + QVERIFY(syncLoader); + + QVERIFY(!asyncLoader->item()); + QVERIFY(!syncLoader->item()); + QMetaObject::invokeMethod(root, "loadComponents"); + QVERIFY(!asyncLoader->item()); + QVERIFY(syncLoader->item()); + + QCOMPARE(asyncLoader->status(), QQuickLoader::Loading); + QVERIFY(!controller->incubated); // asynchronous compilation means not immediately compiled/incubating. + QTRY_VERIFY(controller->incubated); // but should start incubating once compilation is complete. + QTRY_VERIFY(asyncLoader->item()); + QCOMPARE(asyncLoader->progress(), 1.0); + QCOMPARE(asyncLoader->status(), QQuickLoader::Ready); + + delete root; +} + void tst_QQuickLoader::parented() { QQmlComponent component(&engine, testFileUrl("parented.qml")); diff --git a/tests/auto/quick/qquickmultipointtoucharea/qquickmultipointtoucharea.pro b/tests/auto/quick/qquickmultipointtoucharea/qquickmultipointtoucharea.pro index 8181eb8c5f..6816566c25 100644 --- a/tests/auto/quick/qquickmultipointtoucharea/qquickmultipointtoucharea.pro +++ b/tests/auto/quick/qquickmultipointtoucharea/qquickmultipointtoucharea.pro @@ -6,4 +6,6 @@ SOURCES += tst_qquickmultipointtoucharea.cpp TESTDATA = data/* +include(../../shared/util.pri) + QT += core-private gui-private qml-private quick-private testlib diff --git a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp index 507612f8ce..1e0cd4eead 100644 --- a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp +++ b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp @@ -44,14 +44,16 @@ #include <private/qquickmultipointtoucharea_p.h> #include <private/qquickflickable_p.h> #include <QtQuick/qquickview.h> +#include "../../shared/util.h" -class tst_QQuickMultiPointTouchArea: public QObject +class tst_QQuickMultiPointTouchArea : public QQmlDataTest { Q_OBJECT public: tst_QQuickMultiPointTouchArea() : device(0) { } private slots: void initTestCase() { + QQmlDataTest::initTestCase(); if (!device) { device = new QTouchDevice; device->setType(QTouchDevice::TouchScreen); @@ -714,7 +716,7 @@ void tst_QQuickMultiPointTouchArea::invisible() QQuickView *tst_QQuickMultiPointTouchArea::createAndShowView(const QString &file) { QQuickView *canvas = new QQuickView(0); - canvas->setSource(QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + QLatin1String("/data/") + file)); + canvas->setSource(testFileUrl(file)); canvas->show(); canvas->requestActivateWindow(); QTest::qWaitForWindowShown(canvas); diff --git a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp index 8f517a4fe3..ab24fbe995 100644 --- a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp +++ b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp @@ -532,7 +532,7 @@ void tst_qquickpositioners::addTransitions(const QString &positionerObjectName) ctxt->setContextProperty("model_displacedItems_transitionVia", &model_displacedItems_transitionVia); ctxt->setContextProperty("targetItems_transitionFrom", targetItems_transitionFrom); ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia); - canvas->setSource(testFile("transitions.qml")); + canvas->setSource(testFileUrl("transitions.qml")); canvas->show(); qApp->processEvents(); @@ -641,7 +641,7 @@ void tst_qquickpositioners::moveTransitions(const QString &positionerObjectName) ctxt->setContextProperty("model_displacedItems_transitionVia", &model_displacedItems_transitionVia); ctxt->setContextProperty("targetItems_transitionFrom", targetItems_transitionFrom); ctxt->setContextProperty("displacedItems_transitionVia", displacedItems_transitionVia); - canvas->setSource(testFile("transitions.qml")); + canvas->setSource(testFileUrl("transitions.qml")); canvas->show(); qApp->processEvents(); diff --git a/tests/auto/quick/qquicktext/qquicktext.pro b/tests/auto/quick/qquicktext/qquicktext.pro index 8932664fa3..daa7bed97b 100644 --- a/tests/auto/quick/qquicktext/qquicktext.pro +++ b/tests/auto/quick/qquicktext/qquicktext.pro @@ -15,3 +15,5 @@ TESTDATA = data/* CONFIG += parallel_test QT += core-private gui-private v8-private qml-private quick-private network testlib + +win32:CONFIG += insignificant_test # QTBUG-24789 diff --git a/tests/auto/quick/qquicktextinput/qquicktextinput.pro b/tests/auto/quick/qquicktextinput/qquicktextinput.pro index 13b087eef5..336338f500 100644 --- a/tests/auto/quick/qquicktextinput/qquicktextinput.pro +++ b/tests/auto/quick/qquicktextinput/qquicktextinput.pro @@ -9,3 +9,5 @@ include (../../shared/util.pri) TESTDATA = data/* QT += core-private gui-private v8-private qml-private quick-private testlib + +win32:CONFIG += insignificant_test # QTBUG-24790 diff --git a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp index dbfd4919b9..73a35c1c78 100644 --- a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp +++ b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp @@ -612,12 +612,12 @@ void tst_qquickvisualdatamodel::modelProperties() QUrl source(testFileUrl("modelproperties2.qml")); //3 items, 3 i each - QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":13: ReferenceError: Can't find variable: modelData"); - QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":13: ReferenceError: Can't find variable: modelData"); - QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":13: ReferenceError: Can't find variable: modelData"); - QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: Can't find variable: modelData"); - QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: Can't find variable: modelData"); - QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: Can't find variable: modelData"); + QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":13: ReferenceError: modelData is not defined"); + QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":13: ReferenceError: modelData is not defined"); + QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":13: ReferenceError: modelData is not defined"); + QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: modelData is not defined"); + QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: modelData is not defined"); + QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":11: ReferenceError: modelData is not defined"); QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Cannot read property 'display' of undefined"); QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Cannot read property 'display' of undefined"); QTest::ignoreMessage(QtWarningMsg, source.toString().toLatin1() + ":17: TypeError: Cannot read property 'display' of undefined"); diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro index 45fa9763da..654b1c86f0 100644 --- a/tests/auto/quick/quick.pro +++ b/tests/auto/quick/quick.pro @@ -19,6 +19,7 @@ PRIVATETESTS += \ qquickpath \ qquicksmoothedanimation \ qquickspringanimation \ + qquickanimationcontroller \ qquickstyledtext \ qquickstates \ qquicksystempalette \ diff --git a/tests/auto/quick/rendernode/tst_rendernode.cpp b/tests/auto/quick/rendernode/tst_rendernode.cpp index b456a5980e..f3832b436f 100644 --- a/tests/auto/quick/rendernode/tst_rendernode.cpp +++ b/tests/auto/quick/rendernode/tst_rendernode.cpp @@ -54,10 +54,10 @@ class tst_rendernode: public QQmlDataTest public: tst_rendernode(); - QImage runTest(const QString &url) + QImage runTest(const QString &fileName) { QQuickView view; - view.setSource(QUrl(url)); + view.setSource(testFileUrl(fileName)); view.show(); QTest::qWaitForWindowShown(&view); @@ -194,7 +194,7 @@ static void fuzzyCompareColor(QRgb x, QRgb y) void tst_rendernode::renderOrder() { - QImage fb = runTest(testFile("RenderOrder.qml")); + QImage fb = runTest("RenderOrder.qml"); int x1 = fb.width() / 8; int x2 = fb.width() * 3 / 8; int x3 = fb.width() * 5 / 8; @@ -216,7 +216,7 @@ void tst_rendernode::renderOrder() void tst_rendernode::messUpState() { - QImage fb = runTest(testFile("MessUpState.qml")); + QImage fb = runTest("MessUpState.qml"); int x1 = 0; int x2 = fb.width() / 2; int x3 = fb.width() - 1; |