File indexing completed on 2024-04-21 14:47:19

0001 /*
0002     SPDX-FileCopyrightText: 2017 Csaba Kertesz <csaba.kertesz@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 
0008 #include "kstars_lite_ui_tests.h"
0009 
0010 #include "auxiliary/kspaths.h"
0011 #include "kstarslite.h"
0012 
0013 #include <QFuture>
0014 #include <QtConcurrentRun>
0015 #include <QTest>
0016 
0017 #include <time.h>
0018 #include <unistd.h>
0019 
0020 namespace
0021 {
0022 KStarsLite *kstarsLiteInstance = nullptr;
0023 QString testProfileName;
0024 }
0025 
0026 void waitForKStars()
0027 {
0028     while (!kstarsLiteInstance->getMainWindow() && !kstarsLiteInstance->getMainWindow()->isActive())
0029     {
0030         QThread::msleep(1000);
0031     }
0032     QThread::msleep(2000);
0033 }
0034 
0035 KStarsLiteUiTests::KStarsLiteUiTests()
0036 {
0037     srand((int)time(nullptr));
0038 }
0039 
0040 void KStarsLiteUiTests::initTestCase()
0041 {
0042     kstarsLiteInstance = KStarsLite::createInstance(true);
0043 }
0044 
0045 void KStarsLiteUiTests::cleanupTestCase()
0046 {
0047     kstarsLiteInstance = nullptr;
0048 }
0049 
0050 void openToolbarsTest()
0051 {
0052     waitForKStars();
0053 
0054     QObject* topMenu = kstarsLiteInstance->getMainWindow()->findChild<QObject*>("topMenu");
0055     QObject* topMenuArrow = kstarsLiteInstance->getMainWindow()->findChild<QObject*>("arrowDownMouseArea");
0056     QObject* bottomMenu = kstarsLiteInstance->getMainWindow()->findChild<QObject*>("bottomMenu");
0057     QObject* bottomMenuArrow = kstarsLiteInstance->getMainWindow()->findChild<QObject*>("arrowUpMouseArea");
0058 
0059     QCOMPARE(topMenu != nullptr, true);
0060     QCOMPARE(topMenuArrow != nullptr, true);
0061     QCOMPARE(bottomMenu != nullptr, true);
0062     QCOMPARE(bottomMenuArrow != nullptr, true);
0063 
0064     // Open the top menu
0065     QCOMPARE(topMenu->property("state") == "closed", true);
0066     QMetaObject::invokeMethod(topMenuArrow, "manualPress");
0067     QThread::msleep(800);
0068     QCOMPARE(topMenu->property("state") == "open", true);
0069     // Close the top menu
0070     QMetaObject::invokeMethod(topMenuArrow, "manualPress");
0071     QThread::msleep(800);
0072     QCOMPARE(topMenu->property("state") == "closed", true);
0073 
0074     // Open the bottom menu
0075     QCOMPARE(bottomMenu->property("state") == "closed", true);
0076     QMetaObject::invokeMethod(bottomMenuArrow, "manualPress");
0077     QThread::msleep(800);
0078     QCOMPARE(bottomMenu->property("state") == "open", true);
0079     // Close the bottom menu
0080     QMetaObject::invokeMethod(bottomMenuArrow, "manualPress");
0081     QThread::msleep(800);
0082     QCOMPARE(bottomMenu->property("state") == "closed", true);
0083 
0084     QThread::msleep(1000);
0085 }
0086 
0087 void KStarsLiteUiTests::openToolbars()
0088 {
0089     QFuture<void> testFuture = QtConcurrent::run(openToolbarsTest);
0090 
0091     while (!testFuture.isFinished())
0092     {
0093         QCoreApplication::instance()->processEvents();
0094         usleep(20*1000);
0095     }
0096 }
0097 
0098 QTEST_MAIN(KStarsLiteUiTests);