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

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Tue May 15 23:37:09 UTC 2018


 sw/qa/extras/globalfilter/globalfilter.cxx |   76 +++++++++++++----------------
 1 file changed, 35 insertions(+), 41 deletions(-)

New commits:
commit b2b1d0a4c4ffcba0e32e5909a61de43eeaf98c25
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue May 15 22:16:53 2018 +0900

    sw: improvements of globalfilter test
    
    - check if linked graphic is registered in LinkManager
    - remove setting of graphic cache size as it doesn't have any
      effect anymore
    - improve asserts for Graphic / XGraphic objects
    
    Change-Id: I97e2772e2a8209ff61975c273ec27401c3e7a976
    Reviewed-on: https://gerrit.libreoffice.org/54373
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx
index 2145eb9fde55..eab2037d697e 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -12,10 +12,11 @@
 #include <com/sun/star/awt/XBitmap.hpp>
 #include <com/sun/star/graphic/XGraphic.hpp>
 #include <com/sun/star/graphic/GraphicType.hpp>
-#include <officecfg/Office/Common.hxx>
+#include <sfx2/linkmgr.hxx>
 #include <comphelper/propertysequence.hxx>
 #include <unotxdoc.hxx>
 #include <docsh.hxx>
+#include <editsh.hxx>
 #include <IDocumentRedlineAccess.hxx>
 #include <IDocumentContentOperations.hxx>
 #include <doc.hxx>
@@ -30,7 +31,7 @@ class Test : public SwModelTestBase
 public:
     Test() : SwModelTestBase() {}
 
-    void testSwappedOutImageExport();
+    void testEmbeddedGraphicRoundtrip();
     void testLinkedGraphicRT();
     void testImageWithSpecialID();
     void testGraphicShape();
@@ -45,7 +46,7 @@ public:
     void testRedlineFlags();
 
     CPPUNIT_TEST_SUITE(Test);
-    CPPUNIT_TEST(testSwappedOutImageExport);
+    CPPUNIT_TEST(testEmbeddedGraphicRoundtrip);
     CPPUNIT_TEST(testLinkedGraphicRT);
     CPPUNIT_TEST(testImageWithSpecialID);
     CPPUNIT_TEST(testGraphicShape);
@@ -60,7 +61,7 @@ public:
     CPPUNIT_TEST_SUITE_END();
 };
 
-void Test::testSwappedOutImageExport()
+void Test::testEmbeddedGraphicRoundtrip()
 {
     const char* aFilterNames[] = {
         "writer8",
@@ -73,11 +74,6 @@ void Test::testSwappedOutImageExport()
     {
         // Check whether the export code swaps in the image which was swapped out before by auto mechanism
 
-        // Set cache size to a very small value to make sure one of the images is swapped out
-        std::shared_ptr< comphelper::ConfigurationChanges > batch(comphelper::ConfigurationChanges::create());
-        officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(static_cast<sal_Int32>(1), batch);
-        batch->commit();
-
         if (mxComponent.is())
             mxComponent->dispose();
         mxComponent = loadFromDesktop(m_directories.getURLFromSrc("/sw/qa/extras/globalfilter/data/document_with_two_images.odt"), "com.sun.star.text.TextDocument");
@@ -110,12 +106,12 @@ void Test::testSwappedOutImageExport()
         {
             uno::Reference<graphic::XGraphic> xGraphic;
             XPropSet->getPropertyValue("Graphic") >>= xGraphic;
-            CPPUNIT_ASSERT(xGraphic.is());
-            CPPUNIT_ASSERT(xGraphic->getType() != graphic::GraphicType::EMPTY);
+            CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), graphic::GraphicType::PIXEL, xGraphic->getType());
             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_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);
         }
 
         // Second Image
@@ -126,12 +122,12 @@ void Test::testSwappedOutImageExport()
         {
             uno::Reference<graphic::XGraphic> xGraphic;
             XPropSet->getPropertyValue("Graphic") >>= xGraphic;
-            CPPUNIT_ASSERT(xGraphic.is());
-            CPPUNIT_ASSERT(xGraphic->getType() != graphic::GraphicType::EMPTY);
+            CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), graphic::GraphicType::PIXEL, xGraphic->getType());
             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>(900), xBitmap->getSize().Width );
-            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(600), xBitmap->getSize().Height );
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(900), xBitmap->getSize().Width);
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(600), xBitmap->getSize().Height);
         }
     }
 }
@@ -176,6 +172,7 @@ void Test::testLinkedGraphicRT()
 
         // Find the image
         bool bImageFound = false;
+        Graphic aGraphic;
         for( sal_uLong nIndex = 0; nIndex < aNodes.Count(); ++nIndex)
         {
             if( aNodes[nIndex]->IsGrfNode() )
@@ -184,13 +181,20 @@ void Test::testLinkedGraphicRT()
                 CPPUNIT_ASSERT(pGrfNode);
 
                 const GraphicObject& rGraphicObj = pGrfNode->GetGrfObj(true);
-                const Graphic& rGraphic = rGraphicObj.GetGraphic();
-                CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), int(GraphicType::Bitmap), int(rGraphic.GetType()));
-                CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_uLong(864900), rGraphic.GetSizeBytes());
+                aGraphic = rGraphicObj.GetGraphic();
                 bImageFound = true;
             }
         }
         CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), bImageFound);
+
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), GraphicType::Bitmap, aGraphic.GetType());
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_uLong(864900), aGraphic.GetSizeBytes());
+
+        // Check if linked graphic is registered in LinkManager
+        sfx2::LinkManager& rLinkManager = pTextDoc->GetDocShell()->GetDoc()->GetEditShell()->GetLinkManager();
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), size_t(1), rLinkManager.GetLinks().size());
+        const tools::SvRef<sfx2::SvBaseLink> & rLink = rLinkManager.GetLinks()[0];
+        CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), rLink->GetLinkSourceName().indexOf("linked_graphic.jpg") >= 0);
     }
 }
 
@@ -206,11 +210,6 @@ void Test::testImageWithSpecialID()
         "Office Open XML Text",
     };
 
-    // Trigger swap out mechanism to test swapped state factor too.
-    std::shared_ptr< comphelper::ConfigurationChanges > batch(comphelper::ConfigurationChanges::create());
-    officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(static_cast<sal_Int32>(1), batch);
-    batch->commit();
-
     for( size_t nFilter = 0; nFilter < SAL_N_ELEMENTS(aFilterNames); ++nFilter )
     {
         if (mxComponent.is())
@@ -244,27 +243,27 @@ void Test::testImageWithSpecialID()
         {
             uno::Reference<graphic::XGraphic> xGraphic;
             XPropSet->getPropertyValue("Graphic") >>= xGraphic;
-            CPPUNIT_ASSERT(xGraphic.is());
-            CPPUNIT_ASSERT(xGraphic->getType() != graphic::GraphicType::EMPTY);
+            CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), graphic::GraphicType::PIXEL, xGraphic->getType());
             uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
-            CPPUNIT_ASSERT(xBitmap.is());
-            CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(610), xBitmap->getSize().Width );
-            CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(381), xBitmap->getSize().Height );
+            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);
         }
         // Second Image
         xImage = getShape(2);
         XPropSet.set( xImage, uno::UNO_QUERY_THROW );
 
-        // Check size
+        // Check graphic, size
         {
             uno::Reference<graphic::XGraphic> xGraphic;
             XPropSet->getPropertyValue("Graphic") >>= xGraphic;
-            CPPUNIT_ASSERT(xGraphic.is());
-            CPPUNIT_ASSERT(xGraphic->getType() != graphic::GraphicType::EMPTY);
+            CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), graphic::GraphicType::PIXEL, xGraphic->getType());
             uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
-            CPPUNIT_ASSERT(xBitmap.is());
-            CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(900), xBitmap->getSize().Width );
-            CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(600), xBitmap->getSize().Height );
+            CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is());
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(900), xBitmap->getSize().Width);
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(600), xBitmap->getSize().Height);
         }
     }
 }
@@ -309,11 +308,6 @@ void Test::testGraphicShape()
         "Office Open XML Text",
     };
 
-    // Trigger swap out mechanism to test swapped state factor too.
-    std::shared_ptr< comphelper::ConfigurationChanges > batch(comphelper::ConfigurationChanges::create());
-    officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(static_cast<sal_Int32>(1), batch);
-    batch->commit();
-
     for( size_t nFilter = 0; nFilter < SAL_N_ELEMENTS(aFilterNames); ++nFilter )
     {
         if (mxComponent.is())


More information about the Libreoffice-commits mailing list