From 908c060ceef81a733cf1d1912b48f5d499afdad8 Mon Sep 17 00:00:00 2001 From: Zolnai Tamás Date: Tue, 17 Feb 2015 15:50:08 +0100 Subject: Test for tdf#88935 Change-Id: I625a59a632c53c77f593268b14e60ab265e5a821 --- svtools/qa/unit/GraphicObjectTest.cxx | 66 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'svtools/qa/unit') diff --git a/svtools/qa/unit/GraphicObjectTest.cxx b/svtools/qa/unit/GraphicObjectTest.cxx index d4ecf29b6653..cc73b5c8f97f 100644 --- a/svtools/qa/unit/GraphicObjectTest.cxx +++ b/svtools/qa/unit/GraphicObjectTest.cxx @@ -41,6 +41,7 @@ public: void testSwap(); void testSizeBasedAutoSwap(); void testTdf88836(); + void testTdf88935(); virtual void setUp() SAL_OVERRIDE @@ -58,6 +59,7 @@ private: CPPUNIT_TEST(testSwap); CPPUNIT_TEST(testSizeBasedAutoSwap); CPPUNIT_TEST(testTdf88836); + CPPUNIT_TEST(testTdf88935); CPPUNIT_TEST_SUITE_END(); }; @@ -239,6 +241,70 @@ void GraphicObjectTest::testTdf88836() CPPUNIT_ASSERT_EQUAL(GRAPHIC_NONE, aGraphic.GetType()); } +void GraphicObjectTest::testTdf88935() +{ + // Cache size was not updated by deletion of graphic objects + + // Load a file with two images + uno::Reference< lang::XComponent > xComponent = + loadFromDesktop(getURLFromSrc("svtools/qa/unit/data/document_with_two_images.odt"), "com.sun.star.text.TextDocument"); + SwXTextDocument* pTxtDoc = dynamic_cast(xComponent.get()); + CPPUNIT_ASSERT(pTxtDoc); + SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc(); + CPPUNIT_ASSERT(pDoc); + SwNodes& aNodes = pDoc->GetNodes(); + + // Find images + const GraphicObject* pGraphObj1 = 0; + const GraphicObject* pGraphObj2 = 0; + for( sal_uLong nIndex = 0; nIndex < aNodes.Count(); ++nIndex) + { + if( aNodes[nIndex]->IsGrfNode() ) + { + SwGrfNode* pGrfNode = aNodes[nIndex]->GetGrfNode(); + if( !pGraphObj1 ) + { + pGraphObj1 = &pGrfNode->GetGrfObj(); + } + else + { + pGraphObj2 = &pGrfNode->GetGrfObj(); + } + } + } + CPPUNIT_ASSERT_MESSAGE("Missing image", pGraphObj1 != 0 && pGraphObj2 != 0); + + // Set cache size + { + GraphicManager& rGrfMgr = pGraphObj1->GetGraphicManager(); + rGrfMgr.SetMaxCacheSize((pGraphObj1->GetSizeBytes()+pGraphObj2->GetSizeBytes())*10); + } + + // Both images fit into the cache + { + pGraphObj1->GetGraphic(); + pGraphObj2->GetGraphic(); + CPPUNIT_ASSERT(!pGraphObj1->IsSwappedOut()); + CPPUNIT_ASSERT(!pGraphObj2->IsSwappedOut()); + } + + // Create and remove some copy of the first image + for( int i = 0; i < 50; ++i ) + { + GraphicObject aGraphObj3(*pGraphObj1, &pGraphObj1->GetGraphicManager()); + CPPUNIT_ASSERT(aGraphObj3.SwapOut()); + CPPUNIT_ASSERT(aGraphObj3.SwapIn()); + } + + // Both images fit into the cache + { + pGraphObj1->GetGraphic(); + pGraphObj2->GetGraphic(); + CPPUNIT_ASSERT(!pGraphObj1->IsSwappedOut()); + CPPUNIT_ASSERT(!pGraphObj2->IsSwappedOut()); + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(GraphicObjectTest); } -- cgit