[Libreoffice-commits] core.git: 2 commits - sw/qa
Miklos Vajna
vmiklos at suse.cz
Thu Jul 18 03:55:30 PDT 2013
sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 155 ++++++++++---------------------
1 file changed, 51 insertions(+), 104 deletions(-)
New commits:
commit 3083cadd7a88f4d839f01d3f282af2909efc93bd
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Thu Jul 18 12:52:25 2013 +0200
merge more copypaste into assertXPath()
Change-Id: I8ee063454e6de98ed134877d6298b6a772cf1e7a
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index f7bd4ae..ea46058 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -113,6 +113,7 @@ private:
* xml stream, so that you can do the asserting.
*/
xmlDocPtr parseExport();
+ void assertXPath(xmlDocPtr pXmlDoc, OString aXPath, OString aAttribute, OUString aExpectedValue);
};
void Test::run()
@@ -217,6 +218,18 @@ xmlDocPtr Test::parseExport()
return xmlParseMemory((const char*)aDocument.getStr(), aDocument.getLength());
}
+void Test::assertXPath(xmlDocPtr pXmlDoc, OString aXPath, OString aAttribute, OUString aExpectedValue)
+{
+ xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
+ xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w"), BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main"));
+ xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(aXPath.getStr()), pXmlXpathCtx);
+ xmlNodeSetPtr pXmlNodes = pXmlXpathObj->nodesetval;
+ CPPUNIT_ASSERT_EQUAL(1, xmlXPathNodeSetGetLength(pXmlNodes));
+ xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
+ OUString aValue = OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(aAttribute.getStr())));
+ CPPUNIT_ASSERT_EQUAL(aExpectedValue, aValue);
+}
+
void Test::testZoom()
{
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
@@ -653,17 +666,7 @@ void Test::testCellBtlr()
*/
xmlDocPtr pXmlDoc = parseExport();
-
- xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
- xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w"), BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main"));
- OString aXPath = "/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:textDirection";
- xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(aXPath.getStr()), pXmlXpathCtx);
- xmlNodeSetPtr pXmlNodes = pXmlXpathObj->nodesetval;
- CPPUNIT_ASSERT_EQUAL(1, xmlXPathNodeSetGetLength(pXmlNodes));
- xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
- OString aAttribute = "val";
- OUString aValue = OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(aAttribute.getStr())));
- CPPUNIT_ASSERT_EQUAL(OUString("btLr"), aValue);
+ assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:textDirection", "val", "btLr");
}
void Test::testTableStylerPrSz()
@@ -989,49 +992,15 @@ void Test::testPageBorderSpacingExportCase2()
*/
xmlDocPtr pXmlDoc = parseExport();
- xmlXPathContextPtr pXmlXpathContext;
- OString aXPath;
- xmlXPathObjectPtr pXmlXpathObj;
- xmlNodeSetPtr pXmlNodes;
- xmlNodePtr pXmlNode;
- OString aAttributeName;
- OUString aAttributeValue;
// Assert the XPath expression - page borders
- pXmlXpathContext = xmlXPathNewContext(pXmlDoc);
- xmlXPathRegisterNs(pXmlXpathContext, BAD_CAST("w"), BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main"));
- aXPath = "/w:document/w:body/w:sectPr/w:pgBorders";
- pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(aXPath.getStr()), pXmlXpathContext);
- pXmlNodes = pXmlXpathObj->nodesetval;
- CPPUNIT_ASSERT_EQUAL(1, xmlXPathNodeSetGetLength(pXmlNodes));
- pXmlNode = pXmlNodes->nodeTab[0];
- aAttributeName = "offsetFrom";
- aAttributeValue = OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(aAttributeName.getStr())));
- CPPUNIT_ASSERT_EQUAL(OUString("page"), aAttributeValue);
+ assertXPath(pXmlDoc, "/w:document/w:body/w:sectPr/w:pgBorders", "offsetFrom", "page");
// Assert the XPath expression - 'left' border
- pXmlXpathContext = xmlXPathNewContext(pXmlDoc);
- xmlXPathRegisterNs(pXmlXpathContext, BAD_CAST("w"), BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main"));
- aXPath = "/w:document/w:body/w:sectPr/w:pgBorders/w:left";
- pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(aXPath.getStr()), pXmlXpathContext);
- pXmlNodes = pXmlXpathObj->nodesetval;
- CPPUNIT_ASSERT_EQUAL(1, xmlXPathNodeSetGetLength(pXmlNodes));
- pXmlNode = pXmlNodes->nodeTab[0];
- aAttributeName = "space";
- aAttributeValue = OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(aAttributeName.getStr())));
- CPPUNIT_ASSERT_EQUAL(OUString("24"), aAttributeValue);
+ assertXPath(pXmlDoc, "/w:document/w:body/w:sectPr/w:pgBorders/w:left", "space", "24");
// Assert the XPath expression - 'right' border
- pXmlXpathContext = xmlXPathNewContext(pXmlDoc);
- xmlXPathRegisterNs(pXmlXpathContext, BAD_CAST("w"), BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main"));
- aXPath = "/w:document/w:body/w:sectPr/w:pgBorders/w:right";
- pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(aXPath.getStr()), pXmlXpathContext);
- pXmlNodes = pXmlXpathObj->nodesetval;
- CPPUNIT_ASSERT_EQUAL(1, xmlXPathNodeSetGetLength(pXmlNodes));
- pXmlNode = pXmlNodes->nodeTab[0];
- aAttributeName = "space";
- aAttributeValue = OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(aAttributeName.getStr())));
- CPPUNIT_ASSERT_EQUAL(OUString("24"), aAttributeValue);
+ assertXPath(pXmlDoc, "/w:document/w:body/w:sectPr/w:pgBorders/w:right", "space", "24");
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
commit 4210c68f7504a9cfb2272781956355679888fc18
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Thu Jul 18 12:37:13 2013 +0200
merge copypaste into parseExport()
Change-Id: I5a680e3853d2411b00de1e286fce08d30b368ad7
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 9778100..f7bd4ae 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -106,6 +106,13 @@ public:
private:
void run();
+ /**
+ * Given that some problem doesn't affect the result in the importer, we
+ * test the resulting file directly, by opening the zip file, parsing an
+ * xml stream, and asserting an XPath expression. This method returns the
+ * xml stream, so that you can do the asserting.
+ */
+ xmlDocPtr parseExport();
};
void Test::run()
@@ -185,6 +192,31 @@ void Test::run()
}
}
+xmlDocPtr Test::parseExport()
+{
+ // Create the zip file.
+ utl::TempFile aTempFile;
+ save("Office Open XML Text", aTempFile);
+
+ // Read the XML stream we're interested in.
+ uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), aTempFile.GetURL());
+ uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName("word/document.xml"), uno::UNO_QUERY);
+ boost::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, sal_True));
+ pStream->Seek(STREAM_SEEK_TO_END);
+ sal_Size nSize = pStream->Tell();
+ pStream->Seek(0);
+ OStringBuffer aDocument(nSize);
+ char ch;
+ for (sal_Size i = 0; i < nSize; ++i)
+ {
+ *pStream >> ch;
+ aDocument.append(ch);
+ }
+
+ // Parse the XML.
+ return xmlParseMemory((const char*)aDocument.getStr(), aDocument.getLength());
+}
+
void Test::testZoom()
{
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
@@ -618,36 +650,10 @@ void Test::testCellBtlr()
* The problem was that the exporter didn't mirror the workaround of the
* importer, regarding the btLr text direction: the <w:textDirection
* w:val="btLr"/> token was completely missing in the output.
- *
- * Given that this doesn't affect the result in the importer, we test the
- * resulting file directly, by opening the zip file, parsing an xml stream,
- * and asserting an XPath expression. This can be extracted to a helper
- * method, once it's clear what is common in such tests.
*/
- // Create the zip file.
- utl::TempFile aTempFile;
- save("Office Open XML Text", aTempFile);
+ xmlDocPtr pXmlDoc = parseExport();
- // Read the XML stream we're interested in.
- uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), aTempFile.GetURL());
- uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName("word/document.xml"), uno::UNO_QUERY);
- boost::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, sal_True));
- pStream->Seek(STREAM_SEEK_TO_END);
- sal_Size nSize = pStream->Tell();
- pStream->Seek(0);
- OStringBuffer aDocument(nSize);
- char ch;
- for (sal_Size i = 0; i < nSize; ++i)
- {
- *pStream >> ch;
- aDocument.append(ch);
- }
-
- // Parse the XML.
- xmlDocPtr pXmlDoc = xmlParseMemory((const char*)aDocument.getStr(), aDocument.getLength());
-
- // Assert the XPath expression.
xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w"), BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main"));
OString aXPath = "/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:textDirection";
@@ -980,34 +986,9 @@ void Test::testPageBorderSpacingExportCase2()
*
* The exporter ALWAYS exported 'w:offsetFrom="text"' even when the spacing values where too large
* for Word to handle (larger than 31 points)
- *
- * Given that this doesn't affect the result in the importer, we test the
- * resulting file directly, by opening the zip file, parsing an xml stream,
- * and asserting an XPath expression. This can be extracted to a helper
- * method, once it's clear what is common in such tests.
*/
- // Create the zip file
- utl::TempFile aTempFile;
- save("Office Open XML Text", aTempFile);
-
- // Read the XML stream we're interested in
- uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), aTempFile.GetURL());
- uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName("word/document.xml"), uno::UNO_QUERY);
- boost::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, sal_True));
- pStream->Seek(STREAM_SEEK_TO_END);
- sal_Size nSize = pStream->Tell();
- pStream->Seek(0);
- OStringBuffer aDocument(nSize);
-
- char ch;
- for (sal_Size i = 0; i < nSize; ++i)
- {
- *pStream >> ch;
- aDocument.append(ch);
- }
-
- xmlDocPtr pXmlDoc;
+ xmlDocPtr pXmlDoc = parseExport();
xmlXPathContextPtr pXmlXpathContext;
OString aXPath;
xmlXPathObjectPtr pXmlXpathObj;
@@ -1016,9 +997,6 @@ void Test::testPageBorderSpacingExportCase2()
OString aAttributeName;
OUString aAttributeValue;
- // Parse the XML
- pXmlDoc = xmlParseMemory((const char*)aDocument.getStr(), aDocument.getLength());
-
// Assert the XPath expression - page borders
pXmlXpathContext = xmlXPathNewContext(pXmlDoc);
xmlXPathRegisterNs(pXmlXpathContext, BAD_CAST("w"), BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main"));
More information about the Libreoffice-commits
mailing list