Skip to content

Commit

Permalink
Expand Unit Tests for XML reader
Browse files Browse the repository at this point in the history
  • Loading branch information
A-j-K committed Jul 9, 2023
1 parent 773530d commit 199b2af
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 32 deletions.
3 changes: 2 additions & 1 deletion plugins/Satellites/src/omm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace PluginSatellites {

omm::omm()
omm::omm()
{
m_source_type = SourceType::Invalid;
}
Expand Down Expand Up @@ -108,6 +108,7 @@ void omm::processXmlElement(const QString & tag, const QString & val)
m_object_id = val;
}
else if (tag == "EPOCH") {
m_epoch_str = val;
m_epoch = QDateTime::fromString(val, "yyyy-MM-ddThh:mm:ss.zzzzzz");
}
else if (tag == "MEAN_MOTION") {
Expand Down
5 changes: 5 additions & 0 deletions plugins/Satellites/src/omm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class omm

virtual SourceType getSourceType() { return m_source_type; }

virtual QDateTime getEpoch() { return m_epoch; }
virtual const QString& getEpochStr() { return m_epoch_str; }
virtual double getMeanMotion() { return m_mean_motion; }
virtual double getEccentricity() { return m_eccentricity; }
virtual double getInclination() { return m_inclination; }
Expand Down Expand Up @@ -112,6 +114,9 @@ class omm
// Metadata
QString m_object_name{};
QString m_object_id{};

// Misc data.
QString m_epoch_str;
};

} // end namespace PluginSatellites
Expand Down
3 changes: 2 additions & 1 deletion plugins/Satellites/src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ SET_TARGET_PROPERTIES(testSatellites PROPERTIES FOLDER "plugins/Satellites/test"

ADD_EXECUTABLE(testOMM testOMM.cpp testOMM.hpp)
TARGET_LINK_LIBRARIES(testOMM Qt${QT_VERSION_MAJOR}::Test Satellites-static stelMain)
ADD_TEST(testOMM testOMM)
ADD_TEST(NAME OMM COMMAND testOMM)
SET_TARGET_PROPERTIES(testOMM PROPERTIES FOLDER "plugins/Satellites/test")
FILE(COPY "${CMAKE_SOURCE_DIR}/plugins/satellites/src/test/test_data.xml" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
72 changes: 42 additions & 30 deletions plugins/Satellites/src/test/testOMM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/

#include <QDir>
#include <QDebug>
#include <QVector>
#include <QDateTime>
#include "testOMM.hpp"

QTEST_GUILESS_MAIN(TestOMM)

void TestOMM::testLegacyTle()
{
QString l0("ISS");
QString l0("ISS (ZARYA)");
QString l1("1 25544U 98067A 23190.18395514 .00010525 00000-0 19463-3 0 9990");
QString l2("2 25544 51.6405 219.5048 0000226 85.5338 22.9089 15.49626907405204");
PluginSatellites::omm dut(l0, l1, l2);
Expand All @@ -33,35 +37,43 @@ void TestOMM::testLegacyTle()
QVERIFY(dut.getLine2() == l2);
}

#if 0
void TestOMM::testSpaceTrackFormattedLine2()
void TestOMM::testXMLread()
{
QString Line = "2 7530 101.7765 338.2965 0012116 317.3609 153.9519 12.53641545 65932";
QString dut = Satellites::getSatIdFromLine2(Line);
QVERIFY(!dut.isEmpty());
QVERIFY("7530" == dut);
}

void TestOMM::testNoSatDuplication()
{
QString LineA = "2 07530 101.7770 337.7317 0012122 318.4445 104.4962 12.53641440 65623";
QString LineB = "2 7530 101.7765 338.2965 0012116 317.3609 153.9519 12.53641545 65932";
QString dutA = Satellites::getSatIdFromLine2(LineA);
QString dutB = Satellites::getSatIdFromLine2(LineB);
QVERIFY(dutA == dutB);
}

void TestOMM::testSatZero()
{
QString LineA = "2 00000 101.7770 337.7317 0012122 318.4445 104.4962 12.53641440 65623";
QString LineB = "2 0 101.7765 338.2965 0012116 317.3609 153.9519 12.53641545 65932";
QString dutA = Satellites::getSatIdFromLine2(LineA);
QString dutB = Satellites::getSatIdFromLine2(LineB);
QVERIFY(!dutA.isEmpty());
QVERIFY(!dutB.isEmpty());
QVERIFY("0" == dutA);
QVERIFY("0" == dutB);
}
QVector<QString> expectOjectId = {
QString("1998-067A"),
QString("2018-046D"),
QString("1998-067RZ")
};
QVector<int> expectNorad = {
25544, 43557, 47853
};
QVector<QString> expectEpoch = {
QString("2023-07-06T08:17:36.314016"),
QString("2023-07-06T01:58:30.910944"),
QString("2023-07-04T18:34:04.881504")
};
int idx = 0;
bool testContinue = true;
bool chkTestDataFileOpened = false;
QFile file("test_data.xml");
chkTestDataFileOpened = file.open(QFile::ReadOnly | QFile::Text);
QVERIFY(true == chkTestDataFileOpened);
if (!chkTestDataFileOpened) return;

#endif
QXmlStreamReader r(&file);

while (testContinue && !r.atEnd()) {
QString tag = r.name().toString();
if (r.isStartElement() && tag.toLower() == "omm") {
PluginSatellites::omm dut(r);
QVERIFY(dut.getObjectId() == expectOjectId[idx]);
QVERIFY(dut.getNoradcatId() == expectNorad[idx]);
QVERIFY(dut.getEpochStr() == expectEpoch[idx]);
QDateTime ep = QDateTime::fromString(expectEpoch[idx]);
QVERIFY(dut.getEpoch() == ep);
idx++;
}
r.readNext();
}
file.close();
}
1 change: 1 addition & 0 deletions plugins/Satellites/src/test/testOMM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class TestOMM : public QObject
Q_OBJECT
private slots:
void testLegacyTle();
void testXMLread();
};

#endif // TESTOMM_HPP
121 changes: 121 additions & 0 deletions plugins/Satellites/src/test/test_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<ndm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://sanaregistry.org/r/ndmxml_unqualified/ndmxml-2.0.0-master-2.0.xsd">
<omm id="CCSDS_OMM_VERS" version="2.0">
<header>
<CREATION_DATE>boo</CREATION_DATE>
<ORIGINATOR/>
</header>
<body>
<segment>
<metadata>
<OBJECT_NAME>ISS (ZARYA)</OBJECT_NAME>
<OBJECT_ID>1998-067A</OBJECT_ID>
<CENTER_NAME>EARTH</CENTER_NAME>
<REF_FRAME>TEME</REF_FRAME>
<TIME_SYSTEM>UTC</TIME_SYSTEM>
<MEAN_ELEMENT_THEORY>SGP4</MEAN_ELEMENT_THEORY>
</metadata>
<data>
<meanElements>
<EPOCH>2023-07-06T08:17:36.314016</EPOCH>
<MEAN_MOTION>15.49560249</MEAN_MOTION>
<ECCENTRICITY>.0000373</ECCENTRICITY>
<INCLINATION>51.6398</INCLINATION>
<RA_OF_ASC_NODE>233.5611</RA_OF_ASC_NODE>
<ARG_OF_PERICENTER>12.3897</ARG_OF_PERICENTER>
<MEAN_ANOMALY>91.4664</MEAN_ANOMALY>
</meanElements>
<tleParameters>
<EPHEMERIS_TYPE>0</EPHEMERIS_TYPE>
<CLASSIFICATION_TYPE>U</CLASSIFICATION_TYPE>
<NORAD_CAT_ID>25544</NORAD_CAT_ID>
<ELEMENT_SET_NO>999</ELEMENT_SET_NO>
<REV_AT_EPOCH>40476</REV_AT_EPOCH>
<BSTAR>.14335E-3</BSTAR>
<MEAN_MOTION_DOT>.7611E-4</MEAN_MOTION_DOT>
<MEAN_MOTION_DDOT>0</MEAN_MOTION_DDOT>
</tleParameters>
</data>
</segment>
</body>
</omm>
<omm id="CCSDS_OMM_VERS" version="2.0">
<header>
<CREATION_DATE/>
<ORIGINATOR/>
</header>
<body>
<segment>
<metadata>
<OBJECT_NAME>AEROCUBE 12B</OBJECT_NAME>
<OBJECT_ID>2018-046D</OBJECT_ID>
<CENTER_NAME>EARTH</CENTER_NAME>
<REF_FRAME>TEME</REF_FRAME>
<TIME_SYSTEM>UTC</TIME_SYSTEM>
<MEAN_ELEMENT_THEORY>SGP4</MEAN_ELEMENT_THEORY>
</metadata>
<data>
<meanElements>
<EPOCH>2023-07-06T01:58:30.910944</EPOCH>
<MEAN_MOTION>15.80461782</MEAN_MOTION>
<ECCENTRICITY>.0001004</ECCENTRICITY>
<INCLINATION>51.6230</INCLINATION>
<RA_OF_ASC_NODE>88.3755</RA_OF_ASC_NODE>
<ARG_OF_PERICENTER>73.6173</ARG_OF_PERICENTER>
<MEAN_ANOMALY>286.4939</MEAN_ANOMALY>
</meanElements>
<tleParameters>
<EPHEMERIS_TYPE>0</EPHEMERIS_TYPE>
<CLASSIFICATION_TYPE>U</CLASSIFICATION_TYPE>
<NORAD_CAT_ID>43557</NORAD_CAT_ID>
<ELEMENT_SET_NO>999</ELEMENT_SET_NO>
<REV_AT_EPOCH>27869</REV_AT_EPOCH>
<BSTAR>.1072E-2</BSTAR>
<MEAN_MOTION_DOT>.212501E-2</MEAN_MOTION_DOT>
<MEAN_MOTION_DDOT>0</MEAN_MOTION_DDOT>
</tleParameters>
</data>
</segment>
</body>
</omm>
<omm id="CCSDS_OMM_VERS" version="2.0">
<header>
<CREATION_DATE/>
<ORIGINATOR/>
</header>
<body>
<segment>
<metadata>
<OBJECT_NAME>ISS DEB</OBJECT_NAME>
<OBJECT_ID>1998-067RZ</OBJECT_ID>
<CENTER_NAME>EARTH</CENTER_NAME>
<REF_FRAME>TEME</REF_FRAME>
<TIME_SYSTEM>UTC</TIME_SYSTEM>
<MEAN_ELEMENT_THEORY>SGP4</MEAN_ELEMENT_THEORY>
</metadata>
<data>
<meanElements>
<EPOCH>2023-07-04T18:34:04.881504</EPOCH>
<MEAN_MOTION>15.68894735</MEAN_MOTION>
<ECCENTRICITY>.0002499</ECCENTRICITY>
<INCLINATION>51.6338</INCLINATION>
<RA_OF_ASC_NODE>209.1240</RA_OF_ASC_NODE>
<ARG_OF_PERICENTER>3.3524</ARG_OF_PERICENTER>
<MEAN_ANOMALY>356.7489</MEAN_ANOMALY>
</meanElements>
<tleParameters>
<EPHEMERIS_TYPE>0</EPHEMERIS_TYPE>
<CLASSIFICATION_TYPE>U</CLASSIFICATION_TYPE>
<NORAD_CAT_ID>47853</NORAD_CAT_ID>
<ELEMENT_SET_NO>999</ELEMENT_SET_NO>
<REV_AT_EPOCH>13157</REV_AT_EPOCH>
<BSTAR>.20358E-3</BSTAR>
<MEAN_MOTION_DOT>.23368E-3</MEAN_MOTION_DOT>
<MEAN_MOTION_DDOT>0</MEAN_MOTION_DDOT>
</tleParameters>
</data>
</segment>
</body>
</omm>
</ndm>


0 comments on commit 199b2af

Please sign in to comment.