diff options
Diffstat (limited to 'tests/auto')
11 files changed, 203 insertions, 29 deletions
diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index 9cae582143..7e04fa5957 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -112,9 +112,11 @@ void tst_QFileSystemWatcher::basicTest_data() + QChar(ushort(0x00DC)) // LATIN_CAPITAL_LETTER_U_WITH_DIAERESIS + QStringLiteral(".txt"); +#if !defined(Q_OS_QNX) || !defined(QT_NO_INOTIFY) QTest::newRow("native backend-testfile") << "native" << testFile; - QTest::newRow("poller backend-testfile") << "poller" << testFile; QTest::newRow("native backend-specialchars") << "native" << specialCharacterFile; +#endif + QTest::newRow("poller backend-testfile") << "poller" << testFile; } void tst_QFileSystemWatcher::basicTest() diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 501ad6f415..2c9868cd10 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -166,6 +166,7 @@ private slots: void testByteArray_data(); void testByteArray(); + void iniCodec(); private: const bool m_canWriteNativeSystemSettings; @@ -695,6 +696,28 @@ void tst_QSettings::testByteArray() } } +void tst_QSettings::iniCodec() +{ + { + QSettings settings("QtProject", "tst_qsettings"); + settings.setIniCodec("cp1251"); + QByteArray ba; + ba.resize(256); + for (int i = 0; i < ba.size(); i++) + ba[i] = i; + settings.setValue("array",ba); + } + { + QSettings settings("QtProject", "tst_qsettings"); + settings.setIniCodec("cp1251"); + QByteArray ba = settings.value("array").toByteArray(); + QCOMPARE(ba.size(), 256); + for (int i = 0; i < ba.size(); i++) + QCOMPARE((uchar)ba.at(i), (uchar)i); + } + +} + void tst_QSettings::testErrorHandling_data() { QTest::addColumn<int>("filePerms"); // -1 means file should not exist diff --git a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp index c385a02b9c..f36bbbc5b6 100644 --- a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp @@ -71,6 +71,7 @@ private slots: void submit_data(); void submit(); void testRoleNames(); + void testSwappingRowsProxy(); }; // Subclass that exposes the protected functions. @@ -397,6 +398,103 @@ void tst_QAbstractProxyModel::testRoleNames() QVERIFY( proxy2RoleNames.value(StandardItemModelWithCustomRoleNames::CustomRole2) == "custom2" ); } +// This class only supports very simple table models +class SwappingProxy : public QAbstractProxyModel +{ + static int swapRow(const int row) + { + if (row == 2) { + return 3; + } else if (row == 3) { + return 2; + } else { + return row; + } + } +public: + virtual QModelIndex index(int row, int column, const QModelIndex &parentIdx) const + { + if (!sourceModel()) + return QModelIndex(); + if (row < 0 || column < 0) + return QModelIndex(); + if (row >= sourceModel()->rowCount()) + return QModelIndex(); + if (column >= sourceModel()->columnCount()) + return QModelIndex(); + return createIndex(row, column, parentIdx.internalPointer()); + } + + virtual QModelIndex parent(const QModelIndex &parentIdx) const + { + // well, we're a 2D model + Q_UNUSED(parentIdx); + return QModelIndex(); + } + + virtual int rowCount(const QModelIndex &parentIdx) const + { + if (parentIdx.isValid() || !sourceModel()) + return 0; + return sourceModel()->rowCount(); + } + + virtual int columnCount(const QModelIndex &parentIdx) const + { + if (parentIdx.isValid() || !sourceModel()) + return 0; + return sourceModel()->rowCount(); + } + + virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const + { + if (!proxyIndex.isValid()) + return QModelIndex(); + if (!sourceModel()) + return QModelIndex(); + Q_ASSERT(!proxyIndex.parent().isValid()); + return sourceModel()->index(swapRow(proxyIndex.row()), proxyIndex.column(), QModelIndex()); + } + + virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const + { + if (!sourceIndex.isValid()) + return QModelIndex(); + if (!sourceModel()) + return QModelIndex(); + Q_ASSERT(!sourceIndex.parent().isValid()); + return index(swapRow(sourceIndex.row()), sourceIndex.column(), QModelIndex()); + } +}; + +void tst_QAbstractProxyModel::testSwappingRowsProxy() +{ + QStandardItemModel defaultModel; + defaultModel.setRowCount(4); + defaultModel.setColumnCount(2); + for (int row = 0; row < defaultModel.rowCount(); ++row) { + defaultModel.setItem(row, 0, new QStandardItem(QString::number(row) + QLatin1Char('A'))); + defaultModel.setItem(row, 1, new QStandardItem(QString::number(row) + QLatin1Char('B'))); + } + SwappingProxy proxy; + proxy.setSourceModel(&defaultModel); + QCOMPARE(proxy.data(proxy.index(0, 0, QModelIndex())), QVariant("0A")); + QCOMPARE(proxy.data(proxy.index(0, 1, QModelIndex())), QVariant("0B")); + QCOMPARE(proxy.data(proxy.index(1, 0, QModelIndex())), QVariant("1A")); + QCOMPARE(proxy.data(proxy.index(1, 1, QModelIndex())), QVariant("1B")); + QCOMPARE(proxy.data(proxy.index(2, 0, QModelIndex())), QVariant("3A")); + QCOMPARE(proxy.data(proxy.index(2, 1, QModelIndex())), QVariant("3B")); + QCOMPARE(proxy.data(proxy.index(3, 0, QModelIndex())), QVariant("2A")); + QCOMPARE(proxy.data(proxy.index(3, 1, QModelIndex())), QVariant("2B")); + + for (int row = 0; row < defaultModel.rowCount(); ++row) { + QModelIndex left = proxy.index(row, 0, QModelIndex()); + QModelIndex right = proxy.index(row, 1, QModelIndex()); + QCOMPARE(left.sibling(left.row(), 1), right); + QCOMPARE(right.sibling(right.row(), 0), left); + } +} + QTEST_MAIN(tst_QAbstractProxyModel) #include "tst_qabstractproxymodel.moc" diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 589f3e66e1..868288e36e 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -92,6 +92,7 @@ private slots: void modalDialogClosingOneOfTwoModal(); void modalWithChildWindow(); void modalWindowModallity(); + void modalWindowPosition(); void initTestCase() { @@ -1429,6 +1430,18 @@ void tst_QWindow::modalWindowModallity() } +void tst_QWindow::modalWindowPosition() +{ + QWindow window; + window.setGeometry(QRect(100, 100, 400, 400)); + // Allow for any potential resizing due to constraints + QRect origGeo = window.geometry(); + window.setModality(Qt::WindowModal); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QCOMPARE(window.geometry(), origGeo); +} + #include <tst_qwindow.moc> QTEST_MAIN(tst_QWindow) diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp index 2c45b7d2ec..a4e1490b01 100644 --- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp +++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp @@ -951,6 +951,11 @@ void tst_QRawFont::rawFontFromInvalidData() font.loadFromData(invalidData, 10, QFont::PreferDefaultHinting); QVERIFY(!font.isValid()); + + invalidData.fill(255, 1024); + font.loadFromData(invalidData, 10, QFont::PreferDefaultHinting); + + QVERIFY(!font.isValid()); } #endif // QT_NO_RAWFONT diff --git a/tests/auto/widgets/dialogs/qfiledialog2/qfiledialog2.pro b/tests/auto/widgets/dialogs/qfiledialog2/qfiledialog2.pro index db36eea11d..5239614fc7 100644 --- a/tests/auto/widgets/dialogs/qfiledialog2/qfiledialog2.pro +++ b/tests/auto/widgets/dialogs/qfiledialog2/qfiledialog2.pro @@ -19,3 +19,5 @@ wince* { } else { DEFINES += SRCDIR=\\\"$$PWD/\\\" } + +macx:CONFIG += insignificant_test # QTBUG-39183 diff --git a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp index 0425db3098..f9abd50a15 100644 --- a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp @@ -593,6 +593,11 @@ void tst_QMessageBox::detailsText() QString text("This is the details text."); box.setDetailedText(text); QCOMPARE(box.detailedText(), text); + box.show(); + QTest::qWaitForWindowExposed(&box); + // QTBUG-39334, the box should now have the default "Ok" button as well as + // the "Show Details.." button. + QCOMPARE(box.findChildren<QAbstractButton *>().size(), 2); } void tst_QMessageBox::detailsButtonText() diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index f686b5854c..c89b05616d 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 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. @@ -49,6 +49,7 @@ #include <QAbstractTextDocumentLayout> #include <QBitmap> #include <QCursor> +#include <QScreen> #include <QLabel> #include <QDial> #include <QGraphicsItem> @@ -141,6 +142,17 @@ static void sendKeyClick(QGraphicsScene *scene, Qt::Key key) sendKeyRelease(scene, key); } +static inline void centerOnScreen(QWidget *w, const QSize &size) +{ + const QPoint offset = QPoint(size.width() / 2, size.height() / 2); + w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset); +} + +static inline void centerOnScreen(QWidget *w) +{ + centerOnScreen(w, w->geometry().size()); +} + class EventSpy : public QGraphicsWidget { Q_OBJECT @@ -4213,14 +4225,18 @@ void tst_QGraphicsItem::cursor() item2->setCursor(Qt::PointingHandCursor); QWidget topLevel; + topLevel.resize(250, 150); + centerOnScreen(&topLevel); QGraphicsView view(&scene,&topLevel); view.setFixedSize(200, 100); topLevel.show(); + QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); + QTest::mouseMove(&view, view.rect().center()); QTest::qWait(25); - QCursor cursor = view.viewport()->cursor(); + const Qt::CursorShape viewportShape = view.viewport()->cursor().shape(); { QTest::mouseMove(view.viewport(), QPoint(100, 50)); @@ -4228,9 +4244,7 @@ void tst_QGraphicsItem::cursor() QApplication::sendEvent(view.viewport(), &event); } - QTest::qWait(25); - - QCOMPARE(view.viewport()->cursor().shape(), cursor.shape()); + QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); { QTest::mouseMove(view.viewport(), view.mapFromScene(item1->sceneBoundingRect().center())); @@ -4238,7 +4252,7 @@ void tst_QGraphicsItem::cursor() QApplication::sendEvent(view.viewport(), &event); } - QCOMPARE(view.viewport()->cursor().shape(), item1->cursor().shape()); + QTRY_COMPARE(view.viewport()->cursor().shape(), item1->cursor().shape()); { QTest::mouseMove(view.viewport(), view.mapFromScene(item2->sceneBoundingRect().center())); @@ -4246,9 +4260,7 @@ void tst_QGraphicsItem::cursor() QApplication::sendEvent(view.viewport(), &event); } - QTest::qWait(25); - - QCOMPARE(view.viewport()->cursor().shape(), item2->cursor().shape()); + QTRY_COMPARE(view.viewport()->cursor().shape(), item2->cursor().shape()); { QTest::mouseMove(view.viewport(), view.rect().center()); @@ -4256,9 +4268,7 @@ void tst_QGraphicsItem::cursor() QApplication::sendEvent(view.viewport(), &event); } - QTest::qWait(25); - - QCOMPARE(view.viewport()->cursor().shape(), cursor.shape()); + QTRY_COMPARE(view.viewport()->cursor().shape(), viewportShape); } #endif /* diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 2a70431223..34936fa5b8 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -288,6 +288,7 @@ private slots: #ifndef Q_OS_MAC void scroll(); + void scrollNativeChildren(); #endif // tests QWidget::setGeometry() @@ -4336,7 +4337,30 @@ void tst_QWidget::scroll() QTRY_COMPARE(updateWidget.paintedRegion, dirty); } } -#endif + +// QTBUG-38999, scrolling a widget with native child widgets should move the children. +void tst_QWidget::scrollNativeChildren() +{ + QWidget parent; + parent.setWindowTitle(QLatin1String(__FUNCTION__)); + parent.resize(400, 400); + centerOnScreen(&parent); + QLabel *nativeLabel = new QLabel(QStringLiteral("nativeLabel"), &parent); + const QPoint oldLabelPos(100, 100); + nativeLabel->move(oldLabelPos); + QVERIFY(nativeLabel->winId()); + parent.show(); + QVERIFY(QTest::qWaitForWindowExposed(&parent)); + const QPoint delta(50, 50); + parent.scroll(delta.x(), delta.y()); + const QPoint newLabelPos = oldLabelPos + delta; + QWindow *labelWindow = nativeLabel->windowHandle(); + QVERIFY(labelWindow); + QTRY_COMPARE(labelWindow->geometry().topLeft(), newLabelPos); + QTRY_COMPARE(nativeLabel->geometry().topLeft(), newLabelPos); +} + +#endif // Mac OS class DestroyedSlotChecker : public QObject { diff --git a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp index d02b86bd8a..7e0b0dac0c 100644 --- a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp +++ b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp @@ -1726,9 +1726,8 @@ void tst_QMainWindow::addToolbarAfterShow() QToolBar toolBar; mainWindow.addToolBar(&toolBar); - QTest::qWait(100); - QVERIFY(!toolBar.isHidden()); + QTRY_VERIFY(!toolBar.isHidden()); } void tst_QMainWindow::centralWidgetSize() @@ -1743,8 +1742,7 @@ void tst_QMainWindow::centralWidgetSize() mainWindow.setCentralWidget(&widget); mainWindow.show(); - QTest::qWait(100); - QCOMPARE(widget.size(), widget.sizeHint()); + QTRY_COMPARE(widget.size(), widget.sizeHint()); } void tst_QMainWindow::dockWidgetSize() @@ -1789,19 +1787,15 @@ void tst_QMainWindow::QTBUG2774_stylechange() { - QTest::qWait(1000); mw.setStyleSheet("QMainWindow::separator { width: 50px; height:50px; }"); - QTest::qWait(5000); - QApplication::processEvents(); - QVERIFY(central->width() < centralOriginalWidth); + QTRY_VERIFY(central->width() < centralOriginalWidth); QVERIFY( mw.isSeparator(QPoint(4, dockw->pos().y() + dockw->size().height()))); QVERIFY( mw.isSeparator(QPoint(4, dockw->pos().y() + dockw->size().height() + 49))); } { mw.setStyleSheet("QMainWindow::separator { width: 0px; height: 0px; }"); - QApplication::processEvents(); - QVERIFY(central->width() > centralOriginalWidth); + QTRY_VERIFY(central->width() > centralOriginalWidth); QVERIFY(!mw.isSeparator(QPoint(4, dockw->pos().y() + dockw->size().height()))); QVERIFY(!mw.isSeparator(QPoint(4, dockw->pos().y() + dockw->size().height() + 1))); } diff --git a/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp b/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp index a301d51c4c..8dd191e621 100644 --- a/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp +++ b/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp @@ -127,9 +127,7 @@ void tst_QStatusBar::tempMessage() QCOMPARE(testWidget->currentMessage(), QString("Ready")); QCOMPARE(testWidget->currentMessage(), currentMessage); - QTest::qWait(1000); - - QVERIFY(testWidget->currentMessage().isNull()); + QTRY_VERIFY(testWidget->currentMessage().isNull()); QVERIFY(currentMessage.isNull()); testWidget->showMessage("Ready again", 500); @@ -294,10 +292,10 @@ void tst_QStatusBar::QTBUG25492_msgtimeout() QCOMPARE(testWidget->currentMessage(), QString("Ready")); QCOMPARE(testWidget->currentMessage(), currentMessage); - QTest::qWait(3000); + QTest::qWait(1500); // Message disappears after 2 seconds - QVERIFY(testWidget->currentMessage().isNull()); + QTRY_VERIFY(testWidget->currentMessage().isNull()); QVERIFY(currentMessage.isNull()); // Set display message for 2 seconds first |