Restore in-scope files missing from the merge and scope-aware CMakeLists
The merge from story/release-validation-scope only carried files that existed at the common base or on that branch. In-scope files added on story/release-2-cleanup after the base (per-module unit-test dirs, the Release 2 driver and rpmbuild script) were missing, breaking ADD_SUBDIRECTORY(unit-test) references. - Restore the 33 missing in-scope files from story/release-2-cleanup. - Lts/Common/CMakeLists.txt and LtsUtilsGui/CMakeLists.txt: take the story/release-2-cleanup versions (the validation versions still reference out-of-scope subdirectories: httq, LtsRestClient, LtsWebSocket, ConnectDialog, StyleManager).
This commit is contained in:
1 parent
cfe15c72c4
commit
262fd226f9
35 files changed
+6856
-16
No files matched your search
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# Unit tests for the LtsCoordinate module.
|
||||
# One test executable per module, each registered with ctest.
|
||||
#
|
||||
if (NOT BUILD_TESTING)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# --- LtsCoordinate: geo<->UTM conversion, MGRS formatting, distances, angles,
|
||||
# --- elevation callback and batch LtsCoordVector conversion
|
||||
if (TARGET LtsCoordinate)
|
||||
ADD_EXECUTABLE(ltscoordinate_unit_test ltscoordinate_unit_test.cpp)
|
||||
TARGET_LINK_LIBRARIES(ltscoordinate_unit_test
|
||||
LtsCoordinate
|
||||
LtsCoordTrans
|
||||
Qt6::Core
|
||||
Qt6::Test
|
||||
)
|
||||
ADD_TEST(NAME ltscoordinate_unit_test COMMAND $<TARGET_FILE:ltscoordinate_unit_test>)
|
||||
endif()
|
||||
+314
@@ -0,0 +1,314 @@
|
||||
//
|
||||
// Unit tests for the LtsCoordinate module (Lts/Common/LtsCoordinate):
|
||||
// LtsCoordinate (geo<->UTM conversion, MGRS formatting, distances, angles,
|
||||
// elevation callback, conversion counter) and LtsCoordVector (batch
|
||||
// geo->UTM conversion with zone caching).
|
||||
//
|
||||
// Note: geographic coordinates are radians everywhere (Core::GeoPosition
|
||||
// and LtsCoordTrans::deg2rad/rad2deg), mirroring the LtsCoordTrans tests.
|
||||
//
|
||||
#include <LtsCoordinate/lts_coordinate.h>
|
||||
#include <LtsCoordinate/lts_coord_vector.h>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
|
||||
#include <Core/core.hpp>
|
||||
|
||||
#include <QtTest/QTest>
|
||||
#include <QtCore/QPointF>
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
using namespace LtsCoordTrans;
|
||||
|
||||
class ltscoordinate_unit_test : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void cleanupTestCase();
|
||||
|
||||
void constructorsAndGeoAccessors();
|
||||
void validityChecks();
|
||||
void valueIsNullOrNan();
|
||||
void mgrsFormatting();
|
||||
void geoUtmRoundtrip();
|
||||
void fromUtm();
|
||||
void utmCoordinateDiffZone();
|
||||
void distanceUtm2D();
|
||||
void distanceUtm3D();
|
||||
void angleDegreeUtm2D();
|
||||
void elevationCallback();
|
||||
void conversionCounter();
|
||||
void ltsCoordVector();
|
||||
};
|
||||
|
||||
// The elevation callback is a static (process-wide) of LtsCoordinate —
|
||||
// reset it so other tests in the suite are not affected.
|
||||
void ltscoordinate_unit_test::cleanupTestCase()
|
||||
{
|
||||
LtsCoordinate::setElevationCallback(nullptr);
|
||||
}
|
||||
|
||||
void ltscoordinate_unit_test::constructorsAndGeoAccessors()
|
||||
{
|
||||
const double lon = 8.6264954126 * deg2rad();
|
||||
const double lat = 53.1138437183 * deg2rad();
|
||||
|
||||
LtsCoordinate coord(lon, lat, 42.5);
|
||||
QCOMPARE(coord.geoPosition().lon, lon);
|
||||
QCOMPARE(coord.geoPosition().lat, lat);
|
||||
QCOMPARE(coord.z(), 42.5);
|
||||
coord.setZ(1.0);
|
||||
QCOMPARE(coord.z(), 1.0);
|
||||
|
||||
const QPointF pnt = coord.toGeoPointF();
|
||||
QCOMPARE(pnt.x(), lon);
|
||||
QCOMPARE(pnt.y(), lat);
|
||||
|
||||
const LtsCoordinate fromPnt(QPointF(lon, lat), 7.0);
|
||||
QCOMPARE(fromPnt.z(), 7.0);
|
||||
|
||||
const LtsCoordinate def;
|
||||
QVERIFY(std::isnan(def.z()));
|
||||
|
||||
const LtsCoordinate fromGeo = LtsCoordinate::fromGeoPosition(lon, lat, 3.0);
|
||||
QCOMPARE(fromGeo.z(), 3.0);
|
||||
|
||||
const Core::GeoPosition2D geo2D(lon, lat);
|
||||
const LtsCoordinate from2D(geo2D);
|
||||
QCOMPARE(from2D.geoPosition().lon, lon);
|
||||
QCOMPARE(from2D.geoPosition2D().lat, lat);
|
||||
}
|
||||
|
||||
void ltscoordinate_unit_test::validityChecks()
|
||||
{
|
||||
// (0,0) is "null" for validity purposes (qFuzzyIsNull), not a real position
|
||||
LtsCoordinate def;
|
||||
QVERIFY(!def.hasGeo());
|
||||
QVERIFY(!def.hasUtm());
|
||||
QVERIFY(!def.isValid());
|
||||
|
||||
const double lon = 8.6264954126 * deg2rad();
|
||||
const double lat = 53.1138437183 * deg2rad();
|
||||
LtsCoordinate valid(lon, lat);
|
||||
QVERIFY(valid.hasGeo());
|
||||
QVERIFY(valid.isValid());
|
||||
QVERIFY(!valid.hasUtm()); // not converted yet
|
||||
|
||||
(void)valid.utmCoordinate();
|
||||
QVERIFY(valid.hasUtm());
|
||||
QVERIFY(valid.utmCoordinate().zone > 0);
|
||||
}
|
||||
|
||||
void ltscoordinate_unit_test::valueIsNullOrNan()
|
||||
{
|
||||
QVERIFY(LtsCoordinate::valueIsNullOrNan(0.0));
|
||||
QVERIFY(LtsCoordinate::valueIsNullOrNan(std::nan("")));
|
||||
QVERIFY(!LtsCoordinate::valueIsNullOrNan(1.0));
|
||||
QVERIFY(!LtsCoordinate::valueIsNullOrNan(-1e-6));
|
||||
}
|
||||
|
||||
// Known MGRS values, mirrored from the LtsCoordTrans test suite through the
|
||||
// LtsCoordinate facade.
|
||||
void ltscoordinate_unit_test::mgrsFormatting()
|
||||
{
|
||||
const LtsCoordinate coord(8.6264954126 * deg2rad(), 53.1138437183 * deg2rad());
|
||||
QCOMPARE(coord.mgrs(0), QStringLiteral("32U MD"));
|
||||
QCOMPARE(coord.mgrs(8), QStringLiteral("32U MD 74999999 84999999"));
|
||||
// no-space form is the concatenation of the space form for this coordinate
|
||||
QCOMPARE(coord.mgrs(8, false), QStringLiteral("32UMD7499999984999999"));
|
||||
|
||||
const LtsCoordinate coord2(11.3003696521 * deg2rad(), 52.8224535191 * deg2rad());
|
||||
QCOMPARE(coord2.mgrs(0), QStringLiteral("32U PD"));
|
||||
QCOMPARE(coord2.mgrs(5), QStringLiteral("32U PD 55000 55000"));
|
||||
|
||||
const LtsCoordinate coord3(54.8821607021 * deg2rad(), 24.2631973752 * deg2rad());
|
||||
QCOMPARE(coord3.mgrs(0), QStringLiteral("40R BM"));
|
||||
QCOMPARE(coord3.mgrs(5), QStringLiteral("40R BM 85000 85000"));
|
||||
|
||||
// Without an elevation callback the z part is NaN
|
||||
const QString withZ = coord.mgrsWithZ(0);
|
||||
QVERIFY(withZ.startsWith(QStringLiteral("32U MD z=")));
|
||||
}
|
||||
|
||||
void ltscoordinate_unit_test::geoUtmRoundtrip()
|
||||
{
|
||||
const double lonDeg = 8.6264954126;
|
||||
const double latDeg = 53.1138437183;
|
||||
LtsCoordinate coord(lonDeg * deg2rad(), latDeg * deg2rad(), 5.0);
|
||||
|
||||
const UtmCoordinate utm = coord.utmCoordinate();
|
||||
QVERIFY(utm.zone > 0);
|
||||
|
||||
const QPointF geoBack = utm.geographic();
|
||||
QVERIFY(std::abs(geoBack.x() * rad2deg() - lonDeg) < 1e-6);
|
||||
QVERIFY(std::abs(geoBack.y() * rad2deg() - latDeg) < 1e-6);
|
||||
|
||||
// toUtmPointF / toUtmPoint3D agree with the cached UTM coordinate
|
||||
const QPointF utmPnt = coord.toUtmPointF();
|
||||
QVERIFY(std::abs(utmPnt.x() - utm.x) < 1e-6);
|
||||
QVERIFY(std::abs(utmPnt.y() - utm.y) < 1e-6);
|
||||
const LtsUtils::QPoint3D utm3D = coord.toUtmPoint3D();
|
||||
QCOMPARE(utm3D.z(), 5.0);
|
||||
}
|
||||
|
||||
void ltscoordinate_unit_test::fromUtm()
|
||||
{
|
||||
const LtsCoordinate c1 = LtsCoordinate::fromUtm(QPointF(500000., 5000000.), 32, 10.0);
|
||||
QCOMPARE(c1.utmCoordinate().zone, 32);
|
||||
QVERIFY(std::abs(c1.utmCoordinate().x - 500000.) < 0.01);
|
||||
QVERIFY(std::abs(c1.utmCoordinate().y - 5000000.) < 0.01);
|
||||
QCOMPARE(c1.z(), 10.0);
|
||||
|
||||
const UtmCoordinate utm(32, 500123., 5000456., true);
|
||||
const LtsCoordinate c2 = LtsCoordinate::fromUtmCoordinate(utm, 20.0);
|
||||
QCOMPARE(c2.z(), 20.0);
|
||||
QVERIFY(std::abs(c2.utmCoordinate().x - 500123.) < 0.01);
|
||||
QVERIFY(std::abs(c2.utmCoordinate().y - 5000456.) < 0.01);
|
||||
|
||||
const UtmCoordinate3D c3 = c1.toUtmCoordinate3D();
|
||||
QCOMPARE(c3.z(), 10.0);
|
||||
}
|
||||
|
||||
void ltscoordinate_unit_test::utmCoordinateDiffZone()
|
||||
{
|
||||
const double lon = 8.6264954126 * deg2rad();
|
||||
const double lat = 53.1138437183 * deg2rad();
|
||||
LtsCoordinate coord(lon, lat);
|
||||
|
||||
const UtmCoordinate in31 = coord.utmCoordinateDiffZone(31);
|
||||
const UtmCoordinate in32 = coord.utmCoordinateDiffZone(32);
|
||||
QCOMPARE(in31.zone, 31);
|
||||
QCOMPARE(in32.zone, 32);
|
||||
QVERIFY(in31.x != in32.x);
|
||||
|
||||
// Same zone: diff-zone result matches the default conversion
|
||||
const UtmCoordinate defaultZone = coord.utmCoordinate();
|
||||
const UtmCoordinate sameZone = coord.utmCoordinateDiffZone(defaultZone.zone);
|
||||
QCOMPARE(sameZone.x, defaultZone.x);
|
||||
QCOMPARE(sameZone.y, defaultZone.y);
|
||||
}
|
||||
|
||||
void ltscoordinate_unit_test::distanceUtm2D()
|
||||
{
|
||||
const LtsCoordinate a = LtsCoordinate::fromUtm(QPointF(500000., 5000000.), 32, 0.);
|
||||
const LtsCoordinate b = LtsCoordinate::fromUtm(QPointF(500100., 5000000.), 32, 0.);
|
||||
|
||||
QVERIFY(std::abs(a.distanceUtm2D(b) - 100.0) < 1e-3);
|
||||
QVERIFY(std::abs(a.distanceUtm2D(a)) < 1e-6);
|
||||
QVERIFY(std::abs(a.distanceUtm2D(b) - b.distanceUtm2D(a)) < 1e-9);
|
||||
}
|
||||
|
||||
void ltscoordinate_unit_test::distanceUtm3D()
|
||||
{
|
||||
const LtsCoordinate a = LtsCoordinate::fromUtm(QPointF(500000., 5000000.), 32, 0.);
|
||||
const LtsCoordinate b = LtsCoordinate::fromUtm(QPointF(500100., 5000000.), 32, 40.);
|
||||
|
||||
const double expected = std::hypot(100., 40.);
|
||||
QVERIFY(std::abs(a.distanceUtm3D(b) - expected) < 1e-3);
|
||||
}
|
||||
|
||||
void ltscoordinate_unit_test::angleDegreeUtm2D()
|
||||
{
|
||||
const LtsCoordinate a = LtsCoordinate::fromUtm(QPointF(500000., 5000000.), 32, 0.);
|
||||
const LtsCoordinate east = LtsCoordinate::fromUtm(QPointF(500100., 5000000.), 32, 0.);
|
||||
const LtsCoordinate north = LtsCoordinate::fromUtm(QPointF(500000., 5000100.), 32, 0.);
|
||||
|
||||
// Conventions: QLineF angle (0 = +x) shifted by +90 degrees
|
||||
QVERIFY(std::abs(LtsCoordinate::angleDegreeUtm2D(a, east) - 90.0) < 0.1);
|
||||
QVERIFY(std::abs(LtsCoordinate::angleDegreeUtm2D(a, north) - 0.0) < 0.1);
|
||||
}
|
||||
|
||||
void ltscoordinate_unit_test::elevationCallback()
|
||||
{
|
||||
LtsCoordinate::setElevationCallback([](double, double, double, bool* covered) {
|
||||
if (covered)
|
||||
*covered = true;
|
||||
return 123.45;
|
||||
});
|
||||
QVERIFY(LtsCoordinate::hasElevationCallback());
|
||||
|
||||
const double lon = 8.6264954126 * deg2rad();
|
||||
const double lat = 53.1138437183 * deg2rad();
|
||||
LtsCoordinate coord(lon, lat);
|
||||
|
||||
bool covered = false;
|
||||
QCOMPARE(coord.elevationAt(0.0, &covered), 123.45);
|
||||
QVERIFY(covered);
|
||||
QCOMPARE(LtsCoordinate::elevationAt(coord), 123.45);
|
||||
|
||||
coord.setZValueAccordingElevation();
|
||||
QCOMPARE(coord.z(), 123.45);
|
||||
QVERIFY(std::abs(coord.heightOverElevation()) < 1e-9);
|
||||
|
||||
const LtsCoordinate above(lon, lat, 200.0);
|
||||
QVERIFY(std::abs(above.heightOverElevation() - (200.0 - 123.45)) < 1e-9);
|
||||
|
||||
// replaceZValueByElevationIfValue: NaN z is replaced
|
||||
LtsCoordinate nanZ(lon, lat);
|
||||
QVERIFY(std::isnan(nanZ.z()));
|
||||
nanZ.replaceZValueByElevationIfValue();
|
||||
QCOMPARE(nanZ.z(), 123.45);
|
||||
|
||||
// matching z is replaced, non-matching z is left alone
|
||||
LtsCoordinate z77(lon, lat, 77.0);
|
||||
z77.replaceZValueByElevationIfValue(77.0);
|
||||
QCOMPARE(z77.z(), 123.45);
|
||||
z77.replaceZValueByElevationIfValue(99.0);
|
||||
QCOMPARE(z77.z(), 123.45);
|
||||
|
||||
// mgrsWithZ now carries the elevation
|
||||
const QString withZ = coord.mgrsWithZ(0);
|
||||
QVERIFY(withZ.startsWith(QStringLiteral("32U MD z=123.45")));
|
||||
}
|
||||
|
||||
void ltscoordinate_unit_test::conversionCounter()
|
||||
{
|
||||
LtsCoordinate::resetConversionCounter();
|
||||
QCOMPARE(LtsCoordinate::getConversionCounter(), 0L);
|
||||
|
||||
const double lon = 8.6264954126 * deg2rad();
|
||||
const double lat = 53.1138437183 * deg2rad();
|
||||
LtsCoordinate coord(lon, lat);
|
||||
(void)coord.utmCoordinate();
|
||||
|
||||
// The counter is only incremented in LTS_DEBUG builds (the pipeline
|
||||
// driver defines it: BUILD_RPM is not set)
|
||||
QVERIFY(LtsCoordinate::getConversionCounter() >= 1L);
|
||||
}
|
||||
|
||||
void ltscoordinate_unit_test::ltsCoordVector()
|
||||
{
|
||||
std::vector<Core::GeoPosition> geos;
|
||||
geos.emplace_back(8.6264954126 * deg2rad(), 53.1138437183 * deg2rad(), 1.0);
|
||||
geos.emplace_back(11.3003696521 * deg2rad(), 52.8224535191 * deg2rad(), 2.0);
|
||||
// (14.0 E, 52.0 N) - in UTM zone 32 like the others (toStdUtmCoord(32))
|
||||
geos.emplace_back(14.0 * deg2rad(), 52.0 * deg2rad(), 3.0);
|
||||
|
||||
const LtsCoordVector vec(geos);
|
||||
QCOMPARE(vec.size(), 3);
|
||||
QCOMPARE(vec.geoPosition().size(), 3u);
|
||||
QCOMPARE(vec.geoPosition()[1].lat, geos[1].lat);
|
||||
|
||||
const std::vector<UtmCoordinate> utmStd = vec.toStdUtmCoord(32);
|
||||
QCOMPARE(utmStd.size(), 3u);
|
||||
for (const auto& u : utmStd)
|
||||
QCOMPARE(u.zone, 32);
|
||||
|
||||
const QVector<UtmCoordinate> utmQv = vec.toQVectorUtmCoord(32);
|
||||
QCOMPARE(utmQv.size(), 3);
|
||||
QCOMPARE(utmQv[0].x, utmStd[0].x);
|
||||
|
||||
const QVector<QPointF> pts = vec.toQVectorQPointF(32);
|
||||
QCOMPARE(pts.size(), 3);
|
||||
for (const QPointF& p : pts)
|
||||
QVERIFY(std::isfinite(p.x()) && std::isfinite(p.y()));
|
||||
|
||||
// Per-zone cache: repeated calls return the same values
|
||||
const QVector<QPointF> again = vec.toQVectorQPointF(32);
|
||||
QCOMPARE(again, pts);
|
||||
}
|
||||
|
||||
QTEST_MAIN(ltscoordinate_unit_test)
|
||||
#include "ltscoordinate_unit_test.moc"
|
||||
Reference in new issue
Block a user