summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx22
-rw-r--r--sw/qa/extras/inc/swmodeltestbase.hxx107
2 files changed, 7 insertions, 122 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 4e42cb417e95..8d73286c62a0 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -18,12 +18,11 @@
#include <swmodule.hxx>
#include <usrpref.hxx>
-#include <libxml/HTMLparser.h>
-#include <libxml/HTMLtree.h>
+#include <test/htmltesttools.hxx>
using namespace rtl;
-class Test : public SwModelTestBase
+class Test : public SwModelTestBase, public HtmlTestTools
{
private:
FieldUnit m_eUnit;
@@ -34,19 +33,6 @@ public:
m_eUnit(FUNIT_NONE)
{}
-protected:
- htmlDocPtr parseHtml()
- {
- SvFileStream aFileStream(m_aTempFile.GetURL(), STREAM_READ);
- sal_Size nSize = aFileStream.remainingSize();
-
- ByteSequence aBuffer(nSize + 1);
- aFileStream.Read(aBuffer.getArray(), nSize);
-
- aBuffer[nSize] = 0;
- return htmlParseDoc(reinterpret_cast<xmlChar*>(aBuffer.getArray()), NULL);
- }
-
private:
bool mustCalcLayoutOf(const char* filename) SAL_OVERRIDE
{
@@ -119,7 +105,7 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testCharacterBorder, "charborder.odt")
DECLARE_HTMLEXPORT_TEST(testExportOfImages, "textAndImage.docx")
{
- htmlDocPtr pDoc = parseHtml();
+ htmlDocPtr pDoc = parseHtml(m_aTempFile);
if (pDoc)
{
assertXPath(pDoc, "/html/body", 1);
@@ -129,7 +115,7 @@ DECLARE_HTMLEXPORT_TEST(testExportOfImages, "textAndImage.docx")
DECLARE_HTMLEXPORT_TEST(testExportOfImagesWithSkipImageEnabled, "textAndImage.docx")
{
- htmlDocPtr pDoc = parseHtml();
+ htmlDocPtr pDoc = parseHtml(m_aTempFile);
if (pDoc)
{
assertXPath(pDoc, "/html/body", 1);
diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index 7a2cf9a438a5..6c5236a6543f 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -22,6 +22,7 @@
#include <com/sun/star/table/BorderLine2.hpp>
#include <test/bootstrapfixture.hxx>
+#include <test/xmltesttools.hxx>
#include <unotest/macros_test.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <rtl/strbuf.hxx>
@@ -36,11 +37,6 @@
#include <doc.hxx>
#include <rootfrm.hxx>
-#include <libxml/xmlwriter.h>
-#include <libxml/xpath.h>
-#include <libxml/xpathInternals.h>
-#include <libxml/parserInternals.h>
-
using namespace css;
#define DEFAULT_STYLE "Default Style"
@@ -114,7 +110,7 @@ using namespace css;
void TestName::verify()
/// Base class for filter tests loading or roundtriping a document, then asserting the document model.
-class SwModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest
+class SwModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools
{
OUString maFilterOptions;
protected:
@@ -586,9 +582,8 @@ protected:
/**
* Helper method to return nodes represented by rXPath.
*/
- xmlNodeSetPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath)
+ virtual void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx)
{
- xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w"), BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("v"), BAD_CAST("urn:schemas-microsoft-com:vml"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("mc"), BAD_CAST("http://schemas.openxmlformats.org/markup-compatibility/2006"));
@@ -604,102 +599,6 @@ protected:
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("ContentType"), BAD_CAST("http://schemas.openxmlformats.org/package/2006/content-types"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("lc"), BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("extended-properties"), BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"));
- xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(rXPath.getStr()), pXmlXpathCtx);
- return pXmlXpathObj->nodesetval;
- }
-
- /**
- * Same as the assertXPath(), but don't assert: return the string instead.
- */
- OUString getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute)
- {
- xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
- 1, xmlXPathNodeSetGetLength(pXmlNodes));
- if (rAttribute.isEmpty())
- return OUString();
- xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
- return OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr())));
- }
-
- /**
- * Same as the assertXPathContent(), but don't assert: return the string instead.
- */
- OUString getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath)
- {
- xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
-
- CPPUNIT_ASSERT_MESSAGE(OString("XPath '" + rXPath + "' not found").getStr(),
- xmlXPathNodeSetGetLength(pXmlNodes) > 0);
-
- xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
- return OUString::createFromAscii((const char*)((pXmlNode->children[0]).content));
- }
-
- /**
- * Assert that rXPath exists, and returns exactly one node.
- * In case rAttribute is provided, the rXPath's attribute's value must
- * equal to the rExpected value.
- */
- void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute = OString(), const OUString& rExpectedValue = OUString())
- {
- OUString aValue = getXPath(pXmlDoc, rXPath, rAttribute);
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("Attribute '" + rAttribute + "' of '" + rXPath + "' incorrect value.").getStr(),
- rExpectedValue, aValue);
- }
-
- /**
- * Assert that rXPath exists, and returns exactly nNumberOfNodes nodes.
- * Useful for checking that we do _not_ export some node (nNumberOfNodes == 0).
- */
- void assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfNodes)
- {
- xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
- nNumberOfNodes, xmlXPathNodeSetGetLength(pXmlNodes));
- }
-
- /**
- * Assert that rXPath exists, and its content equals rContent.
- */
- void assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rContent)
- {
- CPPUNIT_ASSERT_EQUAL_MESSAGE("XPath contents of child does not match", rContent, getXPathContent(pXmlDoc, rXPath));
- }
-
- /**
- * Assert that rXPath exists, and has exactly nNumberOfChildNodes child nodes.
- * Useful for checking that we do have a no child nodes to a specific node (nNumberOfChildNodes == 0).
- */
- void assertXPathChildren(xmlDocPtr pXmlDoc, const OString& rXPath, int nNumberOfChildNodes)
- {
- xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
- 1, xmlXPathNodeSetGetLength(pXmlNodes));
- xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of child-nodes is incorrect").getStr(),
- nNumberOfChildNodes, (int)xmlChildElementCount(pXmlNode));
- }
-
- /**
- * Get the position of the child named rName of the parent node specified by rXPath.
- * Useful for checking relative order of elements.
- */
- int getXPathPosition(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rChildName)
- {
- xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("XPath '" + rXPath + "' number of nodes is incorrect").getStr(),
- 1,
- xmlXPathNodeSetGetLength(pXmlNodes));
- xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
- int nRet = 0;
- for (xmlNodePtr pChild = pXmlNode->children; pChild; pChild = pChild->next)
- {
- if (OUString::createFromAscii((const char*)pChild->name) == rChildName)
- break;
- ++nRet;
- }
- return nRet;
}
uno::Reference<lang::XComponent> mxComponent;