Kaydet (Commit) 2efee3c6 authored tarafından Miklos Vajna's avatar Miklos Vajna

CppunitTest_sw_ooxmlexport: factor out drawing-related testcases

As a start, moved 30 asserts to the new suite, still 378 is in the
original one.

Change-Id: I934bce63e286af3080ae014c3bd8f4f09866feb2
üst f7857265
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
# #
#************************************************************************* #*************************************************************************
include $(SRCDIR)/sw/ooxmlexport_setup.mk
$(eval $(call gb_CppunitTest_CppunitTest,sw_ooxmlexport)) $(eval $(call gb_CppunitTest_CppunitTest,sw_ooxmlexport))
$(eval $(call gb_CppunitTest_add_exception_objects,sw_ooxmlexport, \ $(eval $(call gb_CppunitTest_add_exception_objects,sw_ooxmlexport, \
...@@ -16,17 +18,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sw_ooxmlexport, \ ...@@ -16,17 +18,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sw_ooxmlexport, \
)) ))
$(eval $(call gb_CppunitTest_use_libraries,sw_ooxmlexport, \ $(eval $(call gb_CppunitTest_use_libraries,sw_ooxmlexport, \
comphelper \ $(sw_ooxmlexport_libraries) \
cppu \
cppuhelper \
sal \
sw \
test \
tl \
unotest \
utl \
vcl \
$(gb_UWINAPI) \
)) ))
$(eval $(call gb_CppunitTest_use_externals,sw_ooxmlexport,\ $(eval $(call gb_CppunitTest_use_externals,sw_ooxmlexport,\
...@@ -49,40 +41,7 @@ $(eval $(call gb_CppunitTest_use_api,sw_ooxmlexport,\ ...@@ -49,40 +41,7 @@ $(eval $(call gb_CppunitTest_use_api,sw_ooxmlexport,\
$(eval $(call gb_CppunitTest_use_ure,sw_ooxmlexport)) $(eval $(call gb_CppunitTest_use_ure,sw_ooxmlexport))
$(eval $(call gb_CppunitTest_use_components,sw_ooxmlexport,\ $(eval $(call gb_CppunitTest_use_components,sw_ooxmlexport,\
basic/util/sb \ $(sw_ooxmlexport_components) \
canvas/source/factory/canvasfactory \
chart2/source/chartcore \
chart2/source/controller/chartcontroller \
comphelper/util/comphelp \
configmgr/source/configmgr \
drawinglayer/drawinglayer \
embeddedobj/util/embobj \
filter/source/config/cache/filterconfig1 \
forms/util/frm \
framework/util/fwk \
i18npool/util/i18npool \
linguistic/source/lng \
oox/util/oox \
package/source/xstor/xstor \
package/util/package2 \
sax/source/expatwrap/expwrap \
sw/util/sw \
sw/util/swd \
sw/util/msword \
sfx2/util/sfx \
starmath/util/sm \
svl/source/fsstor/fsstorage \
svtools/util/svt \
svx/util/svx \
svx/util/svxcore \
toolkit/util/tk \
ucb/source/core/ucb1 \
ucb/source/ucp/file/ucpfile1 \
unotools/util/utl \
unoxml/source/service/unoxml \
uui/util/uui \
writerfilter/util/writerfilter \
xmloff/util/xo \
)) ))
$(eval $(call gb_CppunitTest_use_configuration,sw_ooxmlexport)) $(eval $(call gb_CppunitTest_use_configuration,sw_ooxmlexport))
......
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#*************************************************************************
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#*************************************************************************
include $(SRCDIR)/sw/ooxmlexport_setup.mk
$(eval $(call gb_CppunitTest_CppunitTest,sw_ooxmlsdrexport))
$(eval $(call gb_CppunitTest_add_exception_objects,sw_ooxmlsdrexport, \
sw/qa/extras/ooxmlexport/ooxmlsdrexport \
))
$(eval $(call gb_CppunitTest_use_libraries,sw_ooxmlsdrexport, \
$(sw_ooxmlexport_libraries) \
))
$(eval $(call gb_CppunitTest_use_externals,sw_ooxmlsdrexport,\
boost_headers \
libxml2 \
))
$(eval $(call gb_CppunitTest_set_include,sw_ooxmlsdrexport,\
-I$(SRCDIR)/sw/inc \
-I$(SRCDIR)/sw/source/core/inc \
-I$(SRCDIR)/sw/qa/extras/inc \
$$(INCLUDE) \
))
$(eval $(call gb_CppunitTest_use_api,sw_ooxmlsdrexport,\
offapi \
udkapi \
))
$(eval $(call gb_CppunitTest_use_ure,sw_ooxmlsdrexport))
$(eval $(call gb_CppunitTest_use_components,sw_ooxmlsdrexport,\
$(sw_ooxmlexport_components) \
))
$(eval $(call gb_CppunitTest_use_configuration,sw_ooxmlsdrexport))
$(eval $(call gb_CppunitTest_use_unittest_configuration,sw_ooxmlsdrexport))
# vim: set noet sw=4 ts=4:
...@@ -54,6 +54,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\ ...@@ -54,6 +54,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
CppunitTest_sw_htmlexport \ CppunitTest_sw_htmlexport \
CppunitTest_sw_macros_test \ CppunitTest_sw_macros_test \
CppunitTest_sw_ooxmlexport \ CppunitTest_sw_ooxmlexport \
CppunitTest_sw_ooxmlsdrexport \
CppunitTest_sw_ooxmlimport \ CppunitTest_sw_ooxmlimport \
CppunitTest_sw_ww8export \ CppunitTest_sw_ww8export \
CppunitTest_sw_ww8import \ CppunitTest_sw_ww8import \
......
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#*************************************************************************
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#*************************************************************************
define sw_ooxmlexport_libraries
comphelper \
cppu \
cppuhelper \
sal \
sw \
test \
tl \
unotest \
utl \
vcl \
$(gb_UWINAPI)
endef
define sw_ooxmlexport_components
basic/util/sb \
canvas/source/factory/canvasfactory \
chart2/source/chartcore \
chart2/source/controller/chartcontroller \
comphelper/util/comphelp \
configmgr/source/configmgr \
drawinglayer/drawinglayer \
embeddedobj/util/embobj \
filter/source/config/cache/filterconfig1 \
forms/util/frm \
framework/util/fwk \
i18npool/util/i18npool \
linguistic/source/lng \
oox/util/oox \
package/source/xstor/xstor \
package/util/package2 \
sax/source/expatwrap/expwrap \
sw/util/sw \
sw/util/swd \
sw/util/msword \
sfx2/util/sfx \
starmath/util/sm \
svl/source/fsstor/fsstorage \
svtools/util/svt \
svx/util/svx \
svx/util/svxcore \
toolkit/util/tk \
ucb/source/core/ucb1 \
ucb/source/ucp/file/ucpfile1 \
unotools/util/utl \
unoxml/source/service/unoxml \
uui/util/uui \
writerfilter/util/writerfilter \
xmloff/util/xo
endef
# vim: set noet sw=4 ts=4:
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <com/sun/star/container/XContentEnumerationAccess.hpp> #include <com/sun/star/container/XContentEnumerationAccess.hpp>
#include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/style/XAutoStylesSupplier.hpp> #include <com/sun/star/style/XAutoStylesSupplier.hpp>
#include <com/sun/star/style/XAutoStyleFamily.hpp> #include <com/sun/star/style/XAutoStyleFamily.hpp>
...@@ -22,6 +23,8 @@ ...@@ -22,6 +23,8 @@
#include <test/bootstrapfixture.hxx> #include <test/bootstrapfixture.hxx>
#include <unotest/macros_test.hxx> #include <unotest/macros_test.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/ustrbuf.hxx> #include <rtl/ustrbuf.hxx>
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <unotools/tempfile.hxx> #include <unotools/tempfile.hxx>
...@@ -33,10 +36,13 @@ ...@@ -33,10 +36,13 @@
#include <libxml/xmlwriter.h> #include <libxml/xmlwriter.h>
#include <libxml/xpath.h> #include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h>
using namespace com::sun::star; using namespace com::sun::star;
#define DEFAULT_STYLE "Default Style" #define DEFAULT_STYLE "Default Style"
#define EMU_TO_MM100(EMU) (EMU / 360)
/** /**
* Macro to declare a new test (with full round-trip. To test * Macro to declare a new test (with full round-trip. To test
...@@ -487,6 +493,129 @@ protected: ...@@ -487,6 +493,129 @@ protected:
return xCursor->getPage(); return xCursor->getPage();
} }
/**
* 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(const OUString& rStreamName = OUString("word/document.xml"))
{
if (!m_bExported)
return 0;
// Read the XML stream we're interested in.
uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), m_aTempFile.GetURL());
uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName(rStreamName), uno::UNO_QUERY);
boost::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, 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->ReadChar( ch );
aDocument.append(ch);
}
// Parse the XML.
return xmlParseMemory((const char*)aDocument.getStr(), aDocument.getLength());
}
/**
* Helper method to return nodes represented by rXPath.
*/
xmlNodeSetPtr getXPathNode(xmlDocPtr pXmlDoc, const OString& rXPath)
{
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"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("wps"), BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingShape"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("wpg"), BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("wp"), BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("wp14"), BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("a"), BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/main"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("pic"), BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/picture"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("rels"), BAD_CAST("http://schemas.openxmlformats.org/package/2006/relationships"));
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w14"), BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordml"));
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())));
}
/**
* 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 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; uno::Reference<lang::XComponent> mxComponent;
xmlBufferPtr mpXmlBuffer; xmlBufferPtr mpXmlBuffer;
const char* mpTestDocumentPath; const char* mpTestDocumentPath;
......
This diff is collapsed.
...@@ -56,12 +56,10 @@ ...@@ -56,12 +56,10 @@
#include <unotools/fltrcfg.hxx> #include <unotools/fltrcfg.hxx>
#include <comphelper/sequenceashashmap.hxx> #include <comphelper/sequenceashashmap.hxx>
#include <com/sun/star/text/GraphicCrop.hpp> #include <com/sun/star/text/GraphicCrop.hpp>
#include <swtypes.hxx>
#include <bordertest.hxx> #include <bordertest.hxx>
#define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
#define EMU_TO_MM100(EMU) (EMU / 360)
class Test : public SwModelTestBase class Test : public SwModelTestBase
{ {
public: public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment