summaryrefslogtreecommitdiff
path: root/sw/qa/extras/globalfilter
diff options
context:
space:
mode:
authorZolnai Tamás <tamas.zolnai@collabora.com>2014-10-27 09:41:00 +0100
committerZolnai Tamás <tamas.zolnai@collabora.com>2014-11-07 10:45:08 +0100
commit8070b12454718d33d4452bb090f40ce8c629ca2c (patch)
tree649949a4d572bafc31e2555a0c8eb1a0f90f2422 /sw/qa/extras/globalfilter
parent6e0761ec54c12f1d8fd4391e9e87f805d39cce30 (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/qa/extras/globalfilter')
-rw-r--r--sw/qa/extras/globalfilter/data/document_with_an_image.odtbin0 -> 98949 bytes
-rw-r--r--sw/qa/extras/globalfilter/globalfilter.cxx110
2 files changed, 110 insertions, 0 deletions
diff --git a/sw/qa/extras/globalfilter/data/document_with_an_image.odt b/sw/qa/extras/globalfilter/data/document_with_an_image.odt
new file mode 100644
index 000000000000..ce7a29ab3161
--- /dev/null
+++ b/sw/qa/extras/globalfilter/data/document_with_an_image.odt
Binary files differ
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();