kill copy&paste by introducing SwModelTestBase::parseDump()
Change-Id: I7cc3e05e48fc9850fbe04c6511f5e9f18a680ec7
This commit is contained in:
@@ -45,14 +45,6 @@
|
|||||||
|
|
||||||
#include <vcl/svapp.hxx>
|
#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::OString;
|
||||||
using rtl::OUString;
|
using rtl::OUString;
|
||||||
using rtl::OUStringBuffer;
|
using rtl::OUStringBuffer;
|
||||||
@@ -568,34 +560,10 @@ void Test::testN758883()
|
|||||||
* to the numbering. This is easier to test using a layout dump.
|
* 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");
|
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
|
OUString aHeight = parseDump("/root/page/body/txt/Special", "nHeight");
|
||||||
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
|
CPPUNIT_ASSERT_EQUAL(sal_Int32(220), aHeight.toInt32()); // It was 280
|
||||||
|
|
||||||
// delete dump
|
|
||||||
xmlFreeDoc(pXmlDoc);
|
|
||||||
xmlBufferFree(pXmlBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
|
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
|
||||||
|
@@ -32,12 +32,31 @@
|
|||||||
#include <unotest/macros_test.hxx>
|
#include <unotest/macros_test.hxx>
|
||||||
#include <rtl/ustrbuf.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;
|
using namespace com::sun::star;
|
||||||
|
|
||||||
/// Base class for filter tests loading or roundtriping a document, then asserting the document model.
|
/// 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:
|
public:
|
||||||
|
SwModelTestBase()
|
||||||
|
: mpXmlBuffer(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~SwModelTestBase()
|
||||||
|
{
|
||||||
|
if (mpXmlBuffer)
|
||||||
|
xmlBufferFree(mpXmlBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
virtual void setUp()
|
virtual void setUp()
|
||||||
{
|
{
|
||||||
test::BootstrapFixture::setUp();
|
test::BootstrapFixture::setUp();
|
||||||
@@ -54,6 +73,26 @@ public:
|
|||||||
test::BootstrapFixture::tearDown();
|
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:
|
protected:
|
||||||
/// Get the length of the whole document.
|
/// Get the length of the whole document.
|
||||||
int getLength()
|
int getLength()
|
||||||
@@ -84,7 +123,27 @@ protected:
|
|||||||
return xStyleFamily;
|
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;
|
uno::Reference<lang::XComponent> mxComponent;
|
||||||
|
xmlBufferPtr mpXmlBuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -36,14 +36,6 @@
|
|||||||
|
|
||||||
#include <vcl/svapp.hxx>
|
#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::OString;
|
||||||
using rtl::OUString;
|
using rtl::OUString;
|
||||||
using rtl::OUStringBuffer;
|
using rtl::OUStringBuffer;
|
||||||
@@ -225,34 +217,10 @@ void Test::testN757905()
|
|||||||
// paragraph height. When in Word-compat mode, we should take the max of
|
// paragraph height. When in Word-compat mode, we should take the max of
|
||||||
// the two, not just the height of the fly.
|
// 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");
|
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
|
OUString aHeight = parseDump("/root/page/body/txt/infos/bounds", "height");
|
||||||
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")));
|
|
||||||
CPPUNIT_ASSERT(sal_Int32(31) < aHeight.toInt32());
|
CPPUNIT_ASSERT(sal_Int32(31) < aHeight.toInt32());
|
||||||
|
|
||||||
// delete dump
|
|
||||||
xmlFreeDoc(pXmlDoc);
|
|
||||||
xmlBufferFree(pXmlBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
|
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
|
||||||
|
Reference in New Issue
Block a user