Files
location_plotter/tests/main_window_tests.cpp
T
onur 2856c5a560
Ubuntu build / build-and-test (ubuntu-22.04) (push) Has been cancelled
Ubuntu build / build-and-test (ubuntu-24.04) (push) Has been cancelled
Initial commit: add Location Plotter
2026-07-16 13:16:12 +03:00

165 lines
7.1 KiB
C++

#include "../src/MainWindow.h"
#include "../src/MapWidget.h"
#include <QApplication>
#include <QCheckBox>
#include <QComboBox>
#include <QDoubleSpinBox>
#include <QLabel>
#include <QLineEdit>
#include <QMetaObject>
#include <QSpinBox>
#include <QTableView>
#include <QTabWidget>
#include <QSplitter>
#include <cassert>
namespace {
void sendLine(MainWindow &window, const QString &line)
{
const bool invoked = QMetaObject::invokeMethod(
&window, "handleSerialLine", Qt::DirectConnection, Q_ARG(QString, line));
assert(invoked);
}
void flushUpdates(MainWindow &window)
{
const bool invoked = QMetaObject::invokeMethod(
&window, "flushUiUpdates", Qt::DirectConnection);
assert(invoked);
}
} // namespace
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MainWindow window;
auto *table = window.findChild<QTableView *>();
auto *referenceLatInput = window.findChild<QLineEdit *>(QStringLiteral("referenceLatInput"));
auto *referenceLonInput = window.findChild<QLineEdit *>(QStringLiteral("referenceLonInput"));
auto *cepValue = window.findChild<QLabel *>(QStringLiteral("cepValue"));
auto *maxPointsInput = window.findChild<QSpinBox *>(QStringLiteral("maxPointsInput"));
auto *elevationMaskSpin = window.findChild<QDoubleSpinBox *>(QStringLiteral("elevationMaskSpin"));
auto *showTelemetry = window.findChild<QCheckBox *>(QStringLiteral("showTelemetryCheck"));
auto *showRecentPoints = window.findChild<QCheckBox *>(QStringLiteral("showRecentPointsCheck"));
auto *showAverage = window.findChild<QCheckBox *>(QStringLiteral("showAverageCheck"));
auto *portSelector = window.findChild<QComboBox *>(QStringLiteral("portSelector"));
auto *map = window.findChild<MapWidget *>();
auto *mainViewTabs = window.findChild<QTabWidget *>(QStringLiteral("mainViewTabs"));
auto *sideSplitter = window.findChild<QSplitter *>(QStringLiteral("sideSplitter"));
assert(table != nullptr);
assert(referenceLatInput != nullptr);
assert(referenceLonInput != nullptr);
assert(cepValue != nullptr);
assert(maxPointsInput != nullptr);
assert(elevationMaskSpin != nullptr);
assert(elevationMaskSpin->value() == 10);
assert(elevationMaskSpin->minimum() == 0);
assert(elevationMaskSpin->maximum() == 90.0);
elevationMaskSpin->setValue(12.5);
assert(elevationMaskSpin->value() == 12.5);
assert(showTelemetry != nullptr);
assert(showRecentPoints != nullptr);
assert(showAverage != nullptr);
assert(portSelector != nullptr);
assert(!portSelector->isEditable());
assert(portSelector->count() >= 1);
for (int i = 0; i < portSelector->count(); ++i) {
assert(portSelector->itemText(i).startsWith(QStringLiteral("/dev/ttyUSB")));
assert(!portSelector->itemText(i).trimmed().isEmpty());
}
assert(map != nullptr);
assert(mainViewTabs != nullptr);
assert(mainViewTabs->count() == 2);
assert(sideSplitter != nullptr);
assert(sideSplitter->orientation() == Qt::Vertical);
assert(QMetaObject::invokeMethod(map, "referenceLocationSelected", Qt::DirectConnection,
Q_ARG(double, 40.25), Q_ARG(double, 29.5)));
assert(referenceLatInput->text() == QStringLiteral("40.250000000000000"));
assert(referenceLonInput->text() == QStringLiteral("29.500000000000000"));
referenceLatInput->clear();
referenceLonInput->clear();
assert(QMetaObject::invokeMethod(&window, "updateReferenceLocation", Qt::DirectConnection));
showTelemetry->setChecked(false);
assert(!showRecentPoints->isEnabled());
assert(!showAverage->isEnabled());
showTelemetry->setChecked(true);
assert(showRecentPoints->isEnabled());
assert(showAverage->isEnabled());
sendLine(window, QStringLiteral("lattitude : 40.78925034214206846173"));
sendLine(window, QStringLiteral("longitude : 29.46277530841727809729"));
assert(table->model()->rowCount() == 0);
sendLine(window, QStringLiteral("NAV solve done"));
flushUpdates(window);
assert(table->model()->rowCount() == 1);
assert(table->model()->data(table->model()->index(0, 1)).toString()
== QStringLiteral("40.78925034214206846173"));
assert(table->model()->data(table->model()->index(0, 2)).toString()
== QStringLiteral("29.46277530841727809729"));
referenceLatInput->setText(QStringLiteral("40.78925034214206846173"));
referenceLonInput->setText(QStringLiteral("29.46277530841727809729"));
const bool referenceUpdated = QMetaObject::invokeMethod(
&window, "updateReferenceLocation", Qt::DirectConnection);
assert(referenceUpdated);
assert(cepValue->text().startsWith(QStringLiteral("0.00 m")));
assert(cepValue->text().contains(QStringLiteral("N=1")));
const bool cleared = QMetaObject::invokeMethod(&window, "clearPoints", Qt::DirectConnection);
assert(cleared);
assert(table->model()->rowCount() == 0);
assert(referenceLatInput->text() == QStringLiteral("40.78925034214206846173"));
assert(referenceLonInput->text() == QStringLiteral("29.46277530841727809729"));
assert(cepValue->text() == QStringLiteral("-"));
referenceLatInput->setText(QStringLiteral("40.0"));
referenceLonInput->setText(QStringLiteral("29.0"));
assert(QMetaObject::invokeMethod(&window, "updateReferenceLocation", Qt::DirectConnection));
sendLine(window, QStringLiteral("lat=40.000 long=29.000"));
sendLine(window, QStringLiteral("lat=40.001 long=29.000"));
sendLine(window, QStringLiteral("lat=40.002 long=29.000"));
flushUpdates(window);
assert(cepValue->text().startsWith(QStringLiteral("111 m")));
assert(cepValue->text().contains(QStringLiteral("N=3")));
assert(QMetaObject::invokeMethod(&window, "clearPoints", Qt::DirectConnection));
referenceLatInput->setText(QStringLiteral("40.78925034214206846173"));
referenceLonInput->setText(QStringLiteral("29.46277530841727809729"));
assert(QMetaObject::invokeMethod(&window, "updateReferenceLocation", Qt::DirectConnection));
maxPointsInput->setValue(10000);
for (int i = 0; i < 10000; ++i) {
sendLine(window, QStringLiteral("lat=40.78925 long=29.46277 sats=7"));
}
flushUpdates(window);
assert(table->model()->rowCount() == 10000);
assert(cepValue->text().contains(QStringLiteral("N=10000")));
assert(QMetaObject::invokeMethod(&window, "clearPoints", Qt::DirectConnection));
maxPointsInput->setValue(10);
const QByteArray screenshotPath = qgetenv("LOCATION_PLOTTER_TEST_SCREENSHOT");
if (!screenshotPath.isEmpty()) {
sendLine(window, QStringLiteral("NAV solve start sats:5"));
sendLine(window, QStringLiteral("tracking PRNs: G03, G08, G14, G21, G27"));
sendLine(window, QStringLiteral(
"lat=40.78925034214206846173 long=29.46277530841727809729 "
"hheight=-89.05779508221894502640 sats=7 PDOP=1.235"));
flushUpdates(window);
mainViewTabs->setCurrentIndex(1);
window.show();
app.processEvents();
window.repaint();
app.processEvents();
assert(window.grab().save(QString::fromLocal8Bit(screenshotPath), "PNG"));
}
return 0;
}