From 554902eac3361c67c6d76e0d7a237d9a16062dfe Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Fri, 7 Nov 2014 10:44:20 +0100 Subject: Make SdrGrafObj swapping methods private. Plus remove some useless call of them. Change the tests accordingly. Change-Id: I47a50b5734d799ac02ee7221c95f82415afb9497 --- filter/source/msfilter/msdffimp.cxx | 1 - include/svx/svdograf.hxx | 3 ++ sc/CppunitTest_sc_subsequent_export_test.mk | 4 ++ sc/qa/unit/data/ods/document_with_an_image.ods | Bin 153495 -> 0 bytes sc/qa/unit/data/ods/document_with_two_images.ods | Bin 0 -> 221281 bytes sc/qa/unit/subsequent_export-test.cxx | 42 +++++++++++++-------- sd/CppunitTest_sd_export_tests.mk | 4 ++ sd/qa/unit/data/odp/document_with_an_image.odp | Bin 101665 -> 0 bytes sd/qa/unit/data/odp/document_with_two_images.odp | Bin 0 -> 202183 bytes sd/qa/unit/export-tests.cxx | 42 ++++++++++++++------- .../sdr/contact/viewobjectcontactofgraphic.cxx | 13 +------ 11 files changed, 69 insertions(+), 40 deletions(-) delete mode 100644 sc/qa/unit/data/ods/document_with_an_image.ods create mode 100644 sc/qa/unit/data/ods/document_with_two_images.ods delete mode 100644 sd/qa/unit/data/odp/document_with_an_image.odp create mode 100644 sd/qa/unit/data/odp/document_with_two_images.odp diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx index a333223a1ea0..7eecc3f1c2c1 100644 --- a/filter/source/msfilter/msdffimp.cxx +++ b/filter/source/msfilter/msdffimp.cxx @@ -3970,7 +3970,6 @@ SdrObject* SvxMSDffManager::ImportGraphic( SvStream& rSt, SfxItemSet& rSet, cons if ( bLinkGrf && !bGrfRead ) { - static_cast(pRet)->ForceSwapIn(); Graphic aGraf(static_cast(pRet)->GetGraphic()); lcl_ApplyCropping( *this, &rSet, aGraf ); } diff --git a/include/svx/svdograf.hxx b/include/svx/svdograf.hxx index cd47a2075f6c..d6cb3d2e16e8 100644 --- a/include/svx/svdograf.hxx +++ b/include/svx/svdograf.hxx @@ -69,6 +69,7 @@ private: // to allow sdr::contact::ViewObjectContactOfGraphic access to ImpUpdateGraphicLink() friend class sdr::contact::ViewObjectContactOfGraphic; + friend class SdrExchangeView; // Only for a ForceSwapIn() call. friend class SdrGraphicLink; private: @@ -135,9 +136,11 @@ public: void SetGrafStreamURL( const OUString& rGraphicStreamURL ); OUString GetGrafStreamURL() const; +private: void ForceSwapIn() const; void ForceSwapOut() const; +public: void SetGraphicLink(const OUString& rFileName, const OUString& rReferer, const OUString& rFilterName); void ReleaseGraphicLink(); bool IsLinkedGraphic() const; diff --git a/sc/CppunitTest_sc_subsequent_export_test.mk b/sc/CppunitTest_sc_subsequent_export_test.mk index 3316beb23114..1cfaf6914850 100644 --- a/sc/CppunitTest_sc_subsequent_export_test.mk +++ b/sc/CppunitTest_sc_subsequent_export_test.mk @@ -117,6 +117,10 @@ $(eval $(call gb_CppunitTest_use_components,sc_subsequent_export_test,\ )) endif +$(eval $(call gb_CppunitTest_use_custom_headers,sc_subsequent_export_test,\ + officecfg/registry \ +)) + $(eval $(call gb_CppunitTest_use_configuration,sc_subsequent_export_test)) # vim: set noet sw=4 ts=4: diff --git a/sc/qa/unit/data/ods/document_with_an_image.ods b/sc/qa/unit/data/ods/document_with_an_image.ods deleted file mode 100644 index adfcd4c0677a..000000000000 Binary files a/sc/qa/unit/data/ods/document_with_an_image.ods and /dev/null differ diff --git a/sc/qa/unit/data/ods/document_with_two_images.ods b/sc/qa/unit/data/ods/document_with_two_images.ods new file mode 100644 index 000000000000..6e1cc68a4bd4 Binary files /dev/null and b/sc/qa/unit/data/ods/document_with_two_images.ods differ diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index 4474cafce391..cdc7532fb457 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -7,6 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include #include #include #include @@ -59,7 +60,7 @@ #include #include - +#include #include #include #include @@ -2271,26 +2272,19 @@ void ScExportTest::testSwappedOutImageExport() "generic_HTML", }; + // Set cache size to a very small value to make sure one of the images is swapped out + boost::shared_ptr< comphelper::ConfigurationChanges > xBatch(comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(sal_Int32(1), xBatch); + xBatch->commit(); + for( size_t nFilter = 0; nFilter < aFilterNames.size(); ++nFilter ) { // Check whether the export code swaps in the image which was swapped out before. - ScDocShellRef xDocSh = loadDoc("document_with_an_image.", ODS); + ScDocShellRef xDocSh = loadDoc("document_with_two_images.", ODS); const OString sFailedMessage = OString("Failed on filter: ") + OUStringToOString(aFilterNames[nFilter], RTL_TEXTENCODING_ASCII_US); - - // Find and swap out the image CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xDocSh.Is()); - ScDocument* pDoc = &xDocSh->GetDocument(); - CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pDoc); - ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); - CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pDrawLayer); - const SdrPage* pPage = pDrawLayer->GetPage(0); - CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pPage); - const SdrObject* pObj = pPage->GetObj(0); - CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pObj->GetObjIdentifier() == OBJ_GRAF); - const SdrGrafObj& rGrafObj = static_cast(*pObj); - rGrafObj.ForceSwapOut(); // Export the document and import again for a check ScDocShellRef xDocSh2 = saveAndReload(xDocSh, nFilter); @@ -2302,7 +2296,7 @@ void ScExportTest::testSwappedOutImageExport() uno::Reference< container::XIndexAccess > xIA(xDoc->getSheets(), UNO_QUERY_THROW); uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xIA->getByIndex(0), UNO_QUERY_THROW); uno::Reference< container::XIndexAccess > xDraws(xDrawPageSupplier->getDrawPage(), UNO_QUERY_THROW); - CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast(1), xDraws->getCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast(2), xDraws->getCount()); uno::Reference xImage(xDraws->getByIndex(0), uno::UNO_QUERY); uno::Reference< beans::XPropertySet > XPropSet( xImage, uno::UNO_QUERY_THROW ); @@ -2322,6 +2316,24 @@ void ScExportTest::testSwappedOutImageExport() CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast(610), xBitmap->getSize().Width ); CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast(381), xBitmap->getSize().Height ); } + // Second Image + xImage.set(xDraws->getByIndex(1), uno::UNO_QUERY); + XPropSet.set( xImage, uno::UNO_QUERY_THROW ); + // Check URL + { + OUString sURL; + XPropSet->getPropertyValue("GraphicURL") >>= sURL; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString("vnd.sun.star.GraphicObject:1000000000000384000002580A24B597"), sURL); + } + // Check size + { + uno::Reference xGraphic; + XPropSet->getPropertyValue("Graphic") >>= xGraphic; + uno::Reference xBitmap(xGraphic, uno::UNO_QUERY); + CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is()); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast(900), xBitmap->getSize().Width ); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast(600), xBitmap->getSize().Height ); + } xDocSh2->DoClose(); } } diff --git a/sd/CppunitTest_sd_export_tests.mk b/sd/CppunitTest_sd_export_tests.mk index 68bdb3211965..a8f3dbfa067b 100644 --- a/sd/CppunitTest_sd_export_tests.mk +++ b/sd/CppunitTest_sd_export_tests.mk @@ -106,6 +106,10 @@ $(eval $(call gb_CppunitTest_use_components,sd_export_tests,\ xmlsecurity/util/xmlsecurity \ )) +$(eval $(call gb_CppunitTest_use_custom_headers,sd_export_tests,\ + officecfg/registry \ +)) + $(eval $(call gb_CppunitTest_use_configuration,sd_export_tests)) $(eval $(call gb_CppunitTest_use_unittest_configuration,sd_export_tests)) diff --git a/sd/qa/unit/data/odp/document_with_an_image.odp b/sd/qa/unit/data/odp/document_with_an_image.odp deleted file mode 100644 index 9e0bdce3bb35..000000000000 Binary files a/sd/qa/unit/data/odp/document_with_an_image.odp and /dev/null differ diff --git a/sd/qa/unit/data/odp/document_with_two_images.odp b/sd/qa/unit/data/odp/document_with_two_images.odp new file mode 100644 index 000000000000..33fb9bb56392 Binary files /dev/null and b/sd/qa/unit/data/odp/document_with_two_images.odp differ diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx index 0dfc4683c729..08f854779fe4 100644 --- a/sd/qa/unit/export-tests.cxx +++ b/sd/qa/unit/export-tests.cxx @@ -6,10 +6,10 @@ * 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 #include "sdmodeltestbase.hxx" #include "Outliner.hxx" - +#include #include #include #include @@ -504,21 +504,17 @@ void SdExportTest::testSwappedOutImageExport() PPTX, }; + // Set cache size to a very small value to make sure one of the images is swapped out + boost::shared_ptr< comphelper::ConfigurationChanges > xBatch(comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(sal_Int32(1), xBatch); + xBatch->commit(); + for( size_t nExportFormat = 0; nExportFormat < vFormats.size(); ++nExportFormat ) { // Load the original file with one image - ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/odp/document_with_an_image.odp"), ODP); + ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/odp/document_with_two_images.odp"), ODP); const OString sFailedMessage = OString("Failed on filter: ") + OString(aFileFormats[nExportFormat].pFilterName); - // Swap out the image - SdDrawDocument *pDoc = xDocShRef->GetDoc(); - CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pDoc != NULL ); - const SdrPage* pPage = pDoc->GetPage(1); - CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pPage != NULL ); - SdrGrafObj* pGrafObject = dynamic_cast(pPage->GetObj(2)); - CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pGrafObject != NULL); - pGrafObject->ForceSwapOut(); - // Export the document and import again for a check uno::Reference< lang::XComponent > xComponent(xDocShRef->GetModel(), uno::UNO_QUERY); uno::Reference xStorable(xComponent, uno::UNO_QUERY); @@ -534,7 +530,7 @@ void SdExportTest::testSwappedOutImageExport() // Check whether graphic exported well after it was swapped out uno::Reference xDrawPagesSupplier(xDocShRef->GetModel(), uno::UNO_QUERY); - CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), xDrawPagesSupplier->getDrawPages()->getCount() == 1 ); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), xDrawPagesSupplier->getDrawPages()->getCount() == 2 ); uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW ); uno::Reference xImage(xDrawPage->getByIndex(2), uno::UNO_QUERY); @@ -554,6 +550,26 @@ void SdExportTest::testSwappedOutImageExport() CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast(610), xBitmap->getSize().Width ); CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast(381), xBitmap->getSize().Height ); } + + // Second Image + xDrawPage.set(xDrawPagesSupplier->getDrawPages()->getByIndex(1), uno::UNO_QUERY_THROW ); + xImage.set(xDrawPage->getByIndex(1), uno::UNO_QUERY); + XPropSet.set( xImage, uno::UNO_QUERY_THROW ); + // Check URL + { + OUString sURL; + XPropSet->getPropertyValue("GraphicURL") >>= sURL; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), OUString("vnd.sun.star.GraphicObject:1000000000000384000002580A24B597"), sURL); + } + // Check size + { + uno::Reference xGraphic; + XPropSet->getPropertyValue("Graphic") >>= xGraphic; + uno::Reference xBitmap(xGraphic, uno::UNO_QUERY); + CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is()); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast(900), xBitmap->getSize().Width ); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast(600), xBitmap->getSize().Height ); + } xDocShRef->DoClose(); } } diff --git a/svx/source/sdr/contact/viewobjectcontactofgraphic.cxx b/svx/source/sdr/contact/viewobjectcontactofgraphic.cxx index a445b753fc59..c95b42d99a7f 100644 --- a/svx/source/sdr/contact/viewobjectcontactofgraphic.cxx +++ b/svx/source/sdr/contact/viewobjectcontactofgraphic.cxx @@ -245,8 +245,6 @@ namespace sdr // prepare primitive generation with evtl. loading the graphic when it's swapped out SdrGrafObj& rGrafObj = const_cast< ViewObjectContactOfGraphic* >(this)->getSdrGrafObj(); bool bDoAsynchronGraphicLoading(rGrafObj.GetModel() && rGrafObj.GetModel()->IsSwapGraphics()); - bool bSwapInDone(false); - bool bSwapInExclusive(false); if( bDoAsynchronGraphicLoading && rGrafObj.IsSwappedOut() ) { @@ -262,16 +260,15 @@ namespace sdr || GetObjectContact().isOutputToPDFFile() ) { bDoAsynchronGraphicLoading = false; - bSwapInExclusive = true; } } if( bDoAsynchronGraphicLoading ) { - bSwapInDone = const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithAsynchroniousLoading(); + const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithAsynchroniousLoading(); } else { - bSwapInDone = const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithSynchroniousLoading(); + const_cast< ViewObjectContactOfGraphic* >(this)->impPrepareGraphicWithSynchroniousLoading(); } // get return value by calling parent @@ -294,12 +291,6 @@ namespace sdr } } - // if swap in was forced only for printing metafile and pdf, swap out again - if( bSwapInDone && bSwapInExclusive ) - { - rGrafObj.ForceSwapOut(); - } - return xRetval; } -- cgit