[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - sc/qa svx/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Mon Dec 9 17:21:57 UTC 2019


 sc/qa/unit/data/ods/keep-preview-missing-obj-link.ods |binary
 sc/qa/unit/helper/qahelper.cxx                        |   17 ++++++++++++----
 sc/qa/unit/helper/qahelper.hxx                        |    2 +
 sc/qa/unit/subsequent_filters-test.cxx                |   19 ++++++++++++++++++
 svx/source/svdraw/svdoole2.cxx                        |    8 +++++++
 5 files changed, 42 insertions(+), 4 deletions(-)

New commits:
commit 15fbc2a7cf879a91c4b0d3853f043e7eba6b48fe
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Wed Nov 20 14:54:16 2019 +0000
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Mon Dec 9 18:21:10 2019 +0100

    If a SdrOle2Obj object is missing/broken show the preview set for it
    
    if the object isn't valid, e.g. link to something that doesn't exist, set the fallback
    graphic as mxGraphic so SdrOle2Obj::GetGraphic will show the fallback, otherwise
    the failing mxObjRef.is test in SdrOle2Obj::GetGraphic means it doesn't get used
    
    Change-Id: I8f1aea6b25dc216e01a0f888a44d10876bb1bebd
    Reviewed-on: https://gerrit.libreoffice.org/83329
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at cib.de>
    Reviewed-on: https://gerrit.libreoffice.org/84750
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Andras Timar <andras.timar at collabora.com>

diff --git a/sc/qa/unit/data/ods/keep-preview-missing-obj-link.ods b/sc/qa/unit/data/ods/keep-preview-missing-obj-link.ods
new file mode 100644
index 000000000000..e7b15fd7688a
Binary files /dev/null and b/sc/qa/unit/data/ods/keep-preview-missing-obj-link.ods differ
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index dad65eb9d7c4..64f41b033ff0 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -280,7 +280,7 @@ void testFormats(ScBootstrapFixture* pTest, ScDocument* pDoc, sal_Int32 nFormat)
     CPPUNIT_ASSERT_EQUAL(ScRangeList(ScRange(1,1,2,3,1,2)), rRange3);
 }
 
-const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage)
+const SdrOle2Obj* getSingleOleObject(ScDocument& rDoc, sal_uInt16 nPage)
 {
     // Retrieve the chart object instance from the 2nd page (for the 2nd sheet).
     ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
@@ -316,14 +316,23 @@ const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage)
         return nullptr;
     }
 
-    const SdrOle2Obj& rOleObj = static_cast<const SdrOle2Obj&>(*pObj);
-    if (!rOleObj.IsChart())
+    return static_cast<const SdrOle2Obj*>(pObj);
+}
+
+const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage)
+{
+    const SdrOle2Obj* pObj = getSingleOleObject(rDoc, nPage);
+
+    if (!pObj)
+        return pObj;
+
+    if (!pObj->IsChart())
     {
         cout << "This should be a chart object." << endl;
         return nullptr;
     }
 
-    return &rOleObj;
+    return pObj;
 }
 
 std::vector<OUString> getChartRangeRepresentations(const SdrOle2Obj& rChartObj)
diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx
index b360851e5f32..21a57002f1a6 100644
--- a/sc/qa/unit/helper/qahelper.hxx
+++ b/sc/qa/unit/helper/qahelper.hxx
@@ -126,6 +126,8 @@ SCQAHELPER_DLLPUBLIC void testFile(const OUString& aFileName, ScDocument& rDoc,
 //need own handler because conditional formatting strings must be generated
 SCQAHELPER_DLLPUBLIC void testCondFile(const OUString& aFileName, ScDocument* pDoc, SCTAB nTab);
 
+SCQAHELPER_DLLPUBLIC const SdrOle2Obj* getSingleOleObject(ScDocument& rDoc, sal_uInt16 nPage);
+
 SCQAHELPER_DLLPUBLIC const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage);
 
 SCQAHELPER_DLLPUBLIC std::vector<OUString> getChartRangeRepresentations(const SdrOle2Obj& rChartObj);
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 7575a124ab90..b080cdf70698 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -254,6 +254,7 @@ public:
     void testCharacterSetXLSXML();
     void testTdf62268();
     void testVBAMacroFunctionODS();
+    void testPreviewMissingObjLink();
 
     CPPUNIT_TEST_SUITE(ScFiltersTest);
     CPPUNIT_TEST(testBooleanFormatXLSX);
@@ -393,6 +394,7 @@ public:
     CPPUNIT_TEST(testCondFormatFormulaListenerXLSX);
     CPPUNIT_TEST(testTdf62268);
     CPPUNIT_TEST(testVBAMacroFunctionODS);
+    CPPUNIT_TEST(testPreviewMissingObjLink);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -4322,6 +4324,23 @@ void ScFiltersTest::testVBAMacroFunctionODS()
     xDocSh->DoClose();
 }
 
+void ScFiltersTest::testPreviewMissingObjLink()
+{
+    ScDocShellRef xDocSh = loadDoc("keep-preview-missing-obj-link.", FORMAT_ODS);
+    CPPUNIT_ASSERT_MESSAGE("Failed to load keep-preview-missing-obj-link.ods.", xDocSh.is());
+
+    ScDocument& rDoc = xDocSh->GetDocument();
+
+    // Retrieve the ole object
+    const SdrOle2Obj* pOleObj = getSingleOleObject(rDoc, 0);
+    CPPUNIT_ASSERT_MESSAGE("Failed to retrieve an ole object from the 2nd sheet.", pOleObj);
+
+    const Graphic* pGraphic = pOleObj->GetGraphic();
+    CPPUNIT_ASSERT_MESSAGE("the ole object links to a missing file, but we should retain its preview", pGraphic);
+
+    xDocSh->DoClose();
+}
+
 ScFiltersTest::ScFiltersTest()
       : ScBootstrapFixture( "sc/qa/unit/data" )
 {
diff --git a/svx/source/svdraw/svdoole2.cxx b/svx/source/svdraw/svdoole2.cxx
index e642cfdc610c..19ded46c6c54 100644
--- a/svx/source/svdraw/svdoole2.cxx
+++ b/svx/source/svdraw/svdoole2.cxx
@@ -1855,11 +1855,19 @@ bool SdrOle2Obj::IsChart() const
 void SdrOle2Obj::SetGraphicToObj( const Graphic& aGraphic )
 {
     mpImpl->mxObjRef.SetGraphic( aGraphic, OUString() );
+    // if the object isn't valid, e.g. link to something that doesn't exist, set the fallback
+    // graphic as mxGraphic so SdrOle2Obj::GetGraphic will show the fallback
+    if (const Graphic* pObjGraphic = mpImpl->mxObjRef.is() ? nullptr : mpImpl->mxObjRef.GetGraphic())
+        mpImpl->mxGraphic.reset(new Graphic(*pObjGraphic));
 }
 
 void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrStream, const OUString& aMediaType )
 {
     mpImpl->mxObjRef.SetGraphicStream( xGrStream, aMediaType );
+    // if the object isn't valid, e.g. link to something that doesn't exist, set the fallback
+    // graphic as mxGraphic so SdrOle2Obj::GetGraphic will show the fallback
+    if (const Graphic* pObjGraphic = mpImpl->mxObjRef.is() ? nullptr : mpImpl->mxObjRef.GetGraphic())
+        mpImpl->mxGraphic.reset(new Graphic(*pObjGraphic));
 }
 
 bool SdrOle2Obj::IsCalc() const


More information about the Libreoffice-commits mailing list