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 <config_features.h>
12 #include <cppunit/TestAssert.h>
13 #include <cppunit/TestFixture.h>
14 #include <cppunit/extensions/HelperMacros.h>
15 #include <unotest/bootstrapfixturebase.hxx>
17 #include <sal/types.h>
18 #include <sfx2/app.hxx>
19 #include <unotools/tempfile.hxx>
20 #include <svx/xtable.hxx>
21 #include <vcl/bitmapex.hxx>
22 #include <svx/XPropertyTable.hxx>
24 #include <xmlxtexp.hxx>
26 #include <com/sun/star/awt/XBitmap.hpp>
27 #include <com/sun/star/graphic/XGraphic.hpp>
31 class XTableImportExportTest
: public CppUnit::TestFixture
34 virtual void setUp() override
36 CppUnit::TestFixture::setUp();
37 SfxApplication::GetOrCreate();
41 CPPUNIT_TEST_FIXTURE(XTableImportExportTest
, testImportExport
)
43 utl::TempFile
aTempFile(nullptr, true);
44 aTempFile
.EnableKillingFile();
45 OUString aTempURL
= aTempFile
.GetURL();
46 BitmapChecksum
aChecksum(0);
49 XBitmapList
xBitmapList(aTempURL
, "REF");
50 uno::Reference
<container::XNameContainer
> xNameContainer(xBitmapList
.createInstance());
51 CPPUNIT_ASSERT(xNameContainer
.is());
53 Bitmap
aBitmap(Size(5, 5), 24);
54 aBitmap
.Erase(COL_RED
);
55 BitmapEx
aBitmapEx(aBitmap
);
56 Graphic
aGraphic(aBitmapEx
);
57 uno::Reference
<awt::XBitmap
> xBitmap(aGraphic
.GetXGraphic(), css::uno::UNO_QUERY
);
59 xNameContainer
->insertByName("SomeBitmap", uno::makeAny(xBitmap
));
62 aChecksum
= aBitmap
.GetChecksum();
66 XBitmapList
xBitmapList(aTempURL
, "REF");
67 bool bResult
= xBitmapList
.Load();
68 CPPUNIT_ASSERT(bResult
);
69 uno::Reference
<container::XNameContainer
> xNameContainer(xBitmapList
.createInstance());
70 CPPUNIT_ASSERT(xNameContainer
.is());
72 uno::Any aAny
= xNameContainer
->getByName("SomeBitmap");
73 CPPUNIT_ASSERT(aAny
.has
<uno::Reference
<awt::XBitmap
>>());
74 auto xBitmap
= aAny
.get
<uno::Reference
<awt::XBitmap
>>();
75 CPPUNIT_ASSERT(xBitmap
.is());
76 uno::Reference
<graphic::XGraphic
> xGraphic(xBitmap
, uno::UNO_QUERY
);
77 CPPUNIT_ASSERT(xGraphic
.is());
78 Graphic
aGraphic(xGraphic
);
79 CPPUNIT_ASSERT(!aGraphic
.IsNone());
80 Bitmap aBitmap
= aGraphic
.GetBitmapEx().GetBitmap();
81 CPPUNIT_ASSERT_EQUAL(aChecksum
, aBitmap
.GetChecksum());
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */