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 <cppunit/TestAssert.h>
11 #include <cppunit/TestFixture.h>
12 #include <cppunit/extensions/HelperMacros.h>
13 #include <unotest/bootstrapfixturebase.hxx>
15 #include <sal/types.h>
16 #include <sfx2/app.hxx>
17 #include <unotools/tempfile.hxx>
18 #include <svx/xtable.hxx>
19 #include <vcl/bitmapex.hxx>
21 #include <com/sun/star/awt/XBitmap.hpp>
22 #include <com/sun/star/graphic/XGraphic.hpp>
26 class XTableImportExportTest
: public CppUnit::TestFixture
29 virtual void setUp() override
31 CppUnit::TestFixture::setUp();
32 SfxApplication::GetOrCreate();
36 CPPUNIT_TEST_FIXTURE(XTableImportExportTest
, testImportExport
)
38 utl::TempFileNamed
aTempFile(nullptr, true);
39 aTempFile
.EnableKillingFile();
40 OUString aTempURL
= aTempFile
.GetURL();
41 BitmapChecksum
aChecksum(0);
44 rtl::Reference
<XBitmapList
> xBitmapList
= new XBitmapList(aTempURL
, u
"REF"_ustr
);
45 uno::Reference
<container::XNameContainer
> xNameContainer(xBitmapList
->createInstance());
46 CPPUNIT_ASSERT(xNameContainer
.is());
48 Bitmap
aBitmap(Size(5, 5), vcl::PixelFormat::N24_BPP
);
49 aBitmap
.Erase(COL_RED
);
50 BitmapEx
aBitmapEx(aBitmap
);
51 Graphic
aGraphic(aBitmapEx
);
52 uno::Reference
<awt::XBitmap
> xBitmap(aGraphic
.GetXGraphic(), css::uno::UNO_QUERY
);
54 xNameContainer
->insertByName(u
"SomeBitmap"_ustr
, uno::Any(xBitmap
));
57 aChecksum
= aBitmap
.GetChecksum();
61 rtl::Reference
<XBitmapList
> xBitmapList
= new XBitmapList(aTempURL
, u
"REF"_ustr
);
62 bool bResult
= xBitmapList
->Load();
63 CPPUNIT_ASSERT(bResult
);
64 uno::Reference
<container::XNameContainer
> xNameContainer(xBitmapList
->createInstance());
65 CPPUNIT_ASSERT(xNameContainer
.is());
67 uno::Any aAny
= xNameContainer
->getByName(u
"SomeBitmap"_ustr
);
68 CPPUNIT_ASSERT(aAny
.has
<uno::Reference
<awt::XBitmap
>>());
69 auto xBitmap
= aAny
.get
<uno::Reference
<awt::XBitmap
>>();
70 CPPUNIT_ASSERT(xBitmap
.is());
71 uno::Reference
<graphic::XGraphic
> xGraphic(xBitmap
, uno::UNO_QUERY
);
72 CPPUNIT_ASSERT(xGraphic
.is());
73 Graphic
aGraphic(xGraphic
);
74 CPPUNIT_ASSERT(!aGraphic
.IsNone());
75 Bitmap aBitmap
= aGraphic
.GetBitmapEx().GetBitmap();
76 CPPUNIT_ASSERT_EQUAL(aChecksum
, aBitmap
.GetChecksum());
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */