diff options
author | Sergio Ahumada <sergio.ahumada@digia.com> | 2013-08-05 10:42:21 +0200 |
---|---|---|
committer | Sergio Ahumada <sergio.ahumada@digia.com> | 2013-08-05 10:42:21 +0200 |
commit | 1d3b9db5b54d8ae99c6b149c8d3d91eda19b5838 (patch) | |
tree | 9ffbf9d6d2ed6b0aef6155215767c56655ff405b /tests | |
parent | 45792359f25813af18b7416e4c18737ed4b20bff (diff) | |
parent | 0316506d9ddbc3ca9f26f880b9e7fb5d5b0fec36 (diff) |
Merge branch 'stable' into dev
Conflicts:
.qmake.conf
Change-Id: I06f79bcbde13c7b12905492a17dbcbb4a594e557
Diffstat (limited to 'tests')
20 files changed, 533 insertions, 154 deletions
diff --git a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp index 9308bc6f40..b2a63f064c 100644 --- a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp +++ b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp @@ -74,6 +74,7 @@ private slots: void showFiles(); void resetFiltering(); void refresh(); + void cdUp(); #if defined (Q_OS_WIN) && !defined (Q_OS_WINCE) // WinCE does not have drive concept, so lets execute this test only on desktop Windows. void changeDrive(); @@ -203,6 +204,33 @@ void tst_qquickfolderlistmodel::refresh() QTRY_COMPARE(removeEnd, count-1); // wait for refresh } +void tst_qquickfolderlistmodel::cdUp() +{ + enum { maxIterations = 50 }; + QQmlComponent component(&engine, testFileUrl("basic.qml")); + checkNoErrors(component); + + QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create()); + QVERIFY(flm != 0); + const QUrl startFolder = flm->property("folder").toUrl(); + QVERIFY(startFolder.isValid()); + + // QTBUG-32139: Ensure navigating upwards terminates cleanly and does not + // return invalid Urls like "file:". + for (int i = 0; ; ++i) { + const QVariant folderV = flm->property("parentFolder"); + const QUrl folder = folderV.toUrl(); + if (!folder.isValid()) + break; + QVERIFY(folder.toString() != QLatin1String("file:")); + QVERIFY2(i < maxIterations, + qPrintable(QString::fromLatin1("Unable to reach root after %1 iterations starting from %2, stuck at %3") + .arg(maxIterations).arg(QDir::toNativeSeparators(startFolder.toLocalFile()), + QDir::toNativeSeparators(folder.toLocalFile())))); + flm->setProperty("folder", folderV); + } +} + #if defined (Q_OS_WIN) && !defined (Q_OS_WINCE) void tst_qquickfolderlistmodel::changeDrive() { diff --git a/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp b/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp index dbb4736c05..15282d4b02 100644 --- a/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp +++ b/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp @@ -1070,106 +1070,131 @@ void tst_QQuickDrag::recursion_data() { QTest::addColumn<QString>("script"); QTest::addColumn<int>("type"); + QTest::addColumn<int>("moveEvents"); QTest::addColumn<QByteArray>("warning"); QTest::newRow("Drag.start() in Enter") << QString("Drag.start()") << int(QEvent::DragEnter) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: start() cannot be called from within a drag event handler"); QTest::newRow("Drag.cancel() in Enter") << QString("Drag.cancel()") << int(QEvent::DragEnter) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: cancel() cannot be called from within a drag event handler"); QTest::newRow("Drag.drop() in Enter") << QString("Drag.drop()") << int(QEvent::DragEnter) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: drop() cannot be called from within a drag event handler"); QTest::newRow("Drag.active = true in Enter") << QString("Drag.active = true") << int(QEvent::DragEnter) + << 1 << QByteArray(); QTest::newRow("Drag.active = false in Enter") << QString("Drag.active = false") << int(QEvent::DragEnter) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: active cannot be changed from within a drag event handler"); QTest::newRow("move in Enter") << QString("x = 23") << int(QEvent::DragEnter) + << 1 << QByteArray(); QTest::newRow("Drag.start() in Move") << QString("Drag.start()") << int(QEvent::DragMove) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: start() cannot be called from within a drag event handler"); QTest::newRow("Drag.cancel() in Move") << QString("Drag.cancel()") << int(QEvent::DragMove) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: cancel() cannot be called from within a drag event handler"); QTest::newRow("Drag.drop() in Move") << QString("Drag.drop()") << int(QEvent::DragMove) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: drop() cannot be called from within a drag event handler"); QTest::newRow("Drag.active = true in Move") << QString("Drag.active = true") << int(QEvent::DragMove) + << 1 << QByteArray(); QTest::newRow("Drag.active = false in Move") << QString("Drag.active = false") << int(QEvent::DragMove) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: active cannot be changed from within a drag event handler"); QTest::newRow("move in Move") << QString("x = 23") << int(QEvent::DragMove) + << 2 << QByteArray(); QTest::newRow("Drag.start() in Leave") << QString("Drag.start()") << int(QEvent::DragLeave) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: start() cannot be called from within a drag event handler"); QTest::newRow("Drag.cancel() in Leave") << QString("Drag.cancel()") << int(QEvent::DragLeave) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: cancel() cannot be called from within a drag event handler"); QTest::newRow("Drag.drop() in Leave") << QString("Drag.drop()") << int(QEvent::DragLeave) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: drop() cannot be called from within a drag event handler"); QTest::newRow("Drag.active = true in Leave") << QString("Drag.active = true") << int(QEvent::DragLeave) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: active cannot be changed from within a drag event handler"); QTest::newRow("Drag.active = false in Leave") << QString("Drag.active = false") << int(QEvent::DragLeave) + << 1 << QByteArray(); QTest::newRow("move in Leave") << QString("x = 23") << int(QEvent::DragLeave) + << 1 << QByteArray(); QTest::newRow("Drag.start() in Drop") << QString("Drag.start()") << int(QEvent::Drop) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: start() cannot be called from within a drag event handler"); QTest::newRow("Drag.cancel() in Drop") << QString("Drag.cancel()") << int(QEvent::Drop) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: cancel() cannot be called from within a drag event handler"); QTest::newRow("Drag.drop() in Drop") << QString("Drag.drop()") << int(QEvent::Drop) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: drop() cannot be called from within a drag event handler"); QTest::newRow("Drag.active = true in Drop") << QString("Drag.active = true") << int(QEvent::Drop) + << 1 << QByteArray("<Unknown File>: QML QQuickDragAttached: active cannot be changed from within a drag event handler"); QTest::newRow("Drag.active = false in Drop") << QString("Drag.active = false") << int(QEvent::Drop) + << 1 << QByteArray(); QTest::newRow("move in Drop") << QString("x = 23") << int(QEvent::Drop) + << 1 << QByteArray(); } @@ -1177,6 +1202,7 @@ void tst_QQuickDrag::recursion() { QFETCH(QString, script); QFETCH(int, type); + QFETCH(int, moveEvents); QFETCH(QByteArray, warning); if (!warning.isEmpty()) @@ -1206,22 +1232,36 @@ void tst_QQuickDrag::recursion() QCOMPARE(dropTarget.leaveEvents, 0); evaluate<void>(item, "y = 15"); + + // the evaluate statement above, y = 15, will cause + // QQuickItem::setY(15) to be called, leading to an + // event being posted that will be delivered + // to RecursingDropTarget::dragMoveEvent(), hence + // the following call to QCoreApplication::processEvents() QCoreApplication::processEvents(); + + + // Regarding 'move in Move' when + // RecursingDropTarget::dragMoveEvent() runs, + // its call 'evaluate' triggers a second + // move event (x = 23) that needs to be delivered. + QCoreApplication::processEvents(); + QCOMPARE(dropTarget.enterEvents, 1); - QCOMPARE(dropTarget.moveEvents, 1); + QCOMPARE(dropTarget.moveEvents, moveEvents); QCOMPARE(dropTarget.dropEvents, 0); QCOMPARE(dropTarget.leaveEvents, 0); if (type == QEvent::Drop) { QCOMPARE(evaluate<bool>(item, "Drag.drop() == Qt.MoveAction"), true); QCOMPARE(dropTarget.enterEvents, 1); - QCOMPARE(dropTarget.moveEvents, 1); + QCOMPARE(dropTarget.moveEvents, moveEvents); QCOMPARE(dropTarget.dropEvents, 1); QCOMPARE(dropTarget.leaveEvents, 0); } else { evaluate<void>(item, "Drag.cancel()"); QCOMPARE(dropTarget.enterEvents, 1); - QCOMPARE(dropTarget.moveEvents, 1); + QCOMPARE(dropTarget.moveEvents, moveEvents); QCOMPARE(dropTarget.dropEvents, 0); QCOMPARE(dropTarget.leaveEvents, 1); } diff --git a/tests/auto/quick/qquickflickable/data/ratios.qml b/tests/auto/quick/qquickflickable/data/ratios.qml new file mode 100644 index 0000000000..1291cada72 --- /dev/null +++ b/tests/auto/quick/qquickflickable/data/ratios.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 400 + height: 400 + + property bool forceNoFlicking: true + property double heightRatioIs: flickable.visibleArea.heightRatio + property double heightRatioShould: flickable.height / flickable.contentHeight + property double widthRatioIs: flickable.visibleArea.widthRatio + property double widthRatioShould: flickable.height / flickable.contentWidth + + Flickable { + id: flickable + flickableDirection: Flickable.AutoFlickDirection + width: forceNoFlicking ? contentItem.width /* so xflick() returns false */ : 20 + height: forceNoFlicking ? contentItem.height /* likewise */ : 20 + contentHeight: contentItem.height + contentWidth: contentItem.width + clip: true + + Rectangle { + id: contentItem + color: "red" + width: 300 + height: 300 + } + } +} + diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 3575dfa012..a8055b3467 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -67,6 +67,7 @@ private slots: void create(); void horizontalViewportSize(); void verticalViewportSize(); + void visibleAreaRatiosUpdate(); void properties(); void boundsBehavior(); void rebound(); @@ -158,6 +159,28 @@ void tst_qquickflickable::verticalViewportSize() delete obj; } +void tst_qquickflickable::visibleAreaRatiosUpdate() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("ratios.qml")); + QQuickItem *obj = qobject_cast<QQuickItem*>(c.create()); + + QVERIFY(obj != 0); + // check initial ratio values + QCOMPARE(obj->property("heightRatioIs").toDouble(), obj->property("heightRatioShould").toDouble()); + QCOMPARE(obj->property("widthRatioIs").toDouble(), obj->property("widthRatioShould").toDouble()); + // change flickable geometry so that flicking is enabled (content size > flickable size) + obj->setProperty("forceNoFlicking", false); + QCOMPARE(obj->property("heightRatioIs").toDouble(), obj->property("heightRatioShould").toDouble()); + QCOMPARE(obj->property("widthRatioIs").toDouble(), obj->property("widthRatioShould").toDouble()); + // change flickable geometry so that flicking is disabled (content size == flickable size) + obj->setProperty("forceNoFlicking", true); + QCOMPARE(obj->property("heightRatioIs").toDouble(), obj->property("heightRatioShould").toDouble()); + QCOMPARE(obj->property("widthRatioIs").toDouble(), obj->property("widthRatioShould").toDouble()); + + delete obj; +} + void tst_qquickflickable::properties() { QQmlEngine engine; diff --git a/tests/auto/quick/qquickgridview/qquickgridview.pro b/tests/auto/quick/qquickgridview/qquickgridview.pro index dd69cda49e..0e679387cc 100644 --- a/tests/auto/quick/qquickgridview/qquickgridview.pro +++ b/tests/auto/quick/qquickgridview/qquickgridview.pro @@ -12,5 +12,3 @@ TESTDATA = data/* QT += core-private gui-private v8-private qml-private quick-private testlib DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 - -mac:CONFIG+=insignificant_test # QTBUG-27890 diff --git a/tests/auto/quick/qquickimage/data/qtbug_32513.qml b/tests/auto/quick/qquickimage/data/qtbug_32513.qml new file mode 100644 index 0000000000..b6cbe33eec --- /dev/null +++ b/tests/auto/quick/qquickimage/data/qtbug_32513.qml @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, 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, Digia gives you certain additional +** rights. These rights are described in the Digia 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. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + width: 200; height: 200 + + Image { + cache: false + + NumberAnimation on opacity { + loops: Animation.Infinite + from: 1; to: 0 + } + + SequentialAnimation on source { + loops: Animation.Infinite + PropertyAction { value: "green.png" } + PauseAnimation { duration: 100 } + PropertyAction { value: "pattern.png" } + PauseAnimation { duration: 100 } + } + } +} diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp index 0804c7b900..8bdb9c9de5 100644 --- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp @@ -99,6 +99,7 @@ private slots: void sourceSize_QTBUG_16389(); void nullPixmapPaint(); void imageCrash_QTBUG_22125(); + void imageCrash_QTBUG_32513(); void sourceSize_data(); void sourceSize(); void progressAndStatusChanges(); @@ -704,6 +705,15 @@ void tst_qquickimage::imageCrash_QTBUG_22125() QCoreApplication::processEvents(); } +void tst_qquickimage::imageCrash_QTBUG_32513() +{ + QQuickView view(testFileUrl("qtbug_32513.qml")); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QTest::qWait(1000); + // shouldn't crash when the image changes sources +} + void tst_qquickimage::sourceSize_data() { QTest::addColumn<int>("sourceWidth"); diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp index a7343f686f..79f08d5147 100644 --- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp @@ -718,24 +718,24 @@ 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); + QQuickView view; + view.setSource(testFileUrl("multipleFocusClears.qml")); + view.show(); + ensureFocus(&view); + QTRY_VERIFY(QGuiApplication::focusWindow() == &view); } void tst_qquickitem::focusSubItemInNonFocusScope() { - QQuickView *view = new QQuickView; - view->setSource(testFileUrl("focusSubItemInNonFocusScope.qml")); - view->show(); - QTest::qWaitForWindowActive(view); + QQuickView view; + view.setSource(testFileUrl("focusSubItemInNonFocusScope.qml")); + view.show(); + QTest::qWaitForWindowActive(&view); - QQuickItem *dummyItem = view->rootObject()->findChild<QQuickItem *>("dummyItem"); + QQuickItem *dummyItem = view.rootObject()->findChild<QQuickItem *>("dummyItem"); QVERIFY(dummyItem); - QQuickItem *textInput = view->rootObject()->findChild<QQuickItem *>("textInput"); + QQuickItem *textInput = view.rootObject()->findChild<QQuickItem *>("textInput"); QVERIFY(textInput); QVERIFY(dummyItem->hasFocus()); @@ -747,8 +747,6 @@ void tst_qquickitem::focusSubItemInNonFocusScope() QVERIFY(!dummyItem->hasFocus()); QVERIFY(textInput->hasFocus()); QVERIFY(textInput->hasActiveFocus()); - - delete view; } void tst_qquickitem::parentItemWithFocus() @@ -880,24 +878,22 @@ void tst_qquickitem::reparentFocusedItem() void tst_qquickitem::constructor() { - QQuickItem *root = new QQuickItem; + QScopedPointer<QQuickItem> root(new QQuickItem); QVERIFY(root->parent() == 0); QVERIFY(root->parentItem() == 0); - QQuickItem *child1 = new QQuickItem(root); - QVERIFY(child1->parent() == root); - QVERIFY(child1->parentItem() == root); + QQuickItem *child1 = new QQuickItem(root.data()); + QVERIFY(child1->parent() == root.data()); + QVERIFY(child1->parentItem() == root.data()); QCOMPARE(root->childItems().count(), 1); QCOMPARE(root->childItems().at(0), child1); - QQuickItem *child2 = new QQuickItem(root); - QVERIFY(child2->parent() == root); - QVERIFY(child2->parentItem() == root); + QQuickItem *child2 = new QQuickItem(root.data()); + QVERIFY(child2->parent() == root.data()); + QVERIFY(child2->parentItem() == root.data()); QCOMPARE(root->childItems().count(), 2); QCOMPARE(root->childItems().at(0), child1); QCOMPARE(root->childItems().at(1), child2); - - delete root; } void tst_qquickitem::setParentItem() @@ -1157,80 +1153,87 @@ void tst_qquickitem::enabledFocus() QCOMPARE(window.activeFocusItem(), static_cast<QQuickItem *>(&child1)); } +static inline QByteArray msgItem(const QQuickItem *item) +{ + QString result; + QDebug(&result) << item; + return result.toLocal8Bit(); +} + void tst_qquickitem::mouseGrab() { - QQuickWindow *window = new QQuickWindow; - window->resize(200, 200); - window->show(); + QQuickWindow window; + window.setFramePosition(QPoint(100, 100)); + window.resize(200, 200); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); - TestItem *child1 = new TestItem; + QScopedPointer<TestItem> child1(new TestItem); + child1->setObjectName(QStringLiteral("child1")); child1->setAcceptedMouseButtons(Qt::LeftButton); child1->setSize(QSizeF(200, 100)); - child1->setParentItem(window->contentItem()); + child1->setParentItem(window.contentItem()); - TestItem *child2 = new TestItem; + QScopedPointer<TestItem> child2(new TestItem); + child2->setObjectName(QStringLiteral("child2")); child2->setAcceptedMouseButtons(Qt::LeftButton); child2->setY(51); child2->setSize(QSizeF(200, 100)); - child2->setParentItem(window->contentItem()); + child2->setParentItem(window.contentItem()); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(50,50)); + QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(50,50)); QTest::qWait(100); - QVERIFY(window->mouseGrabberItem() == child1); + QVERIFY2(window.mouseGrabberItem() == child1.data(), msgItem(window.mouseGrabberItem()).constData()); QTest::qWait(100); QCOMPARE(child1->pressCount, 1); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(50,50)); + QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(50,50)); QTest::qWait(50); - QVERIFY(window->mouseGrabberItem() == 0); + QVERIFY2(window.mouseGrabberItem() == 0, msgItem(window.mouseGrabberItem()).constData()); QCOMPARE(child1->releaseCount, 1); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(50,50)); + QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(50,50)); QTest::qWait(50); - QVERIFY(window->mouseGrabberItem() == child1); + QVERIFY2(window.mouseGrabberItem() == child1.data(), msgItem(window.mouseGrabberItem()).constData()); QCOMPARE(child1->pressCount, 2); child1->setEnabled(false); - QVERIFY(window->mouseGrabberItem() == 0); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(50,50)); + QVERIFY2(window.mouseGrabberItem() == 0, msgItem(window.mouseGrabberItem()).constData()); + QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(50,50)); QTest::qWait(50); QCOMPARE(child1->releaseCount, 1); child1->setEnabled(true); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(50,50)); + QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(50,50)); QTest::qWait(50); - QVERIFY(window->mouseGrabberItem() == child1); + QVERIFY2(window.mouseGrabberItem() == child1.data(), msgItem(window.mouseGrabberItem()).constData()); QCOMPARE(child1->pressCount, 3); child1->setVisible(false); - QVERIFY(window->mouseGrabberItem() == 0); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(50,50)); + QVERIFY2(window.mouseGrabberItem() == 0, msgItem(window.mouseGrabberItem())); + QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(50,50)); QCOMPARE(child1->releaseCount, 1); child1->setVisible(true); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(50,50)); + QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(50,50)); QTest::qWait(50); - QVERIFY(window->mouseGrabberItem() == child1); + QVERIFY2(window.mouseGrabberItem() == child1.data(), msgItem(window.mouseGrabberItem()).constData()); QCOMPARE(child1->pressCount, 4); child2->grabMouse(); - QVERIFY(window->mouseGrabberItem() == child2); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(50,50)); + QVERIFY2(window.mouseGrabberItem() == child2.data(), msgItem(window.mouseGrabberItem()).constData()); + QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(50,50)); QTest::qWait(50); QCOMPARE(child1->releaseCount, 1); QCOMPARE(child2->releaseCount, 1); child2->grabMouse(); - QVERIFY(window->mouseGrabberItem() == child2); - QTest::mousePress(window, Qt::LeftButton, 0, QPoint(50,50)); + QVERIFY2(window.mouseGrabberItem() == child2.data(), msgItem(window.mouseGrabberItem()).constData()); + QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(50,50)); QTest::qWait(50); QCOMPARE(child1->pressCount, 4); QCOMPARE(child2->pressCount, 1); - QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(50,50)); + QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(50,50)); QTest::qWait(50); QCOMPARE(child1->releaseCount, 1); QCOMPARE(child2->releaseCount, 2); - - delete child1; - delete child2; - delete window; } void tst_qquickitem::touchEventAcceptIgnore_data() @@ -1245,13 +1248,14 @@ void tst_qquickitem::touchEventAcceptIgnore() { QFETCH(bool, itemSupportsTouch); - TestWindow *window = new TestWindow; - window->resize(100, 100); - window->show(); + TestWindow window; + window.resize(100, 100); + window.show(); + QTest::qWaitForWindowExposed(&window); - TestItem *item = new TestItem; + QScopedPointer<TestItem> item(new TestItem); item->setSize(QSizeF(100, 100)); - item->setParentItem(window->contentItem()); + item->setParentItem(window.contentItem()); item->acceptIncomingTouchEvents = itemSupportsTouch; static QTouchDevice* device = 0; @@ -1277,7 +1281,7 @@ void tst_qquickitem::touchEventAcceptIgnore() item->touchEventReached = false; - bool accepted = window->event(&event); + bool accepted = window.event(&event); QVERIFY(item->touchEventReached); QCOMPARE(accepted && event.isAccepted(), itemSupportsTouch); @@ -1297,7 +1301,7 @@ void tst_qquickitem::touchEventAcceptIgnore() item->touchEventReached = false; - bool accepted = window->event(&event); + bool accepted = window.event(&event); QCOMPARE(item->touchEventReached, itemSupportsTouch); QCOMPARE(accepted && event.isAccepted(), itemSupportsTouch); @@ -1317,14 +1321,11 @@ void tst_qquickitem::touchEventAcceptIgnore() item->touchEventReached = false; - bool accepted = window->event(&event); + bool accepted = window.event(&event); QCOMPARE(item->touchEventReached, itemSupportsTouch); QCOMPARE(accepted && event.isAccepted(), itemSupportsTouch); } - - delete item; - delete window; } void tst_qquickitem::polishOutsideAnimation() @@ -1346,16 +1347,15 @@ void tst_qquickitem::polishOutsideAnimation() void tst_qquickitem::polishOnCompleted() { - QQuickView *view = new QQuickView; - view->setSource(testFileUrl("polishOnCompleted.qml")); - view->show(); + QQuickView view; + view.setSource(testFileUrl("polishOnCompleted.qml")); + view.show(); + QTest::qWaitForWindowExposed(&view); - TestPolishItem *item = qobject_cast<TestPolishItem*>(view->rootObject()); + TestPolishItem *item = qobject_cast<TestPolishItem*>(view.rootObject()); QVERIFY(item); QTRY_VERIFY(item->wasPolished); - - delete view; } void tst_qquickitem::wheelEvent_data() @@ -1376,20 +1376,21 @@ void tst_qquickitem::wheelEvent() const bool shouldReceiveWheelEvents = visible && enabled; - QQuickWindow *window = new QQuickWindow; - window->resize(200, 200); - window->show(); + QQuickWindow window; + window.resize(200, 200); + window.show(); + QTest::qWaitForWindowExposed(&window); TestItem *item = new TestItem; item->setSize(QSizeF(200, 100)); - item->setParentItem(window->contentItem()); + item->setParentItem(window.contentItem()); item->setEnabled(enabled); item->setVisible(visible); QWheelEvent event(QPoint(100, 50), -120, Qt::NoButton, Qt::NoModifier, Qt::Vertical); event.setAccepted(false); - QGuiApplication::sendEvent(window, &event); + QGuiApplication::sendEvent(&window, &event); if (shouldReceiveWheelEvents) { QVERIFY(event.isAccepted()); @@ -1398,8 +1399,6 @@ void tst_qquickitem::wheelEvent() QVERIFY(!event.isAccepted()); QCOMPARE(item->wheelCount, 0); } - - delete window; } class HoverItem : public QQuickItem @@ -1503,11 +1502,11 @@ void tst_qquickitem::hoverEvent() void tst_qquickitem::hoverEventInParent() { - QQuickWindow *window = new QQuickWindow(); - window->resize(200, 200); - window->show(); + QQuickWindow window; + window.resize(200, 200); + window.show(); - HoverItem *parentItem = new HoverItem(window->contentItem()); + HoverItem *parentItem = new HoverItem(window.contentItem()); parentItem->setSize(QSizeF(200, 200)); parentItem->setAcceptHoverEvents(true); @@ -1523,12 +1522,12 @@ void tst_qquickitem::hoverEventInParent() const QPoint insideLeft(50, 100); const QPoint insideRight(150, 100); - sendMouseMove(window, insideLeft); + sendMouseMove(&window, insideLeft); parentItem->resetCounters(); leftItem->resetCounters(); rightItem->resetCounters(); - sendMouseMove(window, insideRight); + sendMouseMove(&window, insideRight); QCOMPARE(parentItem->hoverEnterCount, 0); QCOMPARE(parentItem->hoverLeaveCount, 0); QCOMPARE(leftItem->hoverEnterCount, 0); @@ -1536,15 +1535,13 @@ void tst_qquickitem::hoverEventInParent() QCOMPARE(rightItem->hoverEnterCount, 1); QCOMPARE(rightItem->hoverLeaveCount, 0); - sendMouseMove(window, insideLeft); + sendMouseMove(&window, insideLeft); QCOMPARE(parentItem->hoverEnterCount, 0); QCOMPARE(parentItem->hoverLeaveCount, 0); QCOMPARE(leftItem->hoverEnterCount, 1); QCOMPARE(leftItem->hoverLeaveCount, 1); QCOMPARE(rightItem->hoverEnterCount, 1); QCOMPARE(rightItem->hoverLeaveCount, 1); - - delete window; } void tst_qquickitem::paintOrder_data() diff --git a/tests/auto/quick/qquicklistview/data/outsideViewportChangeNotAffectingView.qml b/tests/auto/quick/qquicklistview/data/outsideViewportChangeNotAffectingView.qml new file mode 100644 index 0000000000..7903c392d1 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/outsideViewportChangeNotAffectingView.qml @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.1 +import QtTest 1.0 + +Item { + function resizeThirdItem(size) { + resizingListModel.setProperty(3, "size", size) + } + + ListView { + width: 300 + height: 542 + model: ListModel { + id: resizingListModel + ListElement { size: 300; } + ListElement { size: 300; } + ListElement { size: 300; } + ListElement { size: 300; } + ListElement { size: 300; } + ListElement { size: 300; } + } + delegate: Rectangle { + width: parent.width + color: index % 2 == 0 ? "red" : "blue" + height: size + } + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index bec61eaccb..2268f0754c 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -209,6 +209,7 @@ private slots: void defaultHighlightMoveDuration(); void accessEmptyCurrentItem_QTBUG_30227(); void delayedChanges_QTBUG_30555(); + void outsideViewportChangeNotAffectingView(); private: template <class T> void items(const QUrl &source); @@ -6880,6 +6881,43 @@ void tst_QQuickListView::delayedChanges_QTBUG_30555() delete window; } +void tst_QQuickListView::outsideViewportChangeNotAffectingView() +{ + QQuickView *window = createView(); + window->setSource(testFileUrl("outsideViewportChangeNotAffectingView.qml")); + + QQuickListView *listview = window->rootObject()->findChild<QQuickListView*>(); + QTRY_VERIFY(listview != 0); + + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + flick(window, QPoint(20, 200), QPoint(20, 20), 10); + + QTRY_COMPARE(listview->isFlicking(), false); + + QTRY_COMPARE(listview->indexAt(0, listview->contentY()), 4); + QTRY_COMPARE(listview->itemAt(0, listview->contentY())->y(), 1200.); + + QMetaObject::invokeMethod(window->rootObject(), "resizeThirdItem", Q_ARG(QVariant, 290)); + QTRY_COMPARE(listview->indexAt(0, listview->contentY()), 4); + QTRY_COMPARE(listview->itemAt(0, listview->contentY())->y(), 1200.); + + QMetaObject::invokeMethod(window->rootObject(), "resizeThirdItem", Q_ARG(QVariant, 300)); + QTRY_COMPARE(listview->indexAt(0, listview->contentY()), 4); + QTRY_COMPARE(listview->itemAt(0, listview->contentY())->y(), 1200.); + + QMetaObject::invokeMethod(window->rootObject(), "resizeThirdItem", Q_ARG(QVariant, 310)); + QTRY_COMPARE(listview->indexAt(0, listview->contentY()), 4); + QTRY_COMPARE(listview->itemAt(0, listview->contentY())->y(), 1200.); + + QMetaObject::invokeMethod(window->rootObject(), "resizeThirdItem", Q_ARG(QVariant, 400)); + QTRY_COMPARE(listview->indexAt(0, listview->contentY()), 4); + QTRY_COMPARE(listview->itemAt(0, listview->contentY())->y(), 1200.); + + delete window; +} + QTEST_MAIN(tst_QQuickListView) #include "tst_qquicklistview.moc" diff --git a/tests/auto/quick/qquickpath/tst_qquickpath.cpp b/tests/auto/quick/qquickpath/tst_qquickpath.cpp index fa68442329..6ecc5cee50 100644 --- a/tests/auto/quick/qquickpath/tst_qquickpath.cpp +++ b/tests/auto/quick/qquickpath/tst_qquickpath.cpp @@ -128,7 +128,7 @@ void tst_QuickPath::catmullromCurve() pos = obj->pointAt(.75); QCOMPARE(pos.toPoint(), QPoint(51,105)); //fuzzy compare pos = obj->pointAt(1); - QCOMPARE(pos, QPointF(100,150)); + QCOMPARE(pos.toPoint(), QPoint(100,150)); } void tst_QuickPath::closedCatmullromCurve() @@ -227,7 +227,7 @@ void tst_QuickPath::line() QCOMPARE(p1.x(), p1.y()); QPointF p2 = path2->pointAt(t); - QCOMPARE(p1, p2); + QCOMPARE(p1.toPoint(), p2.toPoint()); } } diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index 274b93e81a..e4ad7b9c40 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -1725,6 +1725,14 @@ void tst_QQuickPathView::missingPercent() delete obj; } +static inline bool hasFraction(qreal o) +{ + const bool result = o != qFloor(o); + if (!result) + qDebug() << "o != qFloor(o)" << o; + return result; +} + void tst_QQuickPathView::cancelDrag() { QScopedPointer<QQuickView> window(createView()); @@ -1747,7 +1755,7 @@ void tst_QQuickPathView::cancelDrag() QTest::mouseMove(window.data(), QPoint(30, 100)); QTest::mouseMove(window.data(), QPoint(85, 100)); - QTRY_VERIFY(pathview->offset() != qFloor(pathview->offset())); + QTRY_VERIFY(hasFraction(pathview->offset())); QTRY_VERIFY(pathview->isMoving()); QVERIFY(pathview->isDragging()); QCOMPARE(draggingSpy.count(), 1); diff --git a/tests/auto/quick/qquicktext/data/hAlignImplicitWidth.qml b/tests/auto/quick/qquicktext/data/hAlignImplicitWidth.qml index 136e5d21a2..9c9318d3cc 100644 --- a/tests/auto/quick/qquicktext/data/hAlignImplicitWidth.qml +++ b/tests/auto/quick/qquicktext/data/hAlignImplicitWidth.qml @@ -6,7 +6,7 @@ Rectangle { Text { objectName: "textItem" - text: "AA\nBBBBB\nCCCCCCCCCCCCCCCC" + text: "AA\nBBBBBBB\nCCCCCCCCCCCCCCCC" anchors.centerIn: parent horizontalAlignment: Text.AlignLeft } diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index 32099ae187..6b93791545 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -854,9 +854,20 @@ int tst_qquicktext::numberOfNonWhitePixels(int fromX, int toX, const QImage &ima return pixels; } +static inline QByteArray msgNotGreaterThan(int n1, int n2) +{ + return QByteArray::number(n1) + QByteArrayLiteral(" is not greater than ") + QByteArray::number(n2); +} + +static inline QByteArray msgNotLessThan(int n1, int n2) +{ + return QByteArray::number(n1) + QByteArrayLiteral(" is not less than ") + QByteArray::number(n2); +} + void tst_qquicktext::hAlignImplicitWidth() { QQuickView view(testFileUrl("hAlignImplicitWidth.qml")); + view.setFlags(view.flags() | Qt::WindowStaysOnTopHint); // Prevent being obscured by other windows. view.show(); view.requestActivate(); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -864,34 +875,45 @@ void tst_qquicktext::hAlignImplicitWidth() QQuickText *text = view.rootObject()->findChild<QQuickText*>("textItem"); QVERIFY(text != 0); + // Try to check whether alignment works by checking the number of black + // pixels in the thirds of the grabbed image. + const int windowWidth = 200; + const int textWidth = qCeil(text->implicitWidth()); + QVERIFY2(textWidth < windowWidth, "System font too large."); + const int sectionWidth = textWidth / 3; + const int centeredSection1 = (windowWidth - textWidth) / 2; + const int centeredSection2 = centeredSection1 + sectionWidth; + const int centeredSection3 = centeredSection2 + sectionWidth; + const int centeredSection3End = centeredSection3 + sectionWidth; + { // Left Align QImage image = view.grabWindow(); - int left = numberOfNonWhitePixels(0, image.width() / 3, image); - int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image); - int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image); - QVERIFY(left > mid); - QVERIFY(mid > right); + const int left = numberOfNonWhitePixels(centeredSection1, centeredSection2, image); + const int mid = numberOfNonWhitePixels(centeredSection2, centeredSection3, image); + const int right = numberOfNonWhitePixels(centeredSection3, centeredSection3End, image); + QVERIFY2(left > mid, msgNotGreaterThan(left, mid).constData()); + QVERIFY2(mid > right, msgNotGreaterThan(mid, right).constData()); } { // HCenter Align text->setHAlign(QQuickText::AlignHCenter); QImage image = view.grabWindow(); - int left = numberOfNonWhitePixels(0, image.width() / 3, image); - int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image); - int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image); - QVERIFY(left < mid); - QVERIFY(mid > right); + const int left = numberOfNonWhitePixels(centeredSection1, centeredSection2, image); + const int mid = numberOfNonWhitePixels(centeredSection2, centeredSection3, image); + const int right = numberOfNonWhitePixels(centeredSection3, centeredSection3End, image); + QVERIFY2(left < mid, msgNotLessThan(left, mid).constData()); + QVERIFY2(mid > right, msgNotGreaterThan(mid, right).constData()); } { // Right Align text->setHAlign(QQuickText::AlignRight); QImage image = view.grabWindow(); - int left = numberOfNonWhitePixels(0, image.width() / 3, image); - int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image); - int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image); - QVERIFY(left < mid); - QVERIFY(mid < right); + const int left = numberOfNonWhitePixels(centeredSection1, centeredSection2, image); + const int mid = numberOfNonWhitePixels(centeredSection2, centeredSection3, image); + const int right = numberOfNonWhitePixels(centeredSection3, centeredSection3End, image); + QVERIFY2(left < mid, msgNotLessThan(left, mid).constData()); + QVERIFY2(mid < right, msgNotLessThan(mid, right).constData()); } } diff --git a/tests/auto/quick/qquicktextedit/data/hAlignVisual.qml b/tests/auto/quick/qquicktextedit/data/hAlignVisual.qml index 136e5d21a2..017bab97a7 100644 --- a/tests/auto/quick/qquicktextedit/data/hAlignVisual.qml +++ b/tests/auto/quick/qquicktextedit/data/hAlignVisual.qml @@ -6,8 +6,9 @@ Rectangle { Text { objectName: "textItem" - text: "AA\nBBBBB\nCCCCCCCCCCCCCCCC" + text: "AA\nBBBBBBB\nCCCCCCCCCCCCCCCC" anchors.centerIn: parent horizontalAlignment: Text.AlignLeft + font.pointSize: 12 } } diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index c14f191cb1..ac8fca1f9d 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -656,7 +656,7 @@ void tst_qquicktextedit::hAlign_RightToLeft() QQuickView window(testFileUrl("horizontalAlignment_RightToLeft.qml")); QQuickTextEdit *textEdit = window.rootObject()->findChild<QQuickTextEdit*>("text"); QVERIFY(textEdit != 0); - window.show(); + window.showNormal(); const QString rtlText = textEdit->text(); @@ -820,42 +820,66 @@ static int numberOfNonWhitePixels(int fromX, int toX, const QImage &image) return pixels; } +static inline QByteArray msgNotGreaterThan(int n1, int n2) +{ + return QByteArray::number(n1) + QByteArrayLiteral(" is not greater than ") + QByteArray::number(n2); +} + +static inline QByteArray msgNotLessThan(int n1, int n2) +{ + return QByteArray::number(n1) + QByteArrayLiteral(" is not less than ") + QByteArray::number(n2); +} + void tst_qquicktextedit::hAlignVisual() { QQuickView view(testFileUrl("hAlignVisual.qml")); - view.show(); + view.setFlags(view.flags() | Qt::WindowStaysOnTopHint); // Prevent being obscured by other windows. + view.showNormal(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QQuickText *text = view.rootObject()->findChild<QQuickText*>("textItem"); QVERIFY(text != 0); + + // Try to check whether alignment works by checking the number of black + // pixels in the thirds of the grabbed image. + const int windowWidth = 200; + const int textWidth = qCeil(text->implicitWidth()); + QVERIFY2(textWidth < windowWidth, "System font too large."); + const int sectionWidth = textWidth / 3; + const int centeredSection1 = (windowWidth - textWidth) / 2; + const int centeredSection2 = centeredSection1 + sectionWidth; + const int centeredSection3 = centeredSection2 + sectionWidth; + const int centeredSection3End = centeredSection3 + sectionWidth; + { // Left Align QImage image = view.grabWindow(); - int left = numberOfNonWhitePixels(0, image.width() / 3, image); - int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image); - int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image); - QVERIFY(left > mid); - QVERIFY(mid > right); + const int left = numberOfNonWhitePixels(centeredSection1, centeredSection2, image); + const int mid = numberOfNonWhitePixels(centeredSection2, centeredSection3, image); + const int right = numberOfNonWhitePixels(centeredSection3, centeredSection3End, image); + QVERIFY2(left > mid, msgNotGreaterThan(left, mid).constData()); + QVERIFY2(mid > right, msgNotGreaterThan(mid, right).constData()); } { // HCenter Align text->setHAlign(QQuickText::AlignHCenter); QImage image = view.grabWindow(); - int left = numberOfNonWhitePixels(0, image.width() / 3, image); - int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image); - int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image); - QVERIFY(left < mid); - QVERIFY(mid > right); + const int left = numberOfNonWhitePixels(centeredSection1, centeredSection2, image); + const int mid = numberOfNonWhitePixels(centeredSection2, centeredSection3, image); + const int right = numberOfNonWhitePixels(centeredSection3, centeredSection3End, image); + QVERIFY2(left < mid, msgNotLessThan(left, mid).constData()); + QVERIFY2(mid > right, msgNotGreaterThan(mid, right).constData()); } { // Right Align text->setHAlign(QQuickText::AlignRight); QImage image = view.grabWindow(); - int left = numberOfNonWhitePixels(0, image.width() / 3, image); - int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image); - int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image); - QVERIFY(left < mid); - QVERIFY(mid < right); + const int left = numberOfNonWhitePixels(centeredSection1, centeredSection2, image); + const int mid = numberOfNonWhitePixels(centeredSection2, centeredSection3, image); + const int right = numberOfNonWhitePixels(centeredSection3, centeredSection3End, image); + image.save("test3.png"); + QVERIFY2(left < mid, msgNotLessThan(left, mid).constData()); + QVERIFY2(mid < right, msgNotLessThan(mid, right).constData()); } text->setWidth(200); @@ -866,8 +890,8 @@ void tst_qquicktextedit::hAlignVisual() int x = qCeil(text->implicitWidth()); int left = numberOfNonWhitePixels(0, x, image); int right = numberOfNonWhitePixels(x, image.width() - x, image); - QVERIFY(left > 0); - QVERIFY(right == 0); + QVERIFY2(left > 0, msgNotGreaterThan(left, 0).constData()); + QCOMPARE(right, 0); } { // HCenter Align @@ -878,9 +902,9 @@ void tst_qquicktextedit::hAlignVisual() int left = numberOfNonWhitePixels(0, x1, image); int mid = numberOfNonWhitePixels(x1, x2 - x1, image); int right = numberOfNonWhitePixels(x2, image.width() - x2, image); - QVERIFY(left == 0); - QVERIFY(mid > 0); - QVERIFY(right == 0); + QCOMPARE(left, 0); + QVERIFY2(mid > 0, msgNotGreaterThan(left, 0).constData()); + QCOMPARE(right, 0); } { // Right Align @@ -889,8 +913,8 @@ void tst_qquicktextedit::hAlignVisual() int x = image.width() - qCeil(text->implicitWidth()); int left = numberOfNonWhitePixels(0, x, image); int right = numberOfNonWhitePixels(x, image.width() - x, image); - QVERIFY(left == 0); - QVERIFY(right > 0); + QCOMPARE(left, 0); + QVERIFY2(right > 0, msgNotGreaterThan(left, 0).constData()); } } @@ -1240,7 +1264,7 @@ void tst_qquicktextedit::focusOnPress() QQuickWindow window; window.resize(100, 50); textEditObject->setParentItem(window.contentItem()); - window.show(); + window.showNormal(); window.requestActivate(); QTest::qWaitForWindowActive(&window); @@ -2519,7 +2543,7 @@ void tst_qquicktextedit::remoteCursorDelegate() view.rootContext()->setContextProperty("contextDelegate", &component); view.setSource(testFileUrl("cursorTestRemote.qml")); - view.show(); + view.showNormal(); view.requestActivate(); QTest::qWaitForWindowActive(&view); QQuickTextEdit *textEditObject = view.rootObject()->findChild<QQuickTextEdit*>("textEditObject"); @@ -2533,10 +2557,6 @@ void tst_qquicktextedit::remoteCursorDelegate() textEditObject->setFocus(true); QVERIFY(textEditObject->isCursorVisible()); - QCOMPARE(component.status(), QQmlComponent::Loading); - QVERIFY(!textEditObject->findChild<QQuickItem*>("cursorInstance")); - server.sendDelayedItem(); - // Wait for component to load. QTRY_COMPARE(component.status(), QQmlComponent::Ready); QVERIFY(textEditObject->findChild<QQuickItem*>("cursorInstance")); @@ -3046,7 +3066,7 @@ void tst_qquicktextedit::openInputPanel() inputMethodPrivate->testContext = &platformInputContext; QQuickView view(testFileUrl("openInputPanel.qml")); - view.show(); + view.showNormal(); view.requestActivate(); QTest::qWaitForWindowActive(&view); diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 8c72be56a4..06b757d198 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -1573,7 +1573,7 @@ void tst_qquicktextinput::verticalAlignment() QQuickView window(testFileUrl("horizontalAlignment.qml")); QQuickTextInput *textInput = window.rootObject()->findChild<QQuickTextInput*>("text"); QVERIFY(textInput != 0); - window.show(); + window.showNormal(); QCOMPARE(textInput->vAlign(), QQuickTextInput::AlignTop); QVERIFY(textInput->boundingRect().bottom() < window.height() / 2); @@ -2775,7 +2775,6 @@ void tst_qquicktextinput::cursorDelegate() void tst_qquicktextinput::remoteCursorDelegate() { - QSKIP("This test is unstable"); TestHTTPServer server(SERVER_PORT); server.serveDirectory(dataDirectory(), TestHTTPServer::Delay); @@ -2799,10 +2798,6 @@ void tst_qquicktextinput::remoteCursorDelegate() textInputObject->setFocus(true); QVERIFY(textInputObject->isCursorVisible()); - QCOMPARE(component.status(), QQmlComponent::Loading); - QVERIFY(!textInputObject->findChild<QQuickItem*>("cursorInstance")); - server.sendDelayedItem(); - // Wait for component to load. QTRY_COMPARE(component.status(), QQmlComponent::Ready); QVERIFY(textInputObject->findChild<QQuickItem*>("cursorInstance")); @@ -3314,7 +3309,7 @@ void tst_qquicktextinput::focusOnPress() QQuickWindow window; window.resize(100, 50); textInputObject->setParentItem(window.contentItem()); - window.show(); + window.showNormal(); window.requestActivate(); QTest::qWaitForWindowActive(&window); @@ -3377,7 +3372,7 @@ void tst_qquicktextinput::openInputPanel() inputMethodPrivate->testContext = &platformInputContext; QQuickView view(testFileUrl("openInputPanel.qml")); - view.show(); + view.showNormal(); view.requestActivate(); QTest::qWaitForWindowActive(&view); @@ -3769,7 +3764,7 @@ void tst_qquicktextinput::inputContextMouseHandler() input->setFocus(true); input->setText(""); - view.show(); + view.showNormal(); view.requestActivate(); QTest::qWaitForWindowActive(&view); diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index e2bb6b431c..fbbc77c31c 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -1072,7 +1072,7 @@ void tst_qquickwindow::noUpdateWhenNothingChanges() QQuickRectangle rect(window.contentItem()); - window.show(); + window.showNormal(); QTRY_VERIFY(window.isExposed()); if (window.openglContext()->thread() == QGuiApplication::instance()->thread()) { diff --git a/tests/auto/quick/rendernode/tst_rendernode.cpp b/tests/auto/quick/rendernode/tst_rendernode.cpp index 509b209654..04b32499ff 100644 --- a/tests/auto/quick/rendernode/tst_rendernode.cpp +++ b/tests/auto/quick/rendernode/tst_rendernode.cpp @@ -59,7 +59,7 @@ public: QQuickView view; view.setSource(testFileUrl(fileName)); - view.show(); + view.showNormal(); QTest::qWaitForWindowExposed(&view); return view.grabWindow(); diff --git a/tests/auto/quick/touchmouse/touchmouse.pro b/tests/auto/quick/touchmouse/touchmouse.pro index 378e199bf5..af6d536cbc 100644 --- a/tests/auto/quick/touchmouse/touchmouse.pro +++ b/tests/auto/quick/touchmouse/touchmouse.pro @@ -14,5 +14,3 @@ TESTDATA = data/* # OTHER_FILES += data/foo.qml DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 - -mac:CONFIG+=insignificant_test # QTBUG-27890 |