From b0ad939db8ae3676e97b6d640a78a1e73863dcd3 Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Sat, 10 Oct 2020 11:13:53 +0100 Subject: [PATCH] tests: Enable tst_tabbingWithAffinities for QtQuick --- src/private/DropArea_p.h | 3 +++ tests/Testing.h | 16 ++++++++++++ tests/tst_common.cpp | 45 ++++++++++++++++++++++++++++++++ tests/tst_docks.cpp | 55 ---------------------------------------- 4 files changed, 64 insertions(+), 55 deletions(-) diff --git a/src/private/DropArea_p.h b/src/private/DropArea_p.h index f28ca8d9..0a5fec51 100644 --- a/src/private/DropArea_p.h +++ b/src/private/DropArea_p.h @@ -25,6 +25,8 @@ #include "MultiSplitter_p.h" #include "DropIndicatorOverlayInterface_p.h" +class TestCommon; + namespace KDDockWidgets { class Frame; @@ -64,6 +66,7 @@ private: Q_DISABLE_COPY(DropArea) friend class Frame; friend class TestDocks; + friend class ::TestCommon; friend class DropIndicatorOverlayInterface; friend class AnimatedIndicators; friend class FloatingWindow; diff --git a/tests/Testing.h b/tests/Testing.h index c7c8120a..b9d82d93 100644 --- a/tests/Testing.h +++ b/tests/Testing.h @@ -136,6 +136,22 @@ namespace Testing { QSize m_minSz; }; } + +struct SetExpectedWarning +{ + explicit SetExpectedWarning(const QString &s) + { + if (!s.isEmpty()) + Testing::setExpectedWarning(s); + } + + ~SetExpectedWarning() + { + Testing::setExpectedWarning({}); + } + Q_DISABLE_COPY(SetExpectedWarning) +}; + } #endif diff --git a/tests/tst_common.cpp b/tests/tst_common.cpp index 4ec5e429..f9c94628 100644 --- a/tests/tst_common.cpp +++ b/tests/tst_common.cpp @@ -19,14 +19,19 @@ #include "private/MultiSplitter_p.h" #include "TitleBar_p.h" #include "Position_p.h" +#include "DropAreaWithCentralFrame_p.h" #include #include #include #ifdef KDDOCKWIDGETS_QTQUICK +# include "quick/DockWidgetQuick.h" + # include # include +# else +# include "DockWidget.h" #endif using namespace KDDockWidgets; @@ -68,6 +73,7 @@ private Q_SLOTS: void tst_detachFromMainWindow(); void tst_detachPos(); void tst_floatingWindowSize(); + void tst_tabbingWithAffinities(); }; void TestCommon::tst_simple1() @@ -250,6 +256,45 @@ void TestCommon::tst_floatingWindowSize() delete fw1; } +void TestCommon::tst_tabbingWithAffinities() +{ + EnsureTopLevelsDeleted e; + // Tests that dock widgets with different affinities should not tab together + + auto m1 = createMainWindow(QSize(1000, 1000), MainWindowOption_None); + m1->setAffinities({ "af1", "af2" }); + + auto dw1 = new DockWidgetType("1"); + dw1->setAffinities({ "af1" }); + dw1->show(); + + auto dw2 = new DockWidgetType("2"); + dw2->setAffinities({ "af2" }); + dw2->show(); + + FloatingWindow *fw1 = dw1->floatingWindow(); + FloatingWindow *fw2 = dw2->floatingWindow(); + + { + SetExpectedWarning ignoreWarning("Refusing to dock widget with incompatible affinity"); + dw1->addDockWidgetAsTab(dw2); + QVERIFY(dw1->window() != dw2->window()); + } + + m1->addDockWidget(dw1, Location_OnBottom); + QVERIFY(!dw1->isFloating()); + + { + SetExpectedWarning ignoreWarning("Refusing to dock widget with incompatible affinity"); + auto dropArea = m1->dropArea(); + QVERIFY(!dropArea->drop(fw2, dw1->frame(), DropIndicatorOverlayInterface::DropLocation_Center)); + QVERIFY(dw1->window() != dw2->window()); + } + + delete fw1; + delete fw2; +} + int main(int argc, char *argv[]) { if (!qpaPassedAsArgument(argc, argv)) { diff --git a/tests/tst_docks.cpp b/tests/tst_docks.cpp index 9fbc0fb1..39579f36 100644 --- a/tests/tst_docks.cpp +++ b/tests/tst_docks.cpp @@ -163,21 +163,6 @@ inline int widgetMinLength(const QWidget *w, Qt::Orientation o) return o == Qt::Vertical ? sz.height() : sz.width(); } -struct SetExpectedWarning -{ - explicit SetExpectedWarning(const QString &s) - { - if (!s.isEmpty()) - Testing::setExpectedWarning(s); - } - - ~SetExpectedWarning() - { - Testing::setExpectedWarning({}); - } - Q_DISABLE_COPY(SetExpectedWarning) -}; - struct WidgetResize { int length; @@ -438,7 +423,6 @@ private Q_SLOTS: void tst_tabTitleChanges(); void tst_dockWidgetGetsFocusWhenDocked(); void tst_sizeAfterRedock(); - void tst_tabbingWithAffinities(); private: std::unique_ptr createMultiSplitterFromSetup(MultiSplitterSetup setup, QHash &frameMap) const; }; @@ -6176,45 +6160,6 @@ void TestDocks::tst_sizeAfterRedock() delete oldFw2; } -void TestDocks::tst_tabbingWithAffinities() -{ - EnsureTopLevelsDeleted e; - // Tests that dock widgets with different affinities should not tab together - - auto m1 = createMainWindow(QSize(1000, 1000), MainWindowOption_None); - m1->setAffinities({ "af1", "af2" }); - - auto dw1 = new DockWidget("1"); - dw1->setAffinities({ "af1" }); - dw1->show(); - - auto dw2 = new DockWidget("2"); - dw2->setAffinities({ "af2" }); - dw2->show(); - - FloatingWindow *fw1 = dw1->floatingWindow(); - FloatingWindow *fw2 = dw2->floatingWindow(); - - { - SetExpectedWarning ignoreWarning("Refusing to dock widget with incompatible affinity"); - dw1->addDockWidgetAsTab(dw2); - QVERIFY(dw1->window() != dw2->window()); - } - - m1->addDockWidget(dw1, Location_OnBottom); - QVERIFY(!dw1->isFloating()); - - { - SetExpectedWarning ignoreWarning("Refusing to dock widget with incompatible affinity"); - DropArea *dropArea = m1->dropArea(); - QVERIFY(!dropArea->drop(fw2, dw1->frame(), DropIndicatorOverlayInterface::DropLocation_Center)); - QVERIFY(dw1->window() != dw2->window()); - } - - delete fw1; - delete fw2; -} - int main(int argc, char *argv[]) { if (!qpaPassedAsArgument(argc, argv)) {