Skip to content

Commit

Permalink
Add SGP4 Unit Test in prep for SGP4 code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
A-j-K committed Jul 11, 2023
1 parent 25e86b8 commit cc5590b
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
7 changes: 6 additions & 1 deletion plugins/Satellites/src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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")
41 changes: 40 additions & 1 deletion plugins/Satellites/src/test/testOMM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,43 @@ void TestOMM::testXMLread()
r.readNext();
}
file.close();
}
}

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());
}
1 change: 1 addition & 0 deletions plugins/Satellites/src/test/testOMM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private slots:
void testProcessTleLegacyLine0();
void testProcessTleLegacyLine1();
void testProcessTleLegacyLine2();
void testLegacyTleVsXML();
};

#endif // TESTOMM_HPP
46 changes: 46 additions & 0 deletions plugins/Satellites/src/test/testSGP4.cpp
Original file line number Diff line number Diff line change
@@ -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 <ios>
#include <string.h>
#include <stdlib.h>

#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);
}
33 changes: 33 additions & 0 deletions plugins/Satellites/src/test/testSGP4.hpp
Original file line number Diff line number Diff line change
@@ -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 <QtTest>

#include "gSatTEME.hpp"

class TestSGP4 : public QObject
{
Q_OBJECT
private slots:
void testSGP4();
};

#endif // TESTSGP4_HPP

0 comments on commit cc5590b

Please sign in to comment.