summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZolnai Tamás <tamas.zolnai@collabora.com>2014-12-08 03:38:36 +0100
committerZolnai Tamás <tamas.zolnai@collabora.com>2014-12-08 15:56:35 +0100
commit9ff7aac6c8f1fa6bce8df8b95f20993d789a51a7 (patch)
tree609d944461922243a9f30198f562cf6e5e2583bf
parent3650b66c366177877d30f6aae83a33bf683d3457 (diff)
Test for Writer import / export of graphic shapes
Graphic shapes are those images which are created not in Writer (but e.g. Impress, Calc) and moved to Writer later (e.g. copy&paste). Embedded image is ok, but MS filters broke the linked graphic shape. Change-Id: I0c86a5d09afb3e40f7d9e5986c05801457d4c13f
-rw-r--r--sw/CppunitTest_sw_globalfilter.mk1
-rw-r--r--sw/qa/extras/globalfilter/data/graphic_shape.odtbin0 -> 100009 bytes
-rw-r--r--sw/qa/extras/globalfilter/globalfilter.cxx90
3 files changed, 91 insertions, 0 deletions
diff --git a/sw/CppunitTest_sw_globalfilter.mk b/sw/CppunitTest_sw_globalfilter.mk
index f02bd41ef162..fd2001efadae 100644
--- a/sw/CppunitTest_sw_globalfilter.mk
+++ b/sw/CppunitTest_sw_globalfilter.mk
@@ -63,6 +63,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_globalfilter,\
forms/util/frm \
framework/util/fwk \
i18npool/util/i18npool \
+ linguistic/source/lng \
oox/util/oox \
package/source/xstor/xstor \
package/util/package2 \
diff --git a/sw/qa/extras/globalfilter/data/graphic_shape.odt b/sw/qa/extras/globalfilter/data/graphic_shape.odt
new file mode 100644
index 000000000000..425e8c2f3217
--- /dev/null
+++ b/sw/qa/extras/globalfilter/data/graphic_shape.odt
Binary files differ
diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx
index 23695a2719c5..c4b98117a1c3 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -27,11 +27,13 @@ public:
void testSwappedOutImageExport();
void testLinkedGraphicRT();
void testImageWithSpecialID();
+ void testGraphicShape();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testSwappedOutImageExport);
CPPUNIT_TEST(testLinkedGraphicRT);
CPPUNIT_TEST(testImageWithSpecialID);
+ CPPUNIT_TEST(testGraphicShape);
CPPUNIT_TEST_SUITE_END();
};
@@ -261,6 +263,94 @@ void Test::testImageWithSpecialID()
}
}
+void Test::testGraphicShape()
+{
+ // There are two kind of images in Writer: 1) Writer specific handled by SwGrfNode and
+ // 2) graphic shape handled by SdrGrafObj (e.g. after copy&paste from Impress).
+
+ const OUString aFilterNames[] = {
+ "writer8",
+ "Rich Text Format",
+ "MS Word 97",
+ "Office Open XML Text",
+ };
+
+ // Trigger swap out mechanism to test swapped state factor too.
+ boost::shared_ptr< comphelper::ConfigurationChanges > batch(comphelper::ConfigurationChanges::create());
+ officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(sal_Int32(1), batch);
+ batch->commit();
+
+ for( size_t nFilter = 0; nFilter < SAL_N_ELEMENTS(aFilterNames); ++nFilter )
+ {
+ if (mxComponent.is())
+ mxComponent->dispose();
+ mxComponent = loadFromDesktop(getURLFromSrc("/sw/qa/extras/globalfilter/data/graphic_shape.odt"), "com.sun.star.text.TextDocument");
+
+ // 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
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
+
+ const OString sFailedMessage = OString("Failed on filter: ")
+ + OUStringToOString(aFilterNames[nFilter], RTL_TEXTENCODING_ASCII_US);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(2), xDraws->getCount());
+
+ uno::Reference<drawing::XShape> xImage = getShape(1);
+ uno::Reference< beans::XPropertySet > XPropSet( xImage, uno::UNO_QUERY_THROW );
+ // First image is embedded
+ // Check URL
+ {
+ OUString sURL;
+ XPropSet->getPropertyValue("GraphicURL") >>= sURL;
+ CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), sURL != OUString("vnd.sun.star.GraphicObject:00000000000000000000000000000000"));
+ }
+ // 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 );
+ }
+
+ // MS filters make this kind of linked images broken !?
+ if( aFilterNames[nFilter] != "writer8" )
+ return;
+
+ // Second image is a linked one
+ xImage = getShape(2);
+ XPropSet.set( xImage, uno::UNO_QUERY_THROW );
+ // Check URL
+ {
+ OUString sURL;
+ XPropSet->getPropertyValue("GraphicURL") >>= sURL;
+ CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), sURL.endsWith("linked_graphic.jpg"));
+ }
+ // 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>(620), xBitmap->getSize().Width );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(465), xBitmap->getSize().Height );
+ }
+ }
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT();