summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2012-06-21 17:03:23 +0200
committerMiklos Vajna <vmiklos@suse.cz>2012-06-21 17:17:47 +0200
commit8616f227c722affcedff7632ba97644d04427c94 (patch)
treed9ed1ca465635b798c78384fb3d5c2a45eea0146
parent4cc2c691a93ec1ada687ad49ba2dd9665d52a3a3 (diff)
kill copy&paste by introducing SwModelTestBase::parseDump()
Change-Id: I7cc3e05e48fc9850fbe04c6511f5e9f18a680ec7
-rw-r--r--sw/qa/extras/ooxmltok/ooxmltok.cxx36
-rw-r--r--sw/qa/extras/swmodeltestbase.hxx59
-rw-r--r--sw/qa/extras/ww8tok/ww8tok.cxx34
3 files changed, 62 insertions, 67 deletions
diff --git a/sw/qa/extras/ooxmltok/ooxmltok.cxx b/sw/qa/extras/ooxmltok/ooxmltok.cxx
index a34dd392f473..59e3aab1327e 100644
--- a/sw/qa/extras/ooxmltok/ooxmltok.cxx
+++ b/sw/qa/extras/ooxmltok/ooxmltok.cxx
@@ -45,14 +45,6 @@
#include <vcl/svapp.hxx>
-#include <unotxdoc.hxx>
-#include <docsh.hxx>
-#include <doc.hxx>
-#include <rootfrm.hxx>
-
-#include <libxml/xmlwriter.h>
-#include <libxml/xpath.h>
-
using rtl::OString;
using rtl::OUString;
using rtl::OUStringBuffer;
@@ -568,34 +560,10 @@ void Test::testN758883()
* to the numbering. This is easier to test using a layout dump.
*/
- // create xml writer
- xmlBufferPtr pXmlBuffer = xmlBufferCreate();
- xmlTextWriterPtr pXmlWriter = xmlNewTextWriterMemory(pXmlBuffer, 0);
- xmlTextWriterStartDocument(pXmlWriter, NULL, NULL, NULL);
-
- // create dump
load("n758883.docx");
- SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
- SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
- SwRootFrm* pLayout = pDoc->GetCurrentLayout();
- pLayout->dumpAsXml(pXmlWriter);
-
- // delete xml writer
- xmlTextWriterEndDocument(pXmlWriter);
- xmlFreeTextWriter(pXmlWriter);
-
- // parse the dump
- xmlDocPtr pXmlDoc = xmlParseMemory((const char*)xmlBufferContent(pXmlBuffer), xmlBufferLength(pXmlBuffer));;
- xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
- xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST("/root/page/body/txt/Special"), pXmlXpathCtx);
- xmlNodeSetPtr pXmlNodes = pXmlXpathObj->nodesetval;
- xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
- OUString aHeight = OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST("nHeight")));
- CPPUNIT_ASSERT_EQUAL(sal_Int32(220), aHeight.toInt32()); // It was 280
- // delete dump
- xmlFreeDoc(pXmlDoc);
- xmlBufferFree(pXmlBuffer);
+ OUString aHeight = parseDump("/root/page/body/txt/Special", "nHeight");
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(220), aHeight.toInt32()); // It was 280
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
diff --git a/sw/qa/extras/swmodeltestbase.hxx b/sw/qa/extras/swmodeltestbase.hxx
index 0ddd2266b830..669e559f8143 100644
--- a/sw/qa/extras/swmodeltestbase.hxx
+++ b/sw/qa/extras/swmodeltestbase.hxx
@@ -32,12 +32,31 @@
#include <unotest/macros_test.hxx>
#include <rtl/ustrbuf.hxx>
+#include <unotxdoc.hxx>
+#include <docsh.hxx>
+#include <doc.hxx>
+#include <rootfrm.hxx>
+
+#include <libxml/xmlwriter.h>
+#include <libxml/xpath.h>
+
using namespace com::sun::star;
/// Base class for filter tests loading or roundtriping a document, then asserting the document model.
class SwModelTestBase : public test::BootstrapFixture, public unotest::MacrosTest
{
public:
+ SwModelTestBase()
+ : mpXmlBuffer(0)
+ {
+ }
+
+ ~SwModelTestBase()
+ {
+ if (mpXmlBuffer)
+ xmlBufferFree(mpXmlBuffer);
+ }
+
virtual void setUp()
{
test::BootstrapFixture::setUp();
@@ -54,6 +73,26 @@ public:
test::BootstrapFixture::tearDown();
}
+private:
+ void dumpLayout()
+ {
+ // create the xml writer
+ mpXmlBuffer = xmlBufferCreate();
+ xmlTextWriterPtr pXmlWriter = xmlNewTextWriterMemory(mpXmlBuffer, 0);
+ xmlTextWriterStartDocument(pXmlWriter, NULL, NULL, NULL);
+
+ // create the dump
+ SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+ SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
+ SwRootFrm* pLayout = pDoc->GetCurrentLayout();
+ pLayout->dumpAsXml(pXmlWriter);
+
+ // delete xml writer
+ xmlTextWriterEndDocument(pXmlWriter);
+ xmlFreeTextWriter(pXmlWriter);
+ }
+
+
protected:
/// Get the length of the whole document.
int getLength()
@@ -84,7 +123,27 @@ protected:
return xStyleFamily;
}
+ /// Extract a value from the layout dump using an XPath expression and an attribute name.
+ rtl::OUString parseDump(rtl::OString aXPath, rtl::OString aAttribute)
+ {
+ if (!mpXmlBuffer)
+ dumpLayout();
+
+ xmlDocPtr pXmlDoc = xmlParseMemory((const char*)xmlBufferContent(mpXmlBuffer), xmlBufferLength(mpXmlBuffer));;
+
+ xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
+ xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(aXPath.getStr()), pXmlXpathCtx);
+ xmlNodeSetPtr pXmlNodes = pXmlXpathObj->nodesetval;
+ xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
+ rtl::OUString aRet = rtl::OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST(aAttribute.getStr())));
+
+ xmlFreeDoc(pXmlDoc);
+
+ return aRet;
+ }
+
uno::Reference<lang::XComponent> mxComponent;
+ xmlBufferPtr mpXmlBuffer;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/ww8tok/ww8tok.cxx b/sw/qa/extras/ww8tok/ww8tok.cxx
index a63ff1437147..53f90301e157 100644
--- a/sw/qa/extras/ww8tok/ww8tok.cxx
+++ b/sw/qa/extras/ww8tok/ww8tok.cxx
@@ -36,14 +36,6 @@
#include <vcl/svapp.hxx>
-#include <unotxdoc.hxx>
-#include <docsh.hxx>
-#include <doc.hxx>
-#include <rootfrm.hxx>
-
-#include <libxml/xmlwriter.h>
-#include <libxml/xpath.h>
-
using rtl::OString;
using rtl::OUString;
using rtl::OUStringBuffer;
@@ -225,34 +217,10 @@ void Test::testN757905()
// paragraph height. When in Word-compat mode, we should take the max of
// the two, not just the height of the fly.
- // create xml writer
- xmlBufferPtr pXmlBuffer = xmlBufferCreate();
- xmlTextWriterPtr pXmlWriter = xmlNewTextWriterMemory(pXmlBuffer, 0);
- xmlTextWriterStartDocument(pXmlWriter, NULL, NULL, NULL);
-
- // create dump
load("n757905.doc");
- SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
- SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
- SwRootFrm* pLayout = pDoc->GetCurrentLayout();
- pLayout->dumpAsXml(pXmlWriter);
- // delete xml writer
- xmlTextWriterEndDocument(pXmlWriter);
- xmlFreeTextWriter(pXmlWriter);
-
- // parse the dump
- xmlDocPtr pXmlDoc = xmlParseMemory((const char*)xmlBufferContent(pXmlBuffer), xmlBufferLength(pXmlBuffer));;
- xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc);
- xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST("/root/page/body/txt/infos/bounds"), pXmlXpathCtx);
- xmlNodeSetPtr pXmlNodes = pXmlXpathObj->nodesetval;
- xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
- OUString aHeight = OUString::createFromAscii((const char*)xmlGetProp(pXmlNode, BAD_CAST("height")));
+ OUString aHeight = parseDump("/root/page/body/txt/infos/bounds", "height");
CPPUNIT_ASSERT(sal_Int32(31) < aHeight.toInt32());
-
- // delete dump
- xmlFreeDoc(pXmlDoc);
- xmlBufferFree(pXmlBuffer);
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);