[Libreoffice-commits] core.git: include/unotest sw/qa unotest/source

László Németh laszlo.nemeth at collabora.com
Mon Mar 30 03:34:48 PDT 2015


 include/unotest/macros_test.hxx                |    3 -
 sw/qa/extras/globalfilter/data/skipimages.doc  |binary
 sw/qa/extras/globalfilter/data/skipimages.docx |binary
 sw/qa/extras/globalfilter/globalfilter.cxx     |   72 +++++++++++++++++++++++++
 unotest/source/cpp/macros_test.cxx             |   15 ++++-
 5 files changed, 88 insertions(+), 2 deletions(-)

New commits:
commit 6ec9e87ced60add494f8d397017f8f9ffc65a00a
Author: László Németh <laszlo.nemeth at collabora.com>
Date:   Mon Mar 30 12:24:28 2015 +0200

    Unit tests for SkipImages
    
    SkipImages filter option skips image loading during DOC and DOCX
    imports, but it keeps the text of textboxes and custom shapes.
    
    Change-Id: Ia0ab3b350b9da22d9375787883678cc357a704b3

diff --git a/include/unotest/macros_test.hxx b/include/unotest/macros_test.hxx
index 12108ba..ae006fc 100644
--- a/include/unotest/macros_test.hxx
+++ b/include/unotest/macros_test.hxx
@@ -27,7 +27,8 @@ namespace unotest {
 class OOO_DLLPUBLIC_UNOTEST MacrosTest
 {
 public:
-    css::uno::Reference< css::lang::XComponent > loadFromDesktop(const OUString& rURL, const OUString& rDocService = OUString() );
+    css::uno::Reference< css::lang::XComponent > loadFromDesktop(const OUString& rURL, const OUString& rDocService = OUString(),
+        css::uno::Sequence<css::beans::PropertyValue> extra_args = css::uno::Sequence<css::beans::PropertyValue>() );
 
 protected:
     css::uno::Reference< css::frame::XDesktop2> mxDesktop;
diff --git a/sw/qa/extras/globalfilter/data/skipimages.doc b/sw/qa/extras/globalfilter/data/skipimages.doc
new file mode 100644
index 0000000..3c40599
Binary files /dev/null and b/sw/qa/extras/globalfilter/data/skipimages.doc differ
diff --git a/sw/qa/extras/globalfilter/data/skipimages.docx b/sw/qa/extras/globalfilter/data/skipimages.docx
new file mode 100644
index 0000000..cc6a4f4
Binary files /dev/null and b/sw/qa/extras/globalfilter/data/skipimages.docx differ
diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx
index c0c5191..2e95927a 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -33,6 +33,7 @@ public:
     void testCharHighlightBody();
     void testMSCharBackgroundEditing();
     void testCharBackgroundToHighlighting();
+    void testSkipImages();
 
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(testSwappedOutImageExport);
@@ -42,6 +43,7 @@ public:
     CPPUNIT_TEST(testCharHighlight);
     CPPUNIT_TEST(testMSCharBackgroundEditing);
     CPPUNIT_TEST(testCharBackgroundToHighlighting);
+    CPPUNIT_TEST(testSkipImages);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -653,6 +655,76 @@ void Test::testCharBackgroundToHighlighting()
     }
 }
 
+void Test::testSkipImages()
+{
+    // Check how LO skips image loading (but not texts of textboxes and custom shapes)
+    // during DOC and DOCX import, using the "SkipImages" FilterOptions.
+
+    const char* aFilterNames[][2] = {
+        { "/sw/qa/extras/globalfilter/data/skipimages.doc", "" },
+        { "/sw/qa/extras/globalfilter/data/skipimages.doc", "SkipImages" },
+        { "/sw/qa/extras/globalfilter/data/skipimages.docx", "" },
+        { "/sw/qa/extras/globalfilter/data/skipimages.docx", "SkipImages" }
+    };
+
+    // FilterOptions parameter (Value will be set before loadFromDesktop call)
+
+    uno::Sequence<beans::PropertyValue> args(1);
+    args[0].Name = "FilterOptions";
+    args[0].Handle = -1;
+    args[0].State = beans::PropertyState_DIRECT_VALUE;
+
+    for( size_t nFilter = 0; nFilter < SAL_N_ELEMENTS(aFilterNames); ++nFilter )
+    {
+        bool bSkipImages = *(aFilterNames[nFilter][1]) != '\0';
+
+        if (mxComponent.is())
+            mxComponent->dispose();
+
+        args[0].Value <<= OUString::createFromAscii(aFilterNames[nFilter][1]);
+
+        mxComponent = loadFromDesktop(getURLFromSrc(aFilterNames[nFilter][0]), "com.sun.star.text.TextDocument", args);
+
+        // Check shapes (images, textboxes, custom shapes
+        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: ") + aFilterNames[nFilter][0] + " - " + aFilterNames[nFilter][1];
+
+        uno::Reference<drawing::XShape> xShape;
+        uno::Reference<graphic::XGraphic> xGraphic;
+        uno::Reference< beans::XPropertySet > XPropSet;
+        uno::Reference<awt::XBitmap> xBitmap;
+
+        bool bHasTextboxText = false;
+        bool bHasCustomShapeText = false;
+        sal_Int32 nImageCount = 0;
+
+        for (int i = 1; i<= xDraws->getCount(); i++)
+        {
+            xShape = getShape(i);
+            XPropSet.set( xShape, uno::UNO_QUERY_THROW );
+            try
+            {
+                XPropSet->getPropertyValue("Graphic") >>= xGraphic;
+                xBitmap.set(xGraphic, uno::UNO_QUERY);
+                if (xBitmap.is()) nImageCount++;
+            }
+            catch (beans::UnknownPropertyException &)
+            {
+                uno::Reference<text::XTextRange> xText(xShape, uno::UNO_QUERY);
+                if (xText->getString().startsWith("Lorem ipsum")) bHasTextboxText = true;
+                if (xText->getString().startsWith("Nam pretium")) bHasCustomShapeText = true;
+            }
+        }
+
+        CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), bHasTextboxText);
+        CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), bHasCustomShapeText);
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(bSkipImages ? 0 : 3), nImageCount );
+    }
+}
+
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/unotest/source/cpp/macros_test.cxx b/unotest/source/cpp/macros_test.cxx
index 44f0d56..02b14ba 100644
--- a/unotest/source/cpp/macros_test.cxx
+++ b/unotest/source/cpp/macros_test.cxx
@@ -19,7 +19,7 @@ using namespace css;
 
 namespace unotest {
 
-uno::Reference<css::lang::XComponent> MacrosTest::loadFromDesktop(const OUString& rURL, const OUString& rDocService)
+uno::Reference<css::lang::XComponent> MacrosTest::loadFromDesktop(const OUString& rURL, const OUString& rDocService, uno::Sequence<beans::PropertyValue> extraArgs)
 {
     CPPUNIT_ASSERT_MESSAGE("no desktop", mxDesktop.is());
     uno::Reference<frame::XComponentLoader> xLoader = uno::Reference<frame::XComponentLoader>(mxDesktop, uno::UNO_QUERY);
@@ -39,6 +39,19 @@ uno::Reference<css::lang::XComponent> MacrosTest::loadFromDesktop(const OUString
         args[1].State = beans::PropertyState_DIRECT_VALUE;
     }
 
+    if (extraArgs.getLength() > 0)
+    {
+        sal_Int32 aSize = args.getLength();
+        args.realloc(aSize + extraArgs.getLength());
+        for (int i = 0; i < extraArgs.getLength(); i++)
+        {
+            args[aSize + i].Name = extraArgs[i].Name;
+            args[aSize + i].Handle = extraArgs[i].Handle;
+            args[aSize + i].Value = extraArgs[i].Value;
+            args[aSize + i].State = extraArgs[i].State;
+        }
+    }
+
     uno::Reference<lang::XComponent> xComponent = xLoader->loadComponentFromURL(rURL, OUString("_default"), 0, args);
     OUString sMessage = "loading failed: " + rURL;
     CPPUNIT_ASSERT_MESSAGE(OUStringToOString( sMessage, RTL_TEXTENCODING_UTF8 ).getStr( ), xComponent.is());


More information about the Libreoffice-commits mailing list