File indexing completed on 2024-05-19 16:37:09

0001 /*
0002     SPDX-FileCopyrightText: 2014 Marco Martin <mart@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "dialognativetest.h"
0008 
0009 #include "utils.h"
0010 
0011 #include <KWindowSystem>
0012 
0013 void DialogNativeTest::initTestCase()
0014 {
0015     QStandardPaths::setTestModeEnabled(true);
0016     Plasma::TestUtils::installPlasmaTheme();
0017 
0018     m_cacheDir = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
0019     m_cacheDir.removeRecursively();
0020 
0021     m_dialog = new PlasmaQuick::Dialog;
0022     m_dialog->setLocation(Plasma::Types::TopEdge);
0023 
0024     m_panel = new QQuickView;
0025     m_panel->setGeometry(0, 0, 50, 50);
0026     m_panel->setFlags(Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
0027 
0028     m_panel2 = new QQuickView;
0029     m_panel2->setGeometry(100, 0, 50, 50);
0030     m_panel2->setFlags(Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
0031 
0032     m_panel3 = new QQuickView;
0033     m_panel3->setGeometry(200, 0, 50, 50);
0034     m_panel3->setFlags(Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
0035 
0036     m_content = new QQuickItem;
0037     m_content->setWidth(100);
0038     m_content->setHeight(100);
0039     m_dialog->setMainItem(m_content);
0040 
0041     m_content2 = new QQuickItem(m_panel3->contentItem());
0042     m_content2->setWidth(50);
0043     m_content2->setHeight(25);
0044 
0045     m_panel->show();
0046     m_panel2->show();
0047     m_panel3->show();
0048     KWindowSystem::setType(m_panel->winId(), NET::Dock);
0049     KWindowSystem::setType(m_panel3->winId(), NET::Dock);
0050     m_dialog->setVisualParent(m_panel->contentItem());
0051     m_dialog->show();
0052 }
0053 
0054 void DialogNativeTest::cleanupTestCase()
0055 {
0056     delete m_dialog;
0057     delete m_panel;
0058     delete m_panel2;
0059     delete m_panel3;
0060     delete m_content;
0061 
0062     m_cacheDir.removeRecursively();
0063 }
0064 
0065 void DialogNativeTest::size()
0066 {
0067     QVERIFY(QTest::qWaitForWindowExposed(m_dialog));
0068 
0069     QCOMPARE(m_content->width(), (qreal)100);
0070     QCOMPARE(m_content->height(), (qreal)100);
0071     QCOMPARE(m_dialog->width(), 112);
0072     QCOMPARE(m_dialog->height(), 112);
0073 
0074     QCOMPARE(m_content2->width(), (qreal)50);
0075     QCOMPARE(m_content2->height(), (qreal)25);
0076 
0077     QCOMPARE(m_dialog->margins()->property("left").value<qreal>(), (qreal)6.0);
0078     QCOMPARE(m_dialog->margins()->property("top").value<qreal>(), (qreal)6.0);
0079     QCOMPARE(m_dialog->margins()->property("right").value<qreal>(), (qreal)6.0);
0080     QCOMPARE(m_dialog->margins()->property("bottom").value<qreal>(), (qreal)6.0);
0081 }
0082 
0083 void DialogNativeTest::position()
0084 {
0085     QVERIFY(QTest::qWaitForWindowExposed(m_dialog));
0086 
0087     // Find where the outermost test-panel lives. Normally that would be
0088     // at x,y = (0,0) but if the test is run on a desktop with a
0089     // left-hand-edge panel, then the test-panel is placed next to it.
0090     const auto upper_left_x = m_panel->x();
0091     const auto upper_left_y = m_panel->y();
0092 
0093     QCOMPARE(m_dialog->x(), upper_left_x + 0);
0094     QCOMPARE(m_dialog->y(), upper_left_y + 49);
0095 
0096     m_dialog->setVisualParent(m_panel2->contentItem());
0097     QCOMPARE(m_dialog->x(), 69);
0098     QCOMPARE(m_dialog->y(), 49);
0099 
0100     m_panel3->setMask(QRect(0, 0, 50, 25));
0101     m_dialog->setVisualParent(m_content2);
0102     QCOMPARE(m_dialog->x(), 169);
0103     QCOMPARE(m_dialog->y(), 24);
0104 }
0105 
0106 QTEST_MAIN(DialogNativeTest)
0107 
0108 #include "moc_dialognativetest.cpp"