LCOV - code coverage report
Current view: top level - svtools/qa/unit - GraphicObjectTest.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 49 51 96.1 %
Date: 2014-11-03 Functions: 11 14 78.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  */
      10             : 
      11             : #include <cppunit/extensions/HelperMacros.h>
      12             : #include "cppunit/plugin/TestPlugIn.h"
      13             : 
      14             : #include <svtools/grfmgr.hxx>
      15             : 
      16             : #include <test/bootstrapfixture.hxx>
      17             : 
      18             : #include <tools/stream.hxx>
      19             : 
      20             : #include <vcl/image.hxx>
      21             : 
      22             : namespace
      23             : {
      24             : 
      25           6 : class GraphicObjectTest: public test::BootstrapFixture
      26             : {
      27             : 
      28             : public:
      29             :     void testSwap();
      30             : 
      31             : private:
      32             :     DECL_LINK(getLinkStream, GraphicObject*);
      33             : 
      34             : private:
      35           4 :     CPPUNIT_TEST_SUITE(GraphicObjectTest);
      36           2 :     CPPUNIT_TEST(testSwap);
      37           4 :     CPPUNIT_TEST_SUITE_END();
      38             : };
      39             : 
      40             : static const char aGraphicFile[] = "/svtools/qa/unit/data/graphic.png";
      41             : static const sal_uLong nGraphicSizeBytes = 4800;
      42             : 
      43           6 : const Graphic lcl_loadGraphic(const rtl::OUString &rUrl)
      44             : {
      45           6 :     const Image aImage(rUrl);
      46           6 :     return Graphic(aImage.GetBitmapEx());
      47             : }
      48             : 
      49           0 : IMPL_LINK(GraphicObjectTest, getLinkStream, GraphicObject*, /*pGraphObj*/)
      50             : {
      51           0 :     return reinterpret_cast<sal_IntPtr>(GRFMGR_AUTOSWAPSTREAM_LINK);
      52             : }
      53             : 
      54           2 : void GraphicObjectTest::testSwap()
      55             : {
      56             :     // simple non-linked case
      57             :     {
      58           2 :         GraphicObject aGraphObj(lcl_loadGraphic(getURLFromSrc(aGraphicFile)));
      59           2 :         CPPUNIT_ASSERT(!aGraphObj.HasSwapStreamHdl());
      60           2 :         CPPUNIT_ASSERT(!aGraphObj.IsSwappedOut());
      61           2 :         CPPUNIT_ASSERT_EQUAL(nGraphicSizeBytes, aGraphObj.GetGraphic().GetSizeBytes());
      62             :         // swap out
      63           2 :         CPPUNIT_ASSERT(aGraphObj.SwapOut());
      64           2 :         CPPUNIT_ASSERT(aGraphObj.IsSwappedOut());
      65             :         // swap in
      66           2 :         CPPUNIT_ASSERT(aGraphObj.SwapIn());
      67           2 :         CPPUNIT_ASSERT(!aGraphObj.IsSwappedOut());
      68             :         // the data are still there
      69           2 :         CPPUNIT_ASSERT_EQUAL(nGraphicSizeBytes, aGraphObj.GetGraphic().GetSizeBytes());
      70             :     }
      71             : 
      72             :     // linked case
      73             :     {
      74           2 :         GraphicObject aGraphObj(lcl_loadGraphic(getURLFromSrc(aGraphicFile)));
      75           2 :         aGraphObj.SetSwapStreamHdl(LINK(this, GraphicObjectTest, getLinkStream));
      76             : 
      77           2 :         CPPUNIT_ASSERT(aGraphObj.HasSwapStreamHdl());
      78           2 :         CPPUNIT_ASSERT(!aGraphObj.IsSwappedOut());
      79           2 :         CPPUNIT_ASSERT_EQUAL(nGraphicSizeBytes, aGraphObj.GetGraphic().GetSizeBytes());
      80             :         // swap out
      81           2 :         CPPUNIT_ASSERT(aGraphObj.SwapOut());
      82           2 :         CPPUNIT_ASSERT(aGraphObj.IsSwappedOut());
      83             :         // swap in
      84           2 :         CPPUNIT_ASSERT(aGraphObj.SwapIn());
      85           2 :         CPPUNIT_ASSERT(!aGraphObj.IsSwappedOut());
      86             :         // the data are still there
      87           2 :         CPPUNIT_ASSERT_EQUAL(nGraphicSizeBytes, aGraphObj.GetGraphic().GetSizeBytes());
      88             :     }
      89             : 
      90             :     // combination of two GraphicObjects
      91             :     {
      92           2 :         GraphicObject aGraphObj(lcl_loadGraphic(getURLFromSrc(aGraphicFile)));
      93             : 
      94           4 :         GraphicObject aGraphObj2(aGraphObj);
      95           2 :         aGraphObj2.SetSwapStreamHdl(LINK(this, GraphicObjectTest, getLinkStream));
      96             : 
      97           2 :         CPPUNIT_ASSERT(!aGraphObj.IsSwappedOut());
      98           2 :         CPPUNIT_ASSERT(!aGraphObj2.IsSwappedOut());
      99           2 :         CPPUNIT_ASSERT_EQUAL(nGraphicSizeBytes, aGraphObj.GetGraphic().GetSizeBytes());
     100           2 :         CPPUNIT_ASSERT_EQUAL(nGraphicSizeBytes, aGraphObj2.GetGraphic().GetSizeBytes());
     101             : 
     102             :         // GraphicObjects never share the same Graphic. A new one is created as one step during
     103             :         // registration of the GraphicObject at GraphicManager.
     104             : 
     105             :         // swap out
     106           2 :         CPPUNIT_ASSERT(aGraphObj.SwapOut());
     107           2 :         CPPUNIT_ASSERT(aGraphObj.IsSwappedOut());
     108           2 :         CPPUNIT_ASSERT(!aGraphObj2.IsSwappedOut());
     109           2 :         CPPUNIT_ASSERT(aGraphObj2.SwapOut());
     110           2 :         CPPUNIT_ASSERT(aGraphObj2.IsSwappedOut());
     111             :         // swap in
     112           2 :         CPPUNIT_ASSERT(aGraphObj2.SwapIn());
     113           2 :         CPPUNIT_ASSERT(!aGraphObj2.IsSwappedOut());
     114           2 :         CPPUNIT_ASSERT(aGraphObj.IsSwappedOut());
     115           2 :         CPPUNIT_ASSERT(aGraphObj.SwapIn());
     116           2 :         CPPUNIT_ASSERT(!aGraphObj.IsSwappedOut());
     117             :         // the data are still there
     118           2 :         CPPUNIT_ASSERT_EQUAL(nGraphicSizeBytes, aGraphObj.GetGraphic().GetSizeBytes());
     119           4 :         CPPUNIT_ASSERT_EQUAL(nGraphicSizeBytes, aGraphObj2.GetGraphic().GetSizeBytes());
     120             :     }
     121           2 : }
     122             : 
     123           2 : CPPUNIT_TEST_SUITE_REGISTRATION(GraphicObjectTest);
     124             : 
     125             : }
     126             : 
     127           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     128             : 
     129             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10