diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-04-29 15:07:54 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-04-29 23:57:33 +0200 |
commit | dde833575e29afecb6b053d3be28d9d028a72bef (patch) | |
tree | d63db949265ca1577dfbcb416299033ac3b92d6e /sw/qa/extras/inc | |
parent | de9ebbaddcb9633380e6614d7e70c1007d3be1c1 (diff) |
tests: add XML and HTML test tools to test module
XML and HTML parsing and XPath asserts are used by many test in
sw, sc and sd modules. This commit moves this functionallity to
test module, where it is available to all modules.
Change-Id: I53ad9c45b24f4c9bf106cb58ea619002968bfeda
Diffstat (limited to 'sw/qa/extras/inc')
-rw-r--r-- | sw/qa/extras/inc/swmodeltestbase.hxx | 107 |
1 files changed, 3 insertions, 104 deletions
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; |