91 lines
2.5 KiB
C++
91 lines
2.5 KiB
C++
![]() |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||
|
/*
|
||
|
* This file is part of the LibreOffice project.
|
||
|
*
|
||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||
|
*/
|
||
|
|
||
|
#include <cppunit/TestAssert.h>
|
||
|
#include <cppunit/TestFixture.h>
|
||
|
#include <cppunit/extensions/HelperMacros.h>
|
||
|
#include <cppunit/plugin/TestPlugIn.h>
|
||
|
|
||
|
#include <vcl/graph.hxx>
|
||
|
#include <vcl/graphicfilter.hxx>
|
||
|
#include <tools/stream.hxx>
|
||
|
#include <vcl/pngwrite.hxx>
|
||
|
|
||
|
namespace
|
||
|
{
|
||
|
class GraphicTest : public CppUnit::TestFixture
|
||
|
{
|
||
|
void testUnloadedGraphic();
|
||
|
|
||
|
CPPUNIT_TEST_SUITE(GraphicTest);
|
||
|
CPPUNIT_TEST(testUnloadedGraphic);
|
||
|
CPPUNIT_TEST_SUITE_END();
|
||
|
};
|
||
|
|
||
|
BitmapEx createBitmap()
|
||
|
{
|
||
|
Bitmap aBitmap(Size(100, 100), 24);
|
||
|
aBitmap.Erase(COL_LIGHTRED);
|
||
|
|
||
|
return BitmapEx(aBitmap);
|
||
|
}
|
||
|
|
||
|
void createBitmapAndExportToPNG(SvStream& rStream)
|
||
|
{
|
||
|
BitmapEx aBitmapEx = createBitmap();
|
||
|
|
||
|
vcl::PNGWriter aWriter(aBitmapEx);
|
||
|
aWriter.Write(rStream);
|
||
|
|
||
|
rStream.Seek(STREAM_SEEK_TO_BEGIN);
|
||
|
}
|
||
|
|
||
|
Graphic makeUnloadedGraphic()
|
||
|
{
|
||
|
SvMemoryStream aStream;
|
||
|
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
|
||
|
createBitmapAndExportToPNG(aStream);
|
||
|
return rGraphicFilter.ImportUnloadedGraphic(aStream);
|
||
|
}
|
||
|
|
||
|
void GraphicTest::testUnloadedGraphic()
|
||
|
{
|
||
|
// make unloaded test graphic
|
||
|
Graphic aGraphic = makeUnloadedGraphic();
|
||
|
Graphic aGraphic2 = aGraphic;
|
||
|
|
||
|
// check available
|
||
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
||
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic2.isAvailable());
|
||
|
|
||
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic2.makeAvailable());
|
||
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
||
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic2.isAvailable());
|
||
|
|
||
|
// check GetSizePixel doesn't load graphic
|
||
|
aGraphic = makeUnloadedGraphic();
|
||
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
||
|
CPPUNIT_ASSERT_EQUAL(100L, aGraphic.GetSizePixel().Width());
|
||
|
CPPUNIT_ASSERT_EQUAL(100L, aGraphic.GetSizePixel().Height());
|
||
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
||
|
|
||
|
// check GetSizeBytes loads graphic
|
||
|
CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
|
||
|
CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > 0);
|
||
|
CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
|
||
|
}
|
||
|
|
||
|
} // namespace
|
||
|
|
||
|
CPPUNIT_TEST_SUITE_REGISTRATION(GraphicTest);
|
||
|
|
||
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
||
|
|
||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|