Kaydet (Commit) 8070b124 authored tarafından Zolnai Tamás's avatar Zolnai Tamás

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:
9dd5caac
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.
üst 6e0761ec
# -*- 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:
......@@ -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)
......
/* -*- 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();
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