klog/tests/tst_mainwindow/tst_mainwindow.cpp

290 lines
11 KiB
C++
Raw Normal View History

2022-07-02 15:52:29 +00:00
/***************************************************************************
2022-07-02 21:58:36 +00:00
tst_mainwindow.h - description
2022-07-02 15:52:29 +00:00
-------------------
begin : Jan 2021
copyright : (C) 2021 by Jaime Robles
email : jaime@robles.es
***************************************************************************/
/*****************************************************************************
* This file is part of Testing suite of KLog. *
* *
* KLog is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* The testing suite of KLog is distributed in the hope that it will *
* be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with Testing suite of KLog. *
* If not, see <https://www.gnu.org/licenses/>. *
* *
*****************************************************************************/
#include <QtTest>
#include <QtWidgets>
#include <QPrinter>
#include <QPrintDialog>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QtAlgorithms>
#include <QDesktopServices>
#include <QUrl>
#include "../../src/aboutdialog.h"
#include "../../src/tipsdialog.h"
#include "../../src/filemanager.h"
#include "../../src/fileawardmanager.h"
#include "../../src/locator.h"
#include "../../src/dxcluster.h"
#include "../../src/awards.h"
#include "../../src/awarddxmarathon.h"
#include "../../src/inputwidgets/mainwindowsattab.h"
#include "../../src/inputwidgets/mainwindowmydatatab.h"
#include "../../src/inputwidgets/mainwindowinputcomment.h"
#include "../../src/inputwidgets/mainwindowinputothers.h"
#include "../../src/inputwidgets/mainwindowinputeqsl.h"
#include "../../src/inputwidgets/mainwindowinputqsl.h"
#include "../../src/inputwidgets/mainwindowinputqso.h"
#include "../../src/mainqsoentrywidget.h"
#include "../../src/elogclublog.h"
#include "../../src/downloadcty.h"
#include "../../src/dxccstatuswidget.h"
#include "../../src/awardswidget.h"
#include "../../src/softwareupdate.h"
#include "../../src/logmodel.h"
#include "../../src/logwindow.h"
#include "../../src/searchwidget.h"
#include "../../src/infowidget.h"
#include "../../src/showerrordialog.h"
#include "../../src/udpserver.h"
#include "../../src/statisticswidget.h"
#include "../../src/updatesatsdata.h"
#include "../../src/hamlibclass.h"
#include "../../src/elogqrzlog.h"
#include "../../src/lotwutilities.h"
#include "../../src/eqslutilities.h"
#include "../../src/widgets/adiflotwexportwidget.h"
#include "../../src/widgets/showadifimportwidget.h"
#include "../../src/widgets/map/mapwindowwidget.h"
#include "../../src/widgets/showkloglogwidget.h"
#include "../../src/mainwindow.h"
#include "../../src/dataproxy_sqlite.h"
#include "../../src/database.h"
#include "../../src/klogdefinitions.h"
#include "../../src/setupdialog.h"
#include "../../src/setuppages/setuppageuserdata.h"
2022-07-02 21:58:36 +00:00
#include "../../src/setuppages/setuppagemisc.h"
2022-07-02 15:52:29 +00:00
#include "../../src/utilities.h"
#include "../../src/qso.h"
#include "../../src/world.h"
2022-07-02 23:10:18 +00:00
// http://blog.davidecoppola.com/2018/01/gui-unit-testing-with-qt-test-introduction/
// http://blog.davidecoppola.com/2018/01/gui-unit-testing-with-qt-test-advanced/
2022-07-02 15:52:29 +00:00
class tst_MainWindow : public QObject
{
Q_OBJECT
public:
tst_MainWindow();
~tst_MainWindow();
private slots:
2022-08-07 19:50:59 +00:00
//void initTestCase();
//void cleanupTestCase();
void init();
2022-07-02 15:52:29 +00:00
void test_Constructor();
2022-08-07 19:50:59 +00:00
void test_focusOrder();
2022-07-13 15:30:32 +00:00
void test_QSOEntry();
2022-08-07 19:50:59 +00:00
void test_Settings();
2022-07-02 15:52:29 +00:00
private:
MainWindow *mainWindow;
2022-07-02 23:10:18 +00:00
//QWidget *testCandidate;
public slots:
void slotTimeOut();
2022-07-02 15:52:29 +00:00
};
tst_MainWindow::tst_MainWindow()
{
//MainWindow mw(klogDir, version);
2022-08-12 16:40:59 +00:00
Utilities util(Q_FUNC_INFO);
2022-07-02 15:52:29 +00:00
mainWindow = new MainWindow(util.getHomeDir(), "2.2");
}
2022-07-03 16:28:49 +00:00
tst_MainWindow::~tst_MainWindow(){}
2022-07-02 15:52:29 +00:00
2022-08-07 19:50:59 +00:00
void tst_MainWindow::init()
{
mainWindow->init();
}
2022-07-02 15:52:29 +00:00
2022-08-07 19:50:59 +00:00
void tst_MainWindow::test_focusOrder()
2022-07-02 23:10:18 +00:00
{
2022-08-07 19:50:59 +00:00
QApplication::setActiveWindow(mainWindow);
mainWindow->mainQSOEntryWidget->setFocus();
QVERIFY2(mainWindow->mainQSOEntryWidget->hasFocus(), "mainQSOEntriWidget didn't get focus");
2022-07-02 23:10:18 +00:00
}
2022-07-02 15:52:29 +00:00
void tst_MainWindow::test_Constructor()
{
2022-08-14 21:47:22 +00:00
//qDebug() << Q_FUNC_INFO;
2022-07-02 23:10:18 +00:00
QVERIFY2(mainWindow->showKLogLogWidget, "showKLogLogWidget not created");
QVERIFY2(mainWindow->showErrorDialog, "showErrorDialog not created");
QVERIFY2(mainWindow->UDPLogServer, "UDPLogServer not created");
QVERIFY2(mainWindow->util, "util not created");
QVERIFY2(mainWindow->qso, "qso not created");
2022-07-13 15:30:32 +00:00
QVERIFY2(mainWindow->showErrorDialog, "showErrorDialog not created");
QVERIFY2(mainWindow->lotwUtilities, "lotwUtilities not created");
QVERIFY2(mainWindow->eqslUtilities, "eqslUtilities not created");
QVERIFY2(mainWindow->elogQRZcom, "elogQRZcom not created");
QVERIFY2(mainWindow->elogClublog, "elogClublog not created");
QVERIFY2(mainWindow->downloadcty, "downloadcty not created");
QVERIFY2(mainWindow->world, "world not created");
QVERIFY2(mainWindow->locator, "locator not created");
QVERIFY2(mainWindow->qso, "qso not created");
2022-07-31 14:32:01 +00:00
//QVERIFY2(mainWindow->debugFile, "debugFile not created");
2022-07-13 15:30:32 +00:00
QVERIFY2(mainWindow->dateTime, "dateTime not created");
QVERIFY2(mainWindow->dateTimeTemp, "dateTimeTemp not created");
QVERIFY2(mainWindow->awards, "awards not created");
QVERIFY2(mainWindow->softUpdate, "softUpdate not created");
QVERIFY2(mainWindow->filemanager, "filemanager not created");
QVERIFY2(mainWindow->fileAwardManager, "fileAwardManager not created");
2022-08-07 19:50:59 +00:00
QVERIFY2(mainWindow->qso, "qso not created");
2022-08-14 15:04:26 +00:00
//QTimer::singleShot(500, this, SLOT(slotTimeOut()));
2022-08-14 21:47:22 +00:00
//qDebug() << Q_FUNC_INFO << " - Init";
2022-08-07 19:50:59 +00:00
2022-08-18 12:02:48 +00:00
//mainWindow->init();
2022-08-14 21:47:22 +00:00
//qDebug() << Q_FUNC_INFO << " - Show";
2022-08-14 15:04:26 +00:00
mainWindow->show();
2022-08-14 21:47:22 +00:00
//qDebug() << Q_FUNC_INFO << " - SlotSetup";
2022-08-07 19:50:59 +00:00
mainWindow->slotSetup();
2022-08-14 21:47:22 +00:00
//qDebug() << Q_FUNC_INFO << " - After the SlotSetup";
2022-07-02 23:10:18 +00:00
//QTest::keyClick(&mainWindow, Qt::Key_Tab);
2022-07-13 15:30:32 +00:00
// QTest::keyClick(toplevelWidget, Qt::Key_Space); // To close the showWar button
//qDebug() << Q_FUNC_INFO << "To be shown";
//qDebug() << Q_FUNC_INFO << "To be showed";
2022-07-02 23:10:18 +00:00
//QTest::mouseClick(toplevelWidget. , Qt::LeftButton);
2022-07-13 15:30:32 +00:00
2022-08-14 21:47:22 +00:00
//qDebug() << Q_FUNC_INFO << " - END";
2022-08-07 19:50:59 +00:00
}
void tst_MainWindow::test_Settings()
{
//qDebug() << Q_FUNC_INFO;
/*
QTestEventList events;
events.addKeyClick('a');
events.addKeyClick(Qt::Key_Backspace);
events.addDelay(200);
QLineEdit *lineEdit = new QLineEdit(myParent);
// ...
events.simulate(lineEdit);
events.simulate(lineEdit);
*/
2022-08-18 12:02:48 +00:00
//mainWindow->show();
2022-08-07 19:50:59 +00:00
mainWindow->slotSetup();
//qDebug() << Q_FUNC_INFO << " - END";
}
void tst_MainWindow::slotTimeOut()
{
//qDebug() << Q_FUNC_INFO;
QWidget *modalWidget = QApplication::activeModalWidget();
if (modalWidget->inherits("QMessageBox"))
{
//qDebug() << Q_FUNC_INFO << " Inherits QmessageBox";
QMessageBox *mb = qobject_cast<QMessageBox *>(modalWidget);
//qDebug() << mb->text ();
//QString msg = mb->informativeText ();
QString msg = mb->text ();
QVERIFY2(msg.contains ("Ukraine"), "Show War Message not created");
QTest::keyClick(mb, Qt::Key_Enter);
}
//qDebug() << Q_FUNC_INFO << " - END";
2022-07-13 15:30:32 +00:00
}
void tst_MainWindow::test_QSOEntry()
{
2022-08-07 19:50:59 +00:00
//qDebug() << Q_FUNC_INFO;
2022-07-13 15:30:32 +00:00
mainWindow->show();
//mainWindow->mainQSOEntryWidget->setQRZ ("EA4K");
//QVERIFY2(mainWindow->mainQSOEntryWidget->getQrz () == "EA4K", "Callsign tested wrong");
2022-08-07 19:50:59 +00:00
//qDebug() << "Prefix: " << mainWindow->othersTabWidget->getEntityPrefix ();
//qDebug() << "Label: " << mainWindow->infoLabel2->text ();
2022-07-13 15:30:32 +00:00
//QVERIFY2(mainWindow->othersTabWidget->getEntityPrefix () == "EA", "Prefix not properly idenfified");
//QVERIFY2(mainWindow->infoLabel2->text () == "Spain", "Entity not properly idenfified");
//QVERIFY2(mainWindow->infoLabel2->text () == "Spadin", "Entity2 not properly idenfified");
/*
QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int,QString,double)));
myCustomObject->doSomething(); // trigger emission of the signal
QList<QVariant> arguments = spy.takeFirst();
QVERIFY(arguments.at(0).type() == QVariant::Int);
QVERIFY(arguments.at(1).type() == QVariant::String);
QVERIFY(arguments.at(2).type() == QVariant::double);
2022-07-02 23:10:18 +00:00
*/
2022-07-13 15:30:32 +00:00
MainQSOEntryWidget *mainQSOEntryWidget = mainWindow->mainQSOEntryWidget;
QWidget *testWidget;
testWidget = mainQSOEntryWidget->manualModeCheckBox;
QSignalSpy spy(testWidget, SIGNAL(clicked()));
QSignalSpy spy1(mainQSOEntryWidget, SIGNAL(manualModeSignal(bool)));
QTest::mouseClick(testWidget, Qt::LeftButton);
// check the signal was indeed emitted, one time
QCOMPARE(spy.count(), 1);
QCOMPARE(spy1.count(), 1);
QList<QVariant> args = spy1.takeFirst();
QVERIFY(args.at(0).type() == QVariant::Bool);
2022-08-07 19:55:41 +00:00
if (mainQSOEntryWidget->getManualMode() == true)
{
QVERIFY2(args.at(0).toBool () == true, "Manual mode has been enabled");
}
else
{
QVERIFY2(args.at(0).toBool () == false, "Manual mode has been disabled");
}
2022-07-13 15:30:32 +00:00
/*
QTest::keyClick(testWidget, Qt::Key_E);
QTest::keyClick(testWidget, Qt::Key_A);
QTest::keyClick(testWidget, Qt::Key_4);
QTest::keyClick(testWidget, Qt::Key_K);
2022-08-07 19:50:59 +00:00
//qDebug() << "Signal count: " << QString::number(spy.count ());
//qDebug() << Q_FUNC_INFO << " - reading signal";
2022-07-13 15:30:32 +00:00
QList<QVariant> arguments = spy.takeFirst();
2022-08-07 19:50:59 +00:00
//qDebug() << Q_FUNC_INFO << " - launching signal-1";
//qDebug() << "Signal: " << arguments.at(0).toString ();
//qDebug() << Q_FUNC_INFO << " - launching signal-2";
2022-07-13 15:30:32 +00:00
QVERIFY2(arguments.at(0).type() == QVariant::String, "currentQRZSignal wrong type");
2022-08-07 19:50:59 +00:00
//qDebug() << Q_FUNC_INFO << " - launching signal-3";
2022-07-13 15:30:32 +00:00
QVERIFY2(arguments.at(0).toString ()== QString("EA4K"), "currentQRZSignal wrong type");
2022-08-07 19:50:59 +00:00
//qDebug() << Q_FUNC_INFO << " - launching signal-4";
2022-07-13 15:30:32 +00:00
*/
//QVERIFY(arguments.at(1).type() == QVariant::String);
//QVERIFY(arguments.at(2).type() == QVariant::double);
//QVERIFY2(mainWindow->mainQSOEntryWidget->getQrz () == "EA4K", "Callsign tested wrong");
2022-08-07 19:50:59 +00:00
//qDebug() << Q_FUNC_INFO << " - END";
2022-07-02 15:52:29 +00:00
}
QTEST_MAIN(tst_MainWindow)
#include "tst_mainwindow.moc"