From cc5590bc116891f3ab856d56c81721b44351f2e6 Mon Sep 17 00:00:00 2001 From: A-j-K Date: Tue, 11 Jul 2023 09:58:11 +0100 Subject: [PATCH] Add SGP4 Unit Test in prep for SGP4 code refactor --- plugins/Satellites/src/test/CMakeLists.txt | 7 +++- plugins/Satellites/src/test/testOMM.cpp | 41 ++++++++++++++++++- plugins/Satellites/src/test/testOMM.hpp | 1 + plugins/Satellites/src/test/testSGP4.cpp | 46 ++++++++++++++++++++++ plugins/Satellites/src/test/testSGP4.hpp | 33 ++++++++++++++++ 5 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 plugins/Satellites/src/test/testSGP4.cpp create mode 100644 plugins/Satellites/src/test/testSGP4.hpp diff --git a/plugins/Satellites/src/test/CMakeLists.txt b/plugins/Satellites/src/test/CMakeLists.txt index 5208ce09386ef..cd55083a1918f 100644 --- a/plugins/Satellites/src/test/CMakeLists.txt +++ b/plugins/Satellites/src/test/CMakeLists.txt @@ -17,4 +17,9 @@ FILE(COPY "${CMAKE_SOURCE_DIR}/plugins/Satellites/src/test/test_data.xml" DESTIN ADD_EXECUTABLE(testOMMDateTime testOMMDateTime.cpp testOMMDateTime.hpp) TARGET_LINK_LIBRARIES(testOMMDateTime Qt${QT_VERSION_MAJOR}::Test Satellites-static stelMain) ADD_TEST(testOMMDateTime testOMMDateTime) -SET_TARGET_PROPERTIES(testOMMDateTime PROPERTIES FOLDER "plugins/Satellites/test") \ No newline at end of file +SET_TARGET_PROPERTIES(testOMMDateTime PROPERTIES FOLDER "plugins/Satellites/test") + +ADD_EXECUTABLE(testSGP4 testSGP4.cpp testSGP4.hpp) +TARGET_LINK_LIBRARIES(testSGP4 Qt${QT_VERSION_MAJOR}::Test Satellites-static stelMain) +ADD_TEST(testSGP4 testSGP4) +SET_TARGET_PROPERTIES(testSGP4 PROPERTIES FOLDER "plugins/Satellites/test") diff --git a/plugins/Satellites/src/test/testOMM.cpp b/plugins/Satellites/src/test/testOMM.cpp index 43e37611c0ca1..5041134229bd7 100644 --- a/plugins/Satellites/src/test/testOMM.cpp +++ b/plugins/Satellites/src/test/testOMM.cpp @@ -127,4 +127,43 @@ void TestOMM::testXMLread() r.readNext(); } file.close(); -} \ No newline at end of file +} + +void TestOMM::testLegacyTleVsXML() +{ + OMM::ShPtr dut_xml; + bool flag = false; + QFile file("test_data.xml"); + flag = file.open(QFile::ReadOnly | QFile::Text); + QVERIFY(true == flag); + if (!flag) + return; + QXmlStreamReader r(&file); + flag = true; + while (flag && !r.atEnd()) { + QString tag = r.name().toString(); + if (r.isStartElement() && tag.toLower() == "omm") { + dut_xml = OMM::ShPtr(new OMM(r)); + QVERIFY(dut_xml->getObjectId() == "1998-067A"); + flag = false; + } + r.readNext(); + } + file.close(); + + QString l0("ISS (ZARYA)"); + // 1 2 3 4 5 6 7 + // 01234567890123456789012345678901234567890123456789012345678901234567890 + QString l1("1 25544U 98067A 23191.40640406 .00007611 00000+0 14335-3 0 9995"); + QString l2("2 25544 51.6398 233.5611 0000373 12.3897 91.4664 15.49560249404764"); + OMM::ShPtr dut_tle(new OMM(l0, l1, l2)); + QVERIFY(dut_tle->getObjectName() == "ISS (ZARYA)"); + QCOMPARE(dut_xml->getInclination(), dut_tle->getInclination()); + QCOMPARE(dut_xml->getAscendingNode(), dut_tle->getAscendingNode()); + QCOMPARE(dut_xml->getArgumentOfPerigee(), dut_tle->getArgumentOfPerigee()); + QCOMPARE(dut_xml->getEccentricity(), dut_tle->getEccentricity()); + QCOMPARE(dut_xml->getMeanAnomoly(), dut_tle->getMeanAnomoly()); + QCOMPARE(dut_xml->getMeanMotion(), dut_tle->getMeanMotion()); + QCOMPARE(dut_xml->getRevAtEpoch(), dut_tle->getRevAtEpoch()); + QCOMPARE(dut_xml->getEpoch()->getJulian(), dut_tle->getEpoch()->getJulian()); +} diff --git a/plugins/Satellites/src/test/testOMM.hpp b/plugins/Satellites/src/test/testOMM.hpp index ebbe38a08b712..78b10e0030263 100644 --- a/plugins/Satellites/src/test/testOMM.hpp +++ b/plugins/Satellites/src/test/testOMM.hpp @@ -33,6 +33,7 @@ private slots: void testProcessTleLegacyLine0(); void testProcessTleLegacyLine1(); void testProcessTleLegacyLine2(); + void testLegacyTleVsXML(); }; #endif // TESTOMM_HPP diff --git a/plugins/Satellites/src/test/testSGP4.cpp b/plugins/Satellites/src/test/testSGP4.cpp new file mode 100644 index 0000000000000..4917c78ac72e3 --- /dev/null +++ b/plugins/Satellites/src/test/testSGP4.cpp @@ -0,0 +1,46 @@ +/* + * Stellarium + * Copyright (C) 2023 Andy Kirkham + * + * This program 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 2 + * of the License, or (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. + */ + +#include +#include +#include + +#include "VecMath.hpp" +#include "testSGP4.hpp" + +QTEST_GUILESS_MAIN(TestSGP4) + +void TestSGP4::testSGP4() +{ + const char *l0 = "ISS (ZARYA)"; + const char *l1 = "1 25544U 98067A 23191.40640406 .00007611 00000+0 14335-3 0 9995"; + const char *l2 = "2 25544 51.6398 233.5611 0000373 12.3897 91.4664 15.49560249404764"; + char *l1c, *l2c; + l1c = strdup(l1); + l2c = strdup(l2); + gSatTEME sat(l0, l1c, l2c); + Vec3d pos = sat.getPos(); + Vec3d vel = sat.getVel(); + + QCOMPARE(pos.toString(), "[4259.68, -1120.18, 5166.77]"); + QCOMPARE(vel.toString(), "[3.50308, 6.662, -1.43989]"); + + free(l1c); + free(l2c); +} diff --git a/plugins/Satellites/src/test/testSGP4.hpp b/plugins/Satellites/src/test/testSGP4.hpp new file mode 100644 index 0000000000000..2f3973ca36aa5 --- /dev/null +++ b/plugins/Satellites/src/test/testSGP4.hpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2023 Andy Kirkham + * + * This program 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 2 + * of the License, or (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. + */ + +#ifndef TESTSGP4_HPP +#define TESTSGP4_HPP + +#include + +#include "gSatTEME.hpp" + +class TestSGP4 : public QObject +{ + Q_OBJECT +private slots: + void testSGP4(); +}; + +#endif // TESTSGP4_HPP