diff options
author | Zolnai Tamás <tamas.zolnai@collabora.com> | 2014-10-27 09:41:00 +0100 |
---|---|---|
committer | Zolnai Tamás <tamas.zolnai@collabora.com> | 2014-11-07 10:45:08 +0100 |
commit | 8070b12454718d33d4452bb090f40ce8c629ca2c (patch) | |
tree | 649949a4d572bafc31e2555a0c8eb1a0f90f2422 /sw | |
parent | 6e0761ec54c12f1d8fd4391e9e87f805d39cce30 (diff) |
Test for swapped out image loss during Writer export
Related to the bug fdo#52226. The fix in *.rtf and *.docx
export was this commit:
9dd5caac62083f7162d83319284df68ee83e3777
The problem was that the images were somehow swapped out but
were not swapped in during export.
Test the main Writer formats: ODT, RTF, DOC, DOCX.
Diffstat (limited to 'sw')
-rw-r--r-- | sw/CppunitTest_sw_globalfilter.mk | 90 | ||||
-rw-r--r-- | sw/Module_sw.mk | 1 | ||||
-rw-r--r-- | sw/qa/extras/globalfilter/data/document_with_an_image.odt | bin | 0 -> 98949 bytes | |||
-rw-r--r-- | sw/qa/extras/globalfilter/globalfilter.cxx | 110 |
4 files changed, 201 insertions, 0 deletions
diff --git a/sw/CppunitTest_sw_globalfilter.mk b/sw/CppunitTest_sw_globalfilter.mk new file mode 100644 index 000000000000..96787c0d6064 --- /dev/null +++ b/sw/CppunitTest_sw_globalfilter.mk @@ -0,0 +1,90 @@ +# -*- 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/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,sw_globalfilter)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sw_globalfilter, \ + sw/qa/extras/globalfilter/globalfilter \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sw_globalfilter, \ + comphelper \ + cppu \ + cppuhelper \ + sal \ + sw \ + test \ + tl \ + unotest \ + utl \ + vcl \ + $(gb_UWINAPI) \ +)) + +$(eval $(call gb_CppunitTest_use_externals,sw_globalfilter,\ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_set_include,sw_globalfilter,\ + -I$(SRCDIR)/sw/inc \ + -I$(SRCDIR)/sw/source/core/inc \ + -I$(SRCDIR)/sw/qa/extras/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_api,sw_globalfilter,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,sw_globalfilter)) +$(eval $(call gb_CppunitTest_use_vcl,sw_globalfilter)) + +$(eval $(call gb_CppunitTest_use_components,sw_globalfilter,\ + basic/util/sb \ + comphelper/util/comphelp \ + configmgr/source/configmgr \ + dbaccess/util/dba \ + drawinglayer/drawinglayer \ + embeddedobj/util/embobj \ + filter/source/config/cache/filterconfig1 \ + filter/source/storagefilterdetect/storagefd \ + filter/source/textfilterdetect/textfd \ + forms/util/frm \ + framework/util/fwk \ + i18npool/util/i18npool \ + oox/util/oox \ + package/source/xstor/xstor \ + package/util/package2 \ + sax/source/expatwrap/expwrap \ + sfx2/util/sfx \ + svl/source/fsstor/fsstorage \ + svtools/util/svt \ + sw/util/msword \ + sw/util/sw \ + sw/util/swd \ + toolkit/util/tk \ + ucb/source/core/ucb1 \ + ucb/source/ucp/file/ucpfile1 \ + unotools/util/utl \ + unoxml/source/service/unoxml \ + uui/util/uui \ + $(if $(filter DESKTOP,$(BUILD_TYPE)),xmlhelp/util/ucpchelp1) \ + writerfilter/util/writerfilter \ + xmloff/util/xo \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,sw_globalfilter)) + +$(eval $(call gb_CppunitTest_use_unittest_configuration,sw_globalfilter)) + +# vim: set noet sw=4 ts=4: diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk index b5809c2a7599..a7a31efbab44 100644 --- a/sw/Module_sw.mk +++ b/sw/Module_sw.mk @@ -68,6 +68,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\ CppunitTest_sw_odfimport \ CppunitTest_sw_uiwriter \ CppunitTest_sw_mailmerge \ + CppunitTest_sw_globalfilter \ )) ifneq ($(DISABLE_CVE_TESTS),TRUE) diff --git a/sw/qa/extras/globalfilter/data/document_with_an_image.odt b/sw/qa/extras/globalfilter/data/document_with_an_image.odt Binary files differnew file mode 100644 index 000000000000..ce7a29ab3161 --- /dev/null +++ b/sw/qa/extras/globalfilter/data/document_with_an_image.odt diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx new file mode 100644 index 000000000000..b31afe3a46b0 --- /dev/null +++ b/sw/qa/extras/globalfilter/globalfilter.cxx @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <swmodeltestbase.hxx> + +#include <com/sun/star/awt/XBitmap.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> + +#include <unotxdoc.hxx> +#include <docsh.hxx> +#include <doc.hxx> +#include <ndgrf.hxx> + +class Test : public SwModelTestBase +{ +public: + Test() : SwModelTestBase() {} + + void testSwappedOutImageExport(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testSwappedOutImageExport); + CPPUNIT_TEST_SUITE_END(); +}; + +void Test::testSwappedOutImageExport() +{ + std::vector<OUString> aFilterNames = { + "writer8", + "Rich Text Format", + "MS Word 97", + "Office Open XML Text", + }; + + for( size_t nFilter = 0; nFilter < aFilterNames.size(); ++nFilter ) + { + // Check whether the export code swaps in the image which was swapped out before. + if (mxComponent.is()) + mxComponent->dispose(); + mxComponent = loadFromDesktop(getURLFromSrc("/sw/qa/extras/globalfilter/data/document_with_an_image.odt"), "com.sun.star.text.TextDocument"); + + const OString sFailedMessage = OString("Failed on filter: ") + + OUStringToOString(aFilterNames[nFilter], RTL_TEXTENCODING_ASCII_US); + SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get()); + CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pTxtDoc); + SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc(); + CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pDoc); + SwNodes& aNodes = pDoc->GetNodes(); + + // Find and swap out the image + bool bImageFound = false; + for( sal_uLong nIndex = 0; nIndex < aNodes.Count(); ++nIndex) + { + if( aNodes[nIndex]->IsGrfNode() ) + { + SwGrfNode* pGrfNode = aNodes[nIndex]->GetGrfNode(); + pGrfNode->SwapOut(); + bImageFound = true; + } + } + CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), bImageFound); + + // Export the document and import again for a check + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= aFilterNames[nFilter]; + + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + uno::Reference< lang::XComponent > xComponent(xStorable, uno::UNO_QUERY); + xComponent->dispose(); + mxComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument"); + + // Check whether graphic exported well after it was swapped out + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(1), xDraws->getCount()); + + uno::Reference<drawing::XShape> xImage(xDraws->getByIndex(0), uno::UNO_QUERY); + uno::Reference< beans::XPropertySet > XPropSet( xImage, uno::UNO_QUERY_THROW ); + // Check URL + { + OUString sURL; + XPropSet->getPropertyValue("GraphicURL") >>= sURL; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + sFailedMessage.getStr(), OUString("vnd.sun.star.GraphicObject:10000000000002620000017D9F4CD7A2"), sURL); + } + // Check size + { + uno::Reference<graphic::XGraphic> xGraphic; + XPropSet->getPropertyValue("Graphic") >>= xGraphic; + uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY); + CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is()); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(610), xBitmap->getSize().Width ); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(381), xBitmap->getSize().Height ); + } + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +CPPUNIT_PLUGIN_IMPLEMENT(); |