Skip to content

Commit

Permalink
Merge branch 'master' into develop/update-externals
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed May 13, 2022
2 parents 0ea5f7f + 8566cbf commit 73d646f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# SIX Release Notes

## Version 3.1.11; ??? ?, 2022
* Lastest [coda-oss](https://github.com/mdaus/coda-oss) and [nitro](https://github.com/mdaus/nitro) (updates from **master**, no new releases)
* Fix bug in XML serializaton where `double`s were given a class of `xs::double` (two `:`s) instead of `xs:double`.

## Version 3.1.10; May 3, 2022
* [coda-oss](https://github.com/mdaus/coda-oss) version [2022-05-03](https://github.com/mdaus/coda-oss/releases/tag/2022-05-03)
* [nitro](https://github.com/mdaus/nitro) version [2.10.9](https://github.com/mdaus/nitro/releases/tag/NITRO-2.10.9)
Expand Down
15 changes: 14 additions & 1 deletion six/modules/c++/six/source/XMLControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,20 @@ std::unique_ptr<Data> XMLControl::fromXML(const xml::lite::Document& doc,

std::string XMLControl::dataTypeToString(DataType dataType, bool appendXML)
{
std::string str = dataType;
std::string str;
switch (dataType)
{
case DataType::COMPLEX:
str = "SICD";
break;
case DataType::DERIVED:
str = "SIDD";
break;
default:
throw except::Exception(
Ctxt("Invalid data type " + str::toString(dataType)));
}

if (appendXML)
{
str += "_XML";
Expand Down
4 changes: 2 additions & 2 deletions six/modules/c++/six/source/XmlLite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ xml::lite::Element& XmlLite::createInt_(const std::string& name, int p, xml::lit
xml::lite::Element& XmlLite::createDouble(const xml::lite::QName& name, double p, xml::lite::Element& parent) const
{
p = value(p); // be sure this is initialized; throws if not
return createValue(name, p, parent, mAddClassAttributes, "xs::double", getDefaultURI());
return createValue(name, p, parent, mAddClassAttributes, "xs:double", getDefaultURI());
}
xml::lite::Element& XmlLite::createDouble(const xml::lite::QName& name, const std::optional<double>& p, xml::lite::Element& parent) const
{
Expand All @@ -274,7 +274,7 @@ xml::lite::Element* XmlLite::createOptionalDouble(const std::string& name, doubl
}
xml::lite::Element* XmlLite::createOptionalDouble(const xml::lite::QName& name, const std::optional<double>& p, xml::lite::Element& parent) const
{
return createOptionalValue(name, p, parent, mAddClassAttributes, "xs::double", getDefaultURI());
return createOptionalValue(name, p, parent, mAddClassAttributes, "xs:double", getDefaultURI());
}
xml::lite::Element* XmlLite::createOptionalDouble(const std::string& name, const std::optional<double>& p, xml::lite::Element& parent) const
{
Expand Down
56 changes: 55 additions & 1 deletion six/modules/c++/six/unittests/test_xml_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <six/XMLControl.h>
#include <string>
#include <vector>

#include "six/XmlLite.h"

#include "TestCase.h"

namespace fs = std::filesystem;
Expand Down Expand Up @@ -96,9 +99,60 @@ TEST_CASE(ignoreEmptyEnvVariable)
}
}

TEST_MAIN(
TEST_CASE(dataTypeToString)
{
std::string result = six::XMLControl::dataTypeToString(six::DataType::COMPLEX);
TEST_ASSERT_EQ("SICD_XML", result);

result = six::XMLControl::dataTypeToString(six::DataType::DERIVED, false /*appendXML*/);
TEST_ASSERT_EQ("SIDD", result);

// Generate a garbage value to test the exception. Have to hack-things-up
// because there are overloads on six::DataType for integer assignment.
auto dataType = six::DataType::COMPLEX;
void* pDataType = &dataType;
int* pIntDataType = static_cast<int*>(pDataType);
*pIntDataType = 999; // bypass overloads; should now be a garbage value
TEST_ASSERT_NOT_EQ(dataType, six::DataType::COMPLEX);
TEST_ASSERT_NOT_EQ(dataType, six::DataType::DERIVED);
TEST_EXCEPTION(six::XMLControl::dataTypeToString(dataType)); // the "default:" case label will throw, as desired
}

TEST_CASE(testXmlLiteAttributeClass)
{
six::XmlLite xmlLite(xml::lite::Uri("urn:example.com"), true /*addClassAttributes*/);
auto root = xmlLite.newElement("root", nullptr /*prnt*/);

{
auto& e = xmlLite.createDouble("double", 3.14, *root);
const auto& attrib = e.attribute("class");
TEST_ASSERT_EQ(attrib, "xs:double");
}
{
auto& e = xmlLite.createInt("int", 314, *root);
const auto& attrib = e.attribute("class");
TEST_ASSERT_EQ(attrib, "xs:int");
}
{
auto& e = xmlLite.createString("string", "abc", *root);
const auto& attrib = e.attribute("class");
TEST_ASSERT_EQ(attrib, "xs:string");
}
{
auto* e = xmlLite.createBooleanType(xml::lite::QName("Boolean"), six::BooleanType::IS_TRUE, *root);
const auto& attrib = e->attribute("class");
TEST_ASSERT_EQ(attrib, "xs:boolean");
}

// TODO: xs:date, xs:dateTime
}


TEST_MAIN((void)argv; (void)argc;
TEST_CHECK(loadCompiledSchemaPath);
TEST_CHECK(respectGivenPaths);
TEST_CHECK(loadFromEnvVariable);
TEST_CHECK(ignoreEmptyEnvVariable);
TEST_CHECK(dataTypeToString);
TEST_CHECK(testXmlLiteAttributeClass);
)

0 comments on commit 73d646f

Please sign in to comment.