diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2019-04-16 16:32:08 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2019-04-16 16:32:08 +0200 |
commit | 6630937e63ae5797487b86743a7733c8ae5cc42c (patch) | |
tree | 3d53dacf6430f9099e1fb20835881205de674961 /tests/auto/widgets/kernel | |
parent | 37ed6dae00640f9cc980ffda05347c12a7eb5d7e (diff) | |
parent | c7af193d2e49e9f10b86262e63d8d13abf72b5cf (diff) |
Merge commit 'dev' into 'wip/cmake-merge'
Change-Id: I176c40d031be26a1dd1cf08843e448a660598783
Diffstat (limited to 'tests/auto/widgets/kernel')
9 files changed, 221 insertions, 23 deletions
diff --git a/tests/auto/widgets/kernel/kernel.pro b/tests/auto/widgets/kernel/kernel.pro index 0382264eb8..15fcf99765 100644 --- a/tests/auto/widgets/kernel/kernel.pro +++ b/tests/auto/widgets/kernel/kernel.pro @@ -22,5 +22,3 @@ SUBDIRS=\ darwin:SUBDIRS -= \ qgesturerecognizer \ - -SUBDIRS -= qsound diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index d06baed322..e57ac77c39 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -360,8 +360,8 @@ void tst_QApplication::setFont_data() int cnt = 0; QFontDatabase fdb; QStringList families = fdb.families(); - for (QStringList::const_iterator itr = families.begin(); - itr != families.end(); + for (QStringList::const_iterator itr = families.cbegin(); + itr != families.cend(); ++itr) { if (cnt < 3) { QString family = *itr; @@ -2200,8 +2200,6 @@ void tst_QApplication::abortQuitOnShow() void tst_QApplication::staticFunctions() { QApplication::setStyle(QStringLiteral("blub")); - QApplication::colorSpec(); - QApplication::setColorSpec(42); QApplication::allWidgets(); QApplication::topLevelWidgets(); QApplication::desktop(); diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp index b2650d1f32..fa9769a002 100644 --- a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp +++ b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp @@ -47,6 +47,7 @@ private slots: void sizeConstraints(); void setGeometry(); void setStyleShouldChangeSpacing(); + void widgetSurplus(); void testLayoutEngine_data(); void testLayoutEngine(); @@ -236,6 +237,69 @@ void tst_QBoxLayout::setStyleShouldChangeSpacing() QTRY_COMPARE(spacing(), 10); } +class MarginEatingStyle : public QProxyStyle +{ +public: + MarginEatingStyle() : QProxyStyle(QStyleFactory::create("windows")) + { + } + + virtual QRect subElementRect(SubElement sr, const QStyleOption *opt, + const QWidget *widget) const + { + QRect rect = opt->rect; + switch (sr) { + case SE_GroupBoxLayoutItem: + // this is a simplifed version of what the macOS style does + rect.setTop(rect.top() + 20); + rect.setLeft(rect.left() + 20); + rect.setRight(rect.right() - 20); + rect.setBottom(rect.bottom() - 20); + break; + default: + return QProxyStyle::subElementRect(sr, opt, widget); + } + + return rect; + } +}; + +void tst_QBoxLayout::widgetSurplus() +{ + // Test case for QTBUG-67608 - a style requests space in the margin + + QDialog window; + QScopedPointer<MarginEatingStyle> marginEater(new MarginEatingStyle); + QVBoxLayout *vbox = new QVBoxLayout(&window); + vbox->setMargin(0); + vbox->setSpacing(0); + + QLabel *hiddenLabel = new QLabel(tr("Invisible label")); + hiddenLabel->setVisible(false); + + QGroupBox *groupBox = new QGroupBox(tr("Groupbox Title")); + groupBox->setStyle(marginEater.data()); + groupBox->setObjectName("Test group box"); + QPushButton *button1 = new QPushButton(tr("Button 1")); + QPushButton *button2 = new QPushButton(tr("Button 2")); + QVBoxLayout *groupLayout = new QVBoxLayout; + groupLayout->addWidget(button1); + groupLayout->addWidget(button2); + groupBox->setLayout(groupLayout); + + QLabel *label = new QLabel(tr("Visible label")); + + vbox->addWidget(hiddenLabel); + vbox->addWidget(groupBox); + vbox->addWidget(label); + window.setLayout(vbox); + + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QCOMPARE(groupBox->y(), 0); + QCOMPARE(groupBox->x(), 0); +} + void tst_QBoxLayout::taskQTBUG_7103_minMaxWidthNotRespected() { QLabel *label = new QLabel("Qt uses standard C++, but makes extensive use of the C pre-processor to enrich the language. Qt can also be used in several other programming languages via language bindings. It runs on all major platforms, and has extensive internationalization support. Non-GUI features include SQL database access, XML parsing, thread management, network support and a unified cross-platform API for file handling."); diff --git a/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp b/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp index 6f2847974f..90776dfcb2 100644 --- a/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp +++ b/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp @@ -32,6 +32,9 @@ #include <QtGui/QWindow> #include <QDebug> +// the complete class is deprecated +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED class tst_QDesktopWidget : public QObject { Q_OBJECT @@ -163,7 +166,7 @@ void tst_QDesktopWidget::topLevels() QCOMPARE(topLevelDesktopWidgets, 0); QCOMPARE(topLevelDesktopWindows, 0); } +QT_WARNING_POP QTEST_MAIN(tst_QDesktopWidget) #include "tst_qdesktopwidget.moc" - diff --git a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp index cff3dad35e..ab32643061 100644 --- a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp +++ b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp @@ -52,7 +52,7 @@ using namespace QTestPrivate; Q_CONSTEXPR QFormLayout::ItemRole invalidRole = QFormLayout::ItemRole(3); struct QFormLayoutTakeRowResultHolder { - QFormLayoutTakeRowResultHolder(QFormLayout::TakeRowResult result) Q_DECL_NOTHROW + QFormLayoutTakeRowResultHolder(QFormLayout::TakeRowResult result) noexcept : labelItem(result.labelItem), fieldItem(result.fieldItem) { @@ -66,20 +66,20 @@ struct QFormLayoutTakeRowResultHolder { if (fieldItem) disposer.setItem(0, QFormLayout::FieldRole, fieldItem); } - QFormLayoutTakeRowResultHolder(QFormLayoutTakeRowResultHolder &&other) Q_DECL_NOTHROW + QFormLayoutTakeRowResultHolder(QFormLayoutTakeRowResultHolder &&other) noexcept : labelItem(other.labelItem), fieldItem(other.fieldItem) { other.labelItem = nullptr; other.fieldItem = nullptr; } - QFormLayoutTakeRowResultHolder &operator=(QFormLayoutTakeRowResultHolder &&other) Q_DECL_NOTHROW + QFormLayoutTakeRowResultHolder &operator=(QFormLayoutTakeRowResultHolder &&other) noexcept { swap(other); return *this; } - void swap(QFormLayoutTakeRowResultHolder &other) Q_DECL_NOTHROW + void swap(QFormLayoutTakeRowResultHolder &other) noexcept { qSwap(labelItem, other.labelItem); qSwap(fieldItem, other.fieldItem); diff --git a/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp b/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp index e02573f8e8..3d609d0b9c 100644 --- a/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp +++ b/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp @@ -46,6 +46,7 @@ private slots: void whatsThis(); void setPalette(); void qtbug64550_stylesheet(); + void dontCrashOutsideScreenGeometry(); }; void tst_QToolTip::init() @@ -218,5 +219,11 @@ void tst_QToolTip::qtbug64550_stylesheet() msgSizeTooSmall(toolTipSize, boundingRect.size()).constData()); } +void tst_QToolTip::dontCrashOutsideScreenGeometry() { + QToolTip::showText(QPoint(-10000, -10000), "tip outside monitor", nullptr); + QTRY_VERIFY(QToolTip::isVisible()); + QToolTip::hideText(); +} + QTEST_MAIN(tst_QToolTip) #include "tst_qtooltip.moc" diff --git a/tests/auto/widgets/kernel/qwidget/BLACKLIST b/tests/auto/widgets/kernel/qwidget/BLACKLIST index d8654e5768..3287d67875 100644 --- a/tests/auto/widgets/kernel/qwidget/BLACKLIST +++ b/tests/auto/widgets/kernel/qwidget/BLACKLIST @@ -10,6 +10,7 @@ osx ubuntu-16.04 ubuntu-18.04 rhel-7.4 +rhel-7.6 osx [focusProxyAndInputMethods] linux @@ -32,7 +33,6 @@ osx [render_systemClip] osx [showMinimizedKeepsFocus] -osx-10.11 ci osx-10.12 ci osx-10.13 ci [maskedUpdate] diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 67b326e7ee..0ac8ccdbe7 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -166,6 +166,7 @@ private slots: void getSetCheck(); void fontPropagation(); void fontPropagation2(); + void fontPropagation3(); void palettePropagation(); void palettePropagation2(); void enabledPropagation(); @@ -320,7 +321,9 @@ private slots: void setMaskInResizeEvent(); void moveInResizeEvent(); - void immediateRepaintAfterInvalidateBuffer(); +#ifdef QT_BUILD_INTERNAL + void immediateRepaintAfterInvalidateBackingStore(); +#endif void effectiveWinId(); void effectiveWinId2(); @@ -819,6 +822,18 @@ void tst_QWidget::fontPropagation2() QVERIFY(child5->font().italic()); } +void tst_QWidget::fontPropagation3() +{ + QWidget parent; + QWidget *child = new QWidget(&parent); + parent.setFont(QFont("Monospace", 9)); + QImage image(32, 32, QImage::Format_RGB32); + QPainter p(&image); + p.setFont(child->font()); + QCOMPARE(p.font().family(), child->font().family()); + QCOMPARE(p.font().pointSize(), child->font().pointSize()); +} + void tst_QWidget::palettePropagation() { QScopedPointer<QWidget> testWidget(new QWidget); @@ -6131,7 +6146,11 @@ public: return false; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + bool nativeEvent(const QByteArray &eventType, void *message, qintptr *) override +#else bool nativeEvent(const QByteArray &eventType, void *message, long *) override +#endif { if (isMapNotify(eventType, message)) gotExpectedMapNotify = true; @@ -6139,7 +6158,11 @@ public: } // QAbstractNativeEventFilter interface +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) override +#else bool nativeEventFilter(const QByteArray &eventType, void *message, long *) override +#endif { if (isMapNotify(eventType, message)) gotExpectedGlobalEvent = true; @@ -8202,7 +8225,7 @@ void tst_QWidget::resizeInPaintEvent() widget.resizeInPaintEvent = true; // This will call resize in the paintEvent, which in turn will call - // invalidateBuffer() and a new update request should be posted. + // invalidateBackingStore() and a new update request should be posted. widget.repaint(); QCOMPARE(widget.numPaintEvents, 1); widget.numPaintEvents = 0; @@ -8357,7 +8380,8 @@ void tst_QWidget::moveInResizeEvent() QTRY_COMPARE(testWidget.geometry(), expectedGeometry); } -void tst_QWidget::immediateRepaintAfterInvalidateBuffer() +#ifdef QT_BUILD_INTERNAL +void tst_QWidget::immediateRepaintAfterInvalidateBackingStore() { if (m_platform != QStringLiteral("xcb") && m_platform != QStringLiteral("windows")) QSKIP("We don't support immediate repaint right after show on other platforms."); @@ -8371,7 +8395,7 @@ void tst_QWidget::immediateRepaintAfterInvalidateBuffer() // Marks the area covered by the widget as dirty in the backing store and // posts an UpdateRequest event. - qt_widget_private(widget.data())->invalidateBuffer(widget->rect()); + qt_widget_private(widget.data())->invalidateBackingStore(widget->rect()); QCOMPARE(widget->numPaintEvents, 0); // The entire widget is already dirty, but this time we want to update immediately @@ -8380,6 +8404,7 @@ void tst_QWidget::immediateRepaintAfterInvalidateBuffer() widget->repaint(); QCOMPARE(widget->numPaintEvents, 1); } +#endif void tst_QWidget::effectiveWinId() { @@ -9422,7 +9447,7 @@ QWidgetBackingStore* backingStore(QWidget &widget) void tst_QWidget::rectOutsideCoordinatesLimit_task144779() { #ifndef QT_NO_CURSOR - QApplication::setOverrideCursor(Qt::BlankCursor); //keep the cursor out of screen grabs + QGuiApplication::setOverrideCursor(Qt::BlankCursor); //keep the cursor out of screen grabs #endif QWidget main(0,Qt::FramelessWindowHint); //don't get confused by the size of the window frame QPalette palette; @@ -9459,7 +9484,7 @@ void tst_QWidget::rectOutsideCoordinatesLimit_task144779() QTRY_COMPARE(mainPixmap.toImage().convertToFormat(QImage::Format_RGB32), correct.toImage().convertToFormat(QImage::Format_RGB32)); #ifndef QT_NO_CURSOR - QApplication::restoreOverrideCursor(); + QGuiApplication::restoreOverrideCursor(); #endif } @@ -9615,7 +9640,7 @@ public: { if (!static_cast<QWidgetPrivate*>(d_ptr.data())->maybeBackingStore()) { static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStoreTracker.create(this); - static_cast<QWidgetPrivate*>(d_ptr.data())->invalidateBuffer(this->rect()); + static_cast<QWidgetPrivate*>(d_ptr.data())->invalidateBackingStore(this->rect()); repaint(); } } diff --git a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp index f4da4c3e5f..8b558aa56f 100644 --- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp +++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp @@ -46,6 +46,9 @@ #include <private/qwindow_p.h> #include <private/qguiapplication_p.h> #include <qpa/qplatformintegration.h> +#include <qpa/qwindowsysteminterface.h> +#include <qpa/qplatformdrag.h> +#include <private/qhighdpiscaling_p.h> #include <QtTest/private/qtesthelpers_p.h> @@ -87,6 +90,7 @@ private slots: #if QT_CONFIG(draganddrop) void tst_dnd(); void tst_dnd_events(); + void tst_dnd_propagation(); #endif void tst_qtbug35600(); @@ -470,6 +474,10 @@ static const char *expectedLogC[] = { "Event at 11,241 accepted", "acceptingDropsWidget2::dropEvent at 1,51 action=1 MIME_DATA_ADDRESS 'testmimetext'", "Event at 11,261 accepted", + "acceptingDropsWidget3::dragEnterEvent at 1,21 action=1 MIME_DATA_ADDRESS 'testmimetext'", + "Event at 11,281 accepted", + "acceptingDropsWidget3::dragLeaveEvent QDragLeaveEvent", + "Event at 11,301 ignored", "acceptingDropsWidget1::dragEnterEvent at 10,10 action=1 MIME_DATA_ADDRESS 'testmimetext'", "Event at 0,0 accepted", "acceptingDropsWidget1::dragMoveEvent at 11,11 action=1 MIME_DATA_ADDRESS 'testmimetext'", @@ -482,8 +490,9 @@ static const char *expectedLogC[] = { class DnDEventLoggerWidget : public QWidget { public: - DnDEventLoggerWidget(QStringList *log, QWidget *w = 0) : QWidget(w), m_log(log) {} - + DnDEventLoggerWidget(QStringList *log, QWidget *w = nullptr, bool ignoreDragMove = false) + : QWidget(w), m_log(log), m_ignoreDragMove(ignoreDragMove) + {} protected: void dragEnterEvent(QDragEnterEvent *); void dragMoveEvent(QDragMoveEvent *); @@ -493,6 +502,7 @@ protected: private: void formatDropEvent(const char *function, const QDropEvent *e, QTextStream &str) const; QStringList *m_log; + bool m_ignoreDragMove; }; void DnDEventLoggerWidget::formatDropEvent(const char *function, const QDropEvent *e, QTextStream &str) const @@ -513,6 +523,8 @@ void DnDEventLoggerWidget::dragEnterEvent(QDragEnterEvent *e) void DnDEventLoggerWidget::dragMoveEvent(QDragMoveEvent *e) { + if (m_ignoreDragMove) + return; e->accept(); QString message; QTextStream str(&message); @@ -580,7 +592,17 @@ void tst_QWidget_window::tst_dnd() dropsRefusingWidget2->resize(160, 60); dropsRefusingWidget2->move(10, 10); + QWidget *dropsAcceptingWidget3 = new DnDEventLoggerWidget(&log, &dndTestWidget, true); + dropsAcceptingWidget3->setAcceptDrops(true); + dropsAcceptingWidget3->setObjectName(QLatin1String("acceptingDropsWidget3")); + // 260 + 40 = 300 = widget size, must not be more than that. + // otherwise it will break WinRT because there the tlw is maximized every time + // and this window will receive one more event + dropsAcceptingWidget3->resize(180, 40); + dropsAcceptingWidget3->move(10, 260); + dndTestWidget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&dndTestWidget)); qApp->setActiveWindow(&dndTestWidget); QVERIFY(QTest::qWaitForWindowActive(&dndTestWidget)); @@ -595,16 +617,17 @@ void tst_QWidget_window::tst_dnd() log.push_back(msgEventAccepted(e)); while (true) { position.ry() += 20; - if (position.y() >= 250) { + if (position.y() >= 250 && position.y() < 270) { QDropEvent e(position, Qt::CopyAction, &mimeData, Qt::LeftButton, Qt::NoModifier); qApp->sendEvent(window, &e); log.push_back(msgEventAccepted(e)); - break; } else { QDragMoveEvent e(position, Qt::CopyAction, &mimeData, Qt::LeftButton, Qt::NoModifier); qApp->sendEvent(window, &e); log.push_back(msgEventAccepted(e)); } + if (position.y() > 290) + break; } window = nativeWidget->windowHandle(); @@ -628,6 +651,15 @@ void tst_QWidget_window::tst_dnd() for (int i= 0; i < expectedLogSize; ++i) expectedLog.push_back(QString::fromLatin1(expectedLogC[i]).replace(mimeDataAddressPlaceHolder, mimeDataAddress)); + if (log.size() != expectedLog.size()) { + for (int i = 0; i < log.size() && i < expectedLog.size(); ++i) + QCOMPARE(log.at(i), expectedLog.at(i)); + const int iMin = std::min(log.size(), expectedLog.size()); + for (int i = iMin; i < log.size(); ++i) + qDebug() << "log[" << i << "]:" << log.at(i); + for (int i = iMin; i < expectedLog.size(); ++i) + qDebug() << "exp[" << i << "]:" << log.at(i); + } QCOMPARE(log, expectedLog); } @@ -716,6 +748,77 @@ void tst_QWidget_window::tst_dnd_events() QCOMPARE(dndWidget._dndEvents, expectedDndEvents); } + +class DropTarget : public QWidget +{ +public: + explicit DropTarget() + { + setAcceptDrops(true); + + const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry(); + auto width = availableGeometry.width() / 6; + auto height = availableGeometry.height() / 4; + + setGeometry(availableGeometry.x() + 200, availableGeometry.y() + 200, width, height); + + QLabel *label = new QLabel(QStringLiteral("Test"), this); + label->setGeometry(40, 40, 60, 60); + label->setAcceptDrops(true); + } + + void dragEnterEvent(QDragEnterEvent *event) override + { + event->accept(); + mDndEvents.append("enter "); + } + + void dragMoveEvent(QDragMoveEvent *event) override + { + event->acceptProposedAction(); + } + + void dragLeaveEvent(QDragLeaveEvent *) override + { + mDndEvents.append("leave "); + } + + void dropEvent(QDropEvent *event) override + { + event->accept(); + mDndEvents.append("drop "); + } + + QString mDndEvents; +}; + +void tst_QWidget_window::tst_dnd_propagation() +{ + QMimeData mimeData; + mimeData.setText(QLatin1String("testmimetext")); + + DropTarget target; + target.show(); + QVERIFY(QTest::qWaitForWindowActive(&target)); + + Qt::DropActions supportedActions = Qt::DropAction::CopyAction; + QWindow *window = target.windowHandle(); + + auto posInsideDropTarget = QHighDpi::toNativePixels(QPoint(20, 20), window->screen()); + auto posInsideLabel = QHighDpi::toNativePixels(QPoint(60, 60), window->screen()); + + // Enter DropTarget. + QWindowSystemInterface::handleDrag(window, &mimeData, posInsideDropTarget, supportedActions, 0, 0); + // Enter QLabel. This will propagate because default QLabel does + // not accept the drop event in dragEnterEvent(). + QWindowSystemInterface::handleDrag(window, &mimeData, posInsideLabel, supportedActions, 0, 0); + // Drop on QLabel. DropTarget will get dropEvent(), because it accepted the event. + QWindowSystemInterface::handleDrop(window, &mimeData, posInsideLabel, supportedActions, 0, 0); + + QGuiApplication::processEvents(); + + QCOMPARE(target.mDndEvents, "enter leave enter drop "); +} #endif void tst_QWidget_window::tst_qtbug35600() |