Skip to content

Commit a52c50c

Browse files
committed
Add SGP4 Unit Test in prep for SGP4 code refactor
1 parent ae60bb9 commit a52c50c

File tree

5 files changed

+126
-2
lines changed

5 files changed

+126
-2
lines changed

plugins/Satellites/src/test/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ FILE(COPY "${CMAKE_SOURCE_DIR}/plugins/Satellites/src/test/test_data.xml" DESTIN
1717
ADD_EXECUTABLE(testOMMDateTime testOMMDateTime.cpp testOMMDateTime.hpp)
1818
TARGET_LINK_LIBRARIES(testOMMDateTime Qt${QT_VERSION_MAJOR}::Test Satellites-static stelMain)
1919
ADD_TEST(testOMMDateTime testOMMDateTime)
20-
SET_TARGET_PROPERTIES(testOMMDateTime PROPERTIES FOLDER "plugins/Satellites/test")
20+
SET_TARGET_PROPERTIES(testOMMDateTime PROPERTIES FOLDER "plugins/Satellites/test")
21+
22+
ADD_EXECUTABLE(testSGP4 testSGP4.cpp testSGP4.hpp)
23+
TARGET_LINK_LIBRARIES(testSGP4 Qt${QT_VERSION_MAJOR}::Test Satellites-static stelMain)
24+
ADD_TEST(testSGP4 testSGP4)
25+
SET_TARGET_PROPERTIES(testSGP4 PROPERTIES FOLDER "plugins/Satellites/test")

plugins/Satellites/src/test/testOMM.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,43 @@ void TestOMM::testXMLread()
127127
r.readNext();
128128
}
129129
file.close();
130-
}
130+
}
131+
132+
void TestOMM::testLegacyTleVsXML()
133+
{
134+
OMM::ShPtr dut_xml;
135+
bool flag = false;
136+
QFile file("test_data.xml");
137+
flag = file.open(QFile::ReadOnly | QFile::Text);
138+
QVERIFY(true == flag);
139+
if (!flag)
140+
return;
141+
QXmlStreamReader r(&file);
142+
flag = true;
143+
while (flag && !r.atEnd()) {
144+
QString tag = r.name().toString();
145+
if (r.isStartElement() && tag.toLower() == "omm") {
146+
dut_xml = OMM::ShPtr(new OMM(r));
147+
QVERIFY(dut_xml->getObjectId() == "1998-067A");
148+
flag = false;
149+
}
150+
r.readNext();
151+
}
152+
file.close();
153+
154+
QString l0("ISS (ZARYA)");
155+
// 1 2 3 4 5 6 7
156+
// 01234567890123456789012345678901234567890123456789012345678901234567890
157+
QString l1("1 25544U 98067A 23191.40640406 .00007611 00000+0 14335-3 0 9995");
158+
QString l2("2 25544 51.6398 233.5611 0000373 12.3897 91.4664 15.49560249404764");
159+
OMM::ShPtr dut_tle(new OMM(l0, l1, l2));
160+
QVERIFY(dut_tle->getObjectName() == "ISS (ZARYA)");
161+
QCOMPARE(dut_xml->getInclination(), dut_tle->getInclination());
162+
QCOMPARE(dut_xml->getAscendingNode(), dut_tle->getAscendingNode());
163+
QCOMPARE(dut_xml->getArgumentOfPerigee(), dut_tle->getArgumentOfPerigee());
164+
QCOMPARE(dut_xml->getEccentricity(), dut_tle->getEccentricity());
165+
QCOMPARE(dut_xml->getMeanAnomoly(), dut_tle->getMeanAnomoly());
166+
QCOMPARE(dut_xml->getMeanMotion(), dut_tle->getMeanMotion());
167+
QCOMPARE(dut_xml->getRevAtEpoch(), dut_tle->getRevAtEpoch());
168+
QCOMPARE(dut_xml->getEpoch()->getJulian(), dut_tle->getEpoch()->getJulian());
169+
}

plugins/Satellites/src/test/testOMM.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private slots:
3333
void testProcessTleLegacyLine0();
3434
void testProcessTleLegacyLine1();
3535
void testProcessTleLegacyLine2();
36+
void testLegacyTleVsXML();
3637
};
3738

3839
#endif // TESTOMM_HPP
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Stellarium
3+
* Copyright (C) 2023 Andy Kirkham
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU General Public License
7+
* as published by the Free Software Foundation; either version 2
8+
* of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18+
*/
19+
20+
#include <ios>
21+
#include <string.h>
22+
#include <stdlib.h>
23+
24+
#include "VecMath.hpp"
25+
#include "testSGP4.hpp"
26+
27+
QTEST_GUILESS_MAIN(TestSGP4)
28+
29+
void TestSGP4::testSGP4()
30+
{
31+
const char *l0 = "ISS (ZARYA)";
32+
const char *l1 = "1 25544U 98067A 23191.40640406 .00007611 00000+0 14335-3 0 9995";
33+
const char *l2 = "2 25544 51.6398 233.5611 0000373 12.3897 91.4664 15.49560249404764";
34+
char *l1c, *l2c;
35+
l1c = strdup(l1);
36+
l2c = strdup(l2);
37+
gSatTEME sat(l0, l1c, l2c);
38+
Vec3d pos = sat.getPos();
39+
Vec3d vel = sat.getVel();
40+
41+
QCOMPARE(pos.toString(), "[4259.68, -1120.18, 5166.77]");
42+
QCOMPARE(vel.toString(), "[3.50308, 6.662, -1.43989]");
43+
44+
free(l1c);
45+
free(l2c);
46+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2023 Andy Kirkham
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; either version 2
7+
* of the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
17+
*/
18+
19+
#ifndef TESTSGP4_HPP
20+
#define TESTSGP4_HPP
21+
22+
#include <QtTest>
23+
24+
#include "gSatTEME.hpp"
25+
26+
class TestSGP4 : public QObject
27+
{
28+
Q_OBJECT
29+
private slots:
30+
void testSGP4();
31+
};
32+
33+
#endif // TESTSGP4_HPP

0 commit comments

Comments
 (0)