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/frame/Desktop.hpp>
12 #include <comphelper/processfactory.hxx>
13 #include <sfx2/app.hxx>
14 #include <sfx2/objsh.hxx>
15 #include <sfx2/sfxbasemodel.hxx>
16 #include <test/unoapi_test.hxx>
17 #include <vcl/bitmapaccess.hxx>
18 #include <vcl/pngwrite.hxx>
19 #include <vcl/gdimtf.hxx>
20 #include <tools/stream.hxx>
22 using namespace com::sun::star
;
24 class Test
: public UnoApiTest
27 Test() : UnoApiTest("/cppcanvas/qa/extras/emfplus/data/")
31 virtual void setUp() override
34 mxDesktop
.set(frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())));
35 SfxApplication::GetOrCreate();
38 virtual void tearDown() override
42 closeDocument(mxComponent
);
43 mxComponent
->dispose();
45 UnoApiTest::tearDown();
48 Bitmap
load(const char* pName
)
51 createFileURL(OUString::createFromAscii(pName
), aFileURL
);
52 mxComponent
= loadFromDesktop(aFileURL
, "com.sun.star.drawing.DrawingDocument");
53 SfxBaseModel
* pModel
= dynamic_cast<SfxBaseModel
*>(mxComponent
.get());
54 CPPUNIT_ASSERT(pModel
);
55 SfxObjectShell
* pShell
= pModel
->GetObjectShell();
56 std::shared_ptr
<GDIMetaFile
> xMetaFile
= pShell
->GetPreviewMetaFile();
57 BitmapEx aResultBitmap
;
58 CPPUNIT_ASSERT(xMetaFile
->CreateThumbnail(aResultBitmap
));
59 // If this is set, the metafile will be dumped as a PNG one for debug purposes.
60 char* pEnv
= getenv("CPPCANVAS_DEBUG_EMFPLUS_DUMP_TO");
63 SvFileStream
aStream(OUString::fromUtf8(pEnv
), StreamMode::WRITE
);
64 vcl::PNGWriter
aWriter(aResultBitmap
);
65 CPPUNIT_ASSERT(aWriter
.Write(aStream
));
68 return aResultBitmap
.GetBitmap();
71 uno::Reference
<lang::XComponent
> mxComponent
;
74 CPPUNIT_TEST_FIXTURE(Test
, testFdo77229
)
76 Bitmap aBitmap
= load("fdo77229.emf");
77 Bitmap::ScopedReadAccess
pAccess(aBitmap
);
78 // The green star was missing.
79 Color
aColor(pAccess
->GetPixel(142, 140));
80 CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), aColor
.GetRed());
81 CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), aColor
.GetBlue());
82 CPPUNIT_ASSERT(aColor
.GetGreen() == 0xfe || aColor
.GetGreen() == 0xff);
85 CPPUNIT_PLUGIN_IMPLEMENT();
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */