File indexing completed on 2024-04-28 15:31:51

0001 /*
0002     SPDX-FileCopyrightText: 2013 Albert Astals Cid <aacid@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "kcolorbuttontest.h"
0008 
0009 #include <QColorDialog>
0010 #include <QTest>
0011 #include <kcolorbutton.h>
0012 
0013 QTEST_MAIN(KColorButtonTest)
0014 
0015 void KColorButtonTest::testWaitForWindowExposed()
0016 {
0017     // because this test fails in the Windows CI, in qWaitForWindowExposed
0018     // let's test that here
0019     QWindow a;
0020     a.setVisible(true);
0021     // Docu says: Note that a window that is mapped to screen may still not be considered exposed if the window client
0022     // area is completely covered by other windows, or if the window is otherwise not visible.
0023     qDebug() << "isExposed=" << a.isExposed() << "geometry=" << a.geometry() << "visible=" << a.isVisible(); // for Windows (immediate)
0024 #ifdef Q_OS_WIN
0025     if (!a.isExposed()) {
0026         a.setGeometry(QRect(0, 0, 1000, 1000));
0027         qDebug() << "with updated geometry:"
0028                  << "isExposed=" << a.isExposed() << "geometry=" << a.geometry();
0029     }
0030 #endif
0031     QVERIFY(QTest::qWaitForWindowExposed(&a));
0032     qDebug() << "isExposed=" << a.isExposed() << "geometry=" << a.geometry() << "visible=" << a.isVisible(); // for X11 (delayed)
0033 }
0034 
0035 void KColorButtonTest::testOpenDialog()
0036 {
0037     KColorButton colorButton(Qt::red);
0038     colorButton.show();
0039     QVERIFY(QTest::qWaitForWindowExposed(&colorButton));
0040     QTest::mouseClick(&colorButton, Qt::LeftButton);
0041     QColorDialog *dialog = colorButton.findChild<QColorDialog *>();
0042     QVERIFY(dialog != nullptr);
0043     QVERIFY(QTest::qWaitForWindowExposed(dialog));
0044     QCOMPARE(dialog->currentColor(), QColor(Qt::red));
0045 }
0046 
0047 #include "moc_kcolorbuttontest.cpp"