Skip to content

Commit

Permalink
Cphd 1.1.0 fixes (#601)
Browse files Browse the repository at this point in the history
* Allow both 1 and +1 to be parsed as valid phase sign strings

* Expose version-to-uri map. Add 1.1.0 uri

* Expand xml string parsing to all supported 1.x version
  • Loading branch information
dave-starinshak authored Oct 28, 2022
1 parent c3f2794 commit 3f2dd2f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
5 changes: 2 additions & 3 deletions six/modules/c++/cphd/include/cphd/CPHDXMLControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,15 @@ class CPHDXMLControl
virtual Metadata fromXML(const xml::lite::Document& doc,
const std::vector<std::filesystem::path>& schemaPaths = std::vector<std::filesystem::path>());

//! \return Suported version to uri mapping
static std::unordered_map<std::string, xml::lite::Uri> getVersionUriMap();

protected:
logging::Logger *mLog = nullptr;
bool mOwnLog = false;
six::Logger mLogger;

private:
//! \return Hardcoded version to uri mapping
static std::unordered_map<std::string, xml::lite::Uri> getVersionUriMap();

/*!
* This function takes in a Metadata object and converts
* it to a new-allocated XML DOM.
Expand Down
1 change: 1 addition & 0 deletions six/modules/c++/cphd/include/cphd/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ SIX_Enum_BEGIN_DEFINE(PhaseSGN)
SIX_Enum_BEGIN_string_to_value
{ "-1", MINUS_1 },
{ "+1", PLUS_1 },
{ "1", PLUS_1 },
SIX_Enum_END_string_to_value
SIX_Enum_END_DEFINE(PhaseSGN);

Expand Down
3 changes: 2 additions & 1 deletion six/modules/c++/cphd/source/CPHDXMLControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ std::unordered_map<std::string, xml::lite::Uri> CPHDXMLControl::getVersionUriMap
{
return {
{"1.0.0", xml::lite::Uri("urn:CPHD:1.0.0")},
{"1.0.1", xml::lite::Uri("http://api.nsgreg.nga.mil/schema/cphd/1.0.1")}
{"1.0.1", xml::lite::Uri("http://api.nsgreg.nga.mil/schema/cphd/1.0.1")},
{"1.1.0", xml::lite::Uri("http://api.nsgreg.nga.mil/schema/cphd/1.1.0")}
};
}

Expand Down
55 changes: 45 additions & 10 deletions six/modules/c++/cphd/unittests/test_cphd_xml_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
#include <xml/lite/MinidomParser.h>
#include "TestCase.h"

const char* test_cphd_xml_control_XML =
"<CPHD xmlns=\"urn:CPHD:1.0.0\">\n"
namespace
{
std::string testCPHDXMLBody()
{
const char* xmlBody =
" <CollectionID>\n"
" <CollectorName>Collector</CollectorName>\n"
" <CoreName>Core</CoreName>\n"
Expand All @@ -48,7 +51,7 @@ const char* test_cphd_xml_control_XML =
" </CollectionID>\n"
" <Global>\n"
" <DomainType>FX</DomainType>\n"
" <SGN>+1</SGN>\n"
" <SGN>1</SGN>\n"
" <Timeline>\n"
" <CollectionStart>2013-04-10T08:52:09.000000Z</CollectionStart>\n"
" <RcvCollectionStart>2014-04-10T08:52:09.000000Z</RcvCollectionStart>\n"
Expand Down Expand Up @@ -875,13 +878,25 @@ const char* test_cphd_xml_control_XML =
" <Parameter name=\"param1\">Match1</Parameter>\n"
" </MatchCollection>\n"
" </MatchType>\n"
" </MatchInfo>\n"
"</CPHD>\n";
" </MatchInfo>\n";
return std::string(xmlBody);
}

TEST_CASE(testReadXML)
std::string testCPHDXML(const std::string& version)
{
auto uri = cphd::CPHDXMLControl::getVersionUriMap().at(version);
return "<CPHD xmlns=\""
+ uri.value
+ "\">\n"
+ testCPHDXMLBody()
+ "</CPHD>\n";
}

void runTest(const std::string& testName, const std::string& version)
{
auto xmlString = testCPHDXML(version);
io::StringStream cphdStream;
cphdStream.write(test_cphd_xml_control_XML, strlen(test_cphd_xml_control_XML));
cphdStream.write(xmlString.c_str(), xmlString.size());

xml::lite::MinidomParser xmlParser;
xmlParser.preserveCharacterData(true);
Expand Down Expand Up @@ -1136,8 +1151,28 @@ TEST_CASE(testReadXML)
TEST_ASSERT_EQ(ref.monostatic->layoverAngle, 30.0);
TEST_ASSERT_EQ(ref.monostatic->dopplerConeAngle, 30.0);
}
}

TEST_CASE(testVersions)
{
auto versionUriMap = cphd::CPHDXMLControl::getVersionUriMap();
for (auto version : {"1.0.0", "1.0.1", "1.1.0"})
{
TEST_ASSERT_TRUE(
versionUriMap.find(version) != versionUriMap.end());
}
}

TEST_CASE(testReadXML)
{
for (auto pair : cphd::CPHDXMLControl::getVersionUriMap())
{
auto& version = pair.first;
runTest("testReadXML" + version, version);
}
}

TEST_MAIN(
TEST_CHECK(testReadXML);
// TEST_CHECK(testValidation);
)
TEST_CHECK(testVersions);
TEST_CHECK(testReadXML);
)

0 comments on commit 3f2dd2f

Please sign in to comment.