1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
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>
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>
23 using namespace com::sun::star
;
25 class Test
: public UnoApiTest
28 Test() : UnoApiTest("/cppcanvas/qa/extras/emfplus/data/")
36 virtual void setUp() SAL_OVERRIDE
39 mxDesktop
.set(frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())));
42 virtual void tearDown() SAL_OVERRIDE
46 closeDocument(mxComponent
);
47 mxComponent
->dispose();
49 UnoApiTest::tearDown();
52 Bitmap
load(const char* pName
)
55 createFileURL(OUString::createFromAscii(pName
), aFileURL
);
56 mxComponent
= loadFromDesktop(aFileURL
, "com.sun.star.drawing.DrawingDocument");
57 SfxBaseModel
* pModel
= dynamic_cast<SfxBaseModel
*>(mxComponent
.get());
58 CPPUNIT_ASSERT(pModel
);
59 SfxObjectShell
* pShell
= pModel
->GetObjectShell();
60 std::shared_ptr
<GDIMetaFile
> xMetaFile
= pShell
->GetPreviewMetaFile();
61 BitmapEx aResultBitmap
;
62 CPPUNIT_ASSERT(xMetaFile
->CreateThumbnail(aResultBitmap
));
63 // If this is set, the metafile will be dumped as a PNG one for debug purposes.
64 char* pEnv
= getenv("CPPCANVAS_DEBUG_EMFPLUS_DUMP_TO");
67 SvFileStream
aStream(OUString::fromUtf8(pEnv
), StreamMode::WRITE
);
68 vcl::PNGWriter
aWriter(aResultBitmap
);
69 CPPUNIT_ASSERT(aWriter
.Write(aStream
));
72 return aResultBitmap
.GetBitmap();
77 CPPUNIT_TEST_SUITE(Test
);
78 CPPUNIT_TEST(testFdo77229
);
79 CPPUNIT_TEST_SUITE_END();
81 uno::Reference
<lang::XComponent
> mxComponent
;
84 void Test::testFdo77229()
86 Bitmap aBitmap
= load("fdo77229.emf");
87 Bitmap::ScopedReadAccess
pAccess(aBitmap
);
88 // The green star was missing.
89 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0x00fe00), Color(pAccess
->GetPixel(142, 140)).GetColor());
92 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
94 CPPUNIT_PLUGIN_IMPLEMENT();
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */