Skip to content

Commit

Permalink
more xml.lite updates from coda-oss
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Dec 9, 2021
1 parent 1c72ba2 commit 351a45f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 42 deletions.
4 changes: 2 additions & 2 deletions externals/coda-oss/modules/c++/xml.lite/source/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ std::unique_ptr<xml::lite::Element> xml::lite::Element::createU8(const std::stri
return mem::make::unique<Element>(qname, uri, str::to_u8string(characterData));
}

xml::lite::Element::Element(const Element& node)
xml::lite::Element::Element(const xml::lite::Element& node)
{
*this = node;
}
xml::lite::Element& xml::lite::Element::operator=(const Element& node)
xml::lite::Element& xml::lite::Element::operator=(const xml::lite::Element& node)
{
if (this != &node)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "io/StringStream.h"
#include "io/FileInputStream.h"
#include "str/Convert.h"
#include "str/Encoding.h"
#include <TestCase.h>

#include "xml/lite/MinidomParser.h"
Expand Down Expand Up @@ -282,8 +283,7 @@ static void testReadEncodedXmlFile(const std::string& testName, const std::strin

std::u8string u8_characterData;
a.getCharacterData(u8_characterData);
const void* pu8_characterData = u8_characterData.c_str();
const std::string u8_characterData_(static_cast<std::string::const_pointer>(pu8_characterData));
const std::string u8_characterData_(str::c_str<std::string::const_pointer>(u8_characterData));
TEST_ASSERT_EQ(utf8Text, u8_characterData_);

}
Expand All @@ -294,13 +294,12 @@ TEST_CASE(testReadEncodedXmlFiles)
testReadEncodedXmlFile(testName, "encoding_windows-1252.xml");
}

TEST_CASE(testReadUtf8XmlFile)
static void testReadXmlFile(const std::string& testName, const std::string& xmlFile)
{
const auto coda_oss = findRoot();
const auto unittests = coda_oss / "modules" / "c++" / "xml.lite" / "unittests";

// Does NOT have "<?xml version="1.0" encoding="..." ?>"
io::FileInputStream input((unittests / "utf-8.xml").string());
io::FileInputStream input((unittests / xmlFile).string());

xml::lite::MinidomParser xmlParser(true /*storeEncoding*/);
xmlParser.preserveCharacterData(true);
Expand All @@ -320,41 +319,14 @@ TEST_CASE(testReadUtf8XmlFile)

std::u8string u8_characterData;
a.getCharacterData(u8_characterData);
const void* pu8_characterData = u8_characterData.c_str();
const std::string u8_characterData_(static_cast<std::string::const_pointer>(pu8_characterData));
TEST_ASSERT_EQ(utf8Text, u8_characterData_);
const std::string u8_characterData_(str::c_str<std::string::const_pointer>(u8_characterData));
TEST_ASSERT_EQ(utf8Text, u8_characterData_);
}

TEST_CASE(testReadWindows1252XmlFile)
TEST_CASE(testReadXmlFiles)
{
const auto coda_oss = findRoot();
const auto unittests = coda_oss / "modules" / "c++" / "xml.lite" / "unittests";

// Does NOT have "<?xml version="1.0" encoding="..." ?>"
io::FileInputStream input((unittests / "windows-1252.xml").string());

//xml::lite::MinidomParser xmlParser;
xml::lite::MinidomParser xmlParser(true /*storeEncoding*/);
xmlParser.preserveCharacterData(true);
xmlParser.parse(input);
const auto& root = getRootElement(*xmlParser.getDocument());

const auto aElements = root.getElementsByTagName("a", true /*recurse*/);
TEST_ASSERT_EQ(aElements.size(), static_cast<size_t>(1));
const auto& a = *(aElements[0]);

const auto characterData = a.getCharacterData();
TEST_ASSERT_EQ(characterData, sys::Platform == sys::PlatformType::Linux ? utf8Text : iso88591Text);
const auto encoding = a.getEncoding();
TEST_ASSERT_TRUE(encoding.has_value());
const auto expected_encoding = sys::Platform == sys::PlatformType::Linux ? xml::lite::StringEncoding::Utf8 : xml::lite::StringEncoding::Windows1252;
TEST_ASSERT(encoding.value() == expected_encoding);

std::u8string u8_characterData;
a.getCharacterData(u8_characterData);
const void* pu8_characterData = u8_characterData.c_str();
const std::string u8_characterData_(static_cast<std::string::const_pointer>(pu8_characterData));
TEST_ASSERT_EQ(utf8Text, u8_characterData_);
// These do NOT have "<?xml version="1.0" encoding="..." ?>"
testReadXmlFile(testName, "utf-8.xml");
testReadXmlFile(testName, "windows-1252.xml");
}

int main(int, char**)
Expand All @@ -372,6 +344,5 @@ int main(int, char**)
TEST_CHECK(testXmlPrintUtf8);

TEST_CHECK(testReadEncodedXmlFiles);
TEST_CHECK(testReadUtf8XmlFile);
TEST_CHECK(testReadWindows1252XmlFile);
TEST_CHECK(testReadXmlFiles);
}

0 comments on commit 351a45f

Please sign in to comment.