diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-12-18 12:30:30 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-12-18 12:34:40 +0100 |
commit | 84a7fa47a548e95892797e9f61d96ae051123121 (patch) | |
tree | 1443c5e55b937b3cec3ba52b6e2dd217866b0bd8 /test | |
parent | 180f0791daa3d3f959f4f70b9f83012bcbf47a64 (diff) |
XmlTestTools: fix conversion from UTF-8 xmlChar strings to OUString
...which resolves the mystery of 0ba6360363fb73b5b200bbc486ed8eeac5f3d337
"Garbage in, garbage out?"
Change-Id: I51f102699d0474872c80392b27f71030b5e3fb59
Diffstat (limited to 'test')
-rw-r--r-- | test/source/xmltesttools.cxx | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/test/source/xmltesttools.cxx b/test/source/xmltesttools.cxx index 32908a068699..4694570226b6 100644 --- a/test/source/xmltesttools.cxx +++ b/test/source/xmltesttools.cxx @@ -11,6 +11,23 @@ #include <boost/scoped_array.hpp> +namespace { + +OUString convert(xmlChar const * string) { + OUString s; + CPPUNIT_ASSERT_MESSAGE( + "xmlChar string is not UTF-8", + rtl_convertStringToUString( + &s.pData, reinterpret_cast<char const *>(string), xmlStrlen(string), + RTL_TEXTENCODING_UTF8, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR))); + return s; +} + +} + XmlTestTools::XmlTestTools() {} @@ -55,7 +72,7 @@ OUString XmlTestTools::getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const return OUString(); xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; xmlChar * prop = xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr())); - OUString s(OUString::createFromAscii((const char*)prop)); + OUString s(convert(prop)); xmlFree(prop); xmlXPathFreeObject(pXmlObj); return s; @@ -70,7 +87,7 @@ OUString XmlTestTools::getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath) xmlXPathNodeSetGetLength(pXmlNodes) > 0); xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; - OUString s(OUString::createFromAscii((const char*)((pXmlNode->children[0]).content))); + OUString s(convert((pXmlNode->children[0]).content)); xmlXPathFreeObject(pXmlObj); return s; } @@ -137,7 +154,7 @@ int XmlTestTools::getXPathPosition(xmlDocPtr pXmlDoc, const OString& rXPath, con int nRet = 0; for (xmlNodePtr pChild = pXmlNode->children; pChild; pChild = pChild->next) { - if (OUString::createFromAscii((const char*)pChild->name) == rChildName) + if (convert(pChild->name) == rChildName) break; ++nRet; } |