LCOV - code coverage report
Current view: top level - cppcanvas/qa/extras/emfplus - emfplus.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 38 41 92.7 %
Date: 2015-06-13 12:38:46 Functions: 16 17 94.1 %
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             : #include <com/sun/star/beans/XPropertySet.hpp>
      11             : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
      12             : #include <com/sun/star/frame/Desktop.hpp>
      13             : #include <com/sun/star/graphic/XGraphic.hpp>
      14             : 
      15             : #include <comphelper/processfactory.hxx>
      16             : #include <sfx2/objsh.hxx>
      17             : #include <sfx2/sfxbasemodel.hxx>
      18             : #include <test/unoapi_test.hxx>
      19             : #include <unotest/macros_test.hxx>
      20             : #include <vcl/bmpacc.hxx>
      21             : #include <vcl/pngwrite.hxx>
      22             : 
      23             : using namespace com::sun::star;
      24             : 
      25             : class Test : public UnoApiTest
      26             : {
      27             : public:
      28           1 :     Test() : UnoApiTest("/cppcanvas/qa/extras/emfplus/data/")
      29             :     {
      30           1 :     }
      31             : 
      32           2 :     virtual ~Test()
      33           1 :     {
      34           2 :     }
      35             : 
      36           1 :     virtual void setUp() SAL_OVERRIDE
      37             :     {
      38           1 :         UnoApiTest::setUp();
      39           1 :         mxDesktop.set(frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())));
      40           1 :     };
      41             : 
      42           1 :     virtual void tearDown() SAL_OVERRIDE
      43             :     {
      44           1 :         if (mxComponent.is())
      45             :         {
      46           1 :             closeDocument(mxComponent);
      47           1 :             mxComponent->dispose();
      48             :         }
      49           1 :         UnoApiTest::tearDown();
      50           1 :     };
      51             : 
      52           1 :     Bitmap load(const char* pName)
      53             :     {
      54           1 :         OUString aFileURL;
      55           1 :         createFileURL(OUString::createFromAscii(pName), aFileURL);
      56           1 :         mxComponent = loadFromDesktop(aFileURL, "com.sun.star.drawing.DrawingDocument");
      57           1 :         SfxBaseModel* pModel = dynamic_cast<SfxBaseModel*>(mxComponent.get());
      58           1 :         CPPUNIT_ASSERT(pModel);
      59           1 :         SfxObjectShell* pShell = pModel->GetObjectShell();
      60           2 :         std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
      61           2 :         BitmapEx aResultBitmap;
      62           1 :         CPPUNIT_ASSERT(xMetaFile->CreateThumbnail(aResultBitmap));
      63             :         // If this is set, the metafile will be dumped as a PNG one for debug purposes.
      64           1 :         char* pEnv = getenv("CPPCANVAS_DEBUG_EMFPLUS_DUMP_TO");
      65           1 :         if (pEnv)
      66             :         {
      67           0 :             SvFileStream aStream(OUString::fromUtf8(pEnv), StreamMode::WRITE);
      68           0 :             vcl::PNGWriter aWriter(aResultBitmap);
      69           0 :             CPPUNIT_ASSERT(aWriter.Write(aStream));
      70             :         }
      71             : 
      72           2 :         return aResultBitmap.GetBitmap();
      73             :     }
      74             : 
      75             :     void testFdo77229();
      76             : 
      77           2 :     CPPUNIT_TEST_SUITE(Test);
      78           1 :     CPPUNIT_TEST(testFdo77229);
      79           5 :     CPPUNIT_TEST_SUITE_END();
      80             : 
      81             :     uno::Reference<lang::XComponent> mxComponent;
      82             : };
      83             : 
      84           1 : void Test::testFdo77229()
      85             : {
      86           1 :     Bitmap aBitmap = load("fdo77229.emf");
      87           2 :     Bitmap::ScopedReadAccess pAccess(aBitmap);
      88             :     // The green star was missing.
      89           2 :     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x00fe00), Color(pAccess->GetPixel(142, 140)).GetColor());
      90           1 : }
      91             : 
      92           1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
      93             : 
      94           4 : CPPUNIT_PLUGIN_IMPLEMENT();
      95             : 
      96             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11