Kaydet (Commit) 84a7fa47 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

XmlTestTools: fix conversion from UTF-8 xmlChar strings to OUString

...which resolves the mystery of 0ba63603
"Garbage in, garbage out?"

Change-Id: I51f102699d0474872c80392b27f71030b5e3fb59
üst 180f0791
...@@ -589,12 +589,7 @@ DECLARE_OOXMLEXPORT_TEST(testDateControl, "date-control.docx") ...@@ -589,12 +589,7 @@ DECLARE_OOXMLEXPORT_TEST(testDateControl, "date-control.docx")
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date", "fullDate", "2014-03-05T00:00:00Z"); assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date", "fullDate", "2014-03-05T00:00:00Z");
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date/w:dateFormat", "val", "dddd, dd' de 'MMMM' de 'yyyy"); assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date/w:dateFormat", "val", "dddd, dd' de 'MMMM' de 'yyyy");
assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date/w:lid", "val", "es-ES"); assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:date/w:lid", "val", "es-ES");
static sal_Unicode const Broken[] = { assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", OUString::fromUtf8("mi\xC3\xA9rcoles, 05 de marzo de 2014"));
'm', 'i', static_cast<sal_Unicode>('\xC3'),
static_cast<sal_Unicode>('\xA9'), 'r', 'c', 'o', 'l', 'e', 's', ',',
' ', '0', '5', ' ', 'd', 'e', ' ', 'm', 'a', 'r', 'z', 'o', ' ', 'd',
'e', ' ', '2', '0', '1', '4' };
assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtContent/w:r/w:t", OUString(Broken, SAL_N_ELEMENTS(Broken)));
// check imported control // check imported control
uno::Reference<drawing::XControlShape> xControl(getShape(1), uno::UNO_QUERY); uno::Reference<drawing::XControlShape> xControl(getShape(1), uno::UNO_QUERY);
......
...@@ -11,6 +11,23 @@ ...@@ -11,6 +11,23 @@
#include <boost/scoped_array.hpp> #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() XmlTestTools::XmlTestTools()
{} {}
...@@ -55,7 +72,7 @@ OUString XmlTestTools::getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const ...@@ -55,7 +72,7 @@ OUString XmlTestTools::getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const
return OUString(); return OUString();
xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
xmlChar * prop = xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr())); xmlChar * prop = xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr()));
OUString s(OUString::createFromAscii((const char*)prop)); OUString s(convert(prop));
xmlFree(prop); xmlFree(prop);
xmlXPathFreeObject(pXmlObj); xmlXPathFreeObject(pXmlObj);
return s; return s;
...@@ -70,7 +87,7 @@ OUString XmlTestTools::getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath) ...@@ -70,7 +87,7 @@ OUString XmlTestTools::getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath)
xmlXPathNodeSetGetLength(pXmlNodes) > 0); xmlXPathNodeSetGetLength(pXmlNodes) > 0);
xmlNodePtr pXmlNode = pXmlNodes->nodeTab[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); xmlXPathFreeObject(pXmlObj);
return s; return s;
} }
...@@ -137,7 +154,7 @@ int XmlTestTools::getXPathPosition(xmlDocPtr pXmlDoc, const OString& rXPath, con ...@@ -137,7 +154,7 @@ int XmlTestTools::getXPathPosition(xmlDocPtr pXmlDoc, const OString& rXPath, con
int nRet = 0; int nRet = 0;
for (xmlNodePtr pChild = pXmlNode->children; pChild; pChild = pChild->next) for (xmlNodePtr pChild = pXmlNode->children; pChild; pChild = pChild->next)
{ {
if (OUString::createFromAscii((const char*)pChild->name) == rChildName) if (convert(pChild->name) == rChildName)
break; break;
++nRet; ++nRet;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment