Kaydet (Commit) 031c2771 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

add test for ImportUnloadedGraphic and GraphicDescriptor

Change-Id: Ibe4d7661462b0a7039fdd09b6a7b619bd0c0362b
Reviewed-on: https://gerrit.libreoffice.org/53584Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst edd0d355
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# 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/.
#
$(eval $(call gb_CppunitTest_CppunitTest,vcl_graphic_test))
$(eval $(call gb_CppunitTest_add_exception_objects,vcl_graphic_test, \
vcl/qa/cppunit/GraphicTest \
vcl/qa/cppunit/GraphicDescriptorTest \
))
$(eval $(call gb_CppunitTest_use_externals,vcl_graphic_test,\
boost_headers \
glm_headers \
))
$(eval $(call gb_CppunitTest_set_include,vcl_graphic_test,\
$$(INCLUDE) \
-I$(SRCDIR)/vcl/inc \
))
$(eval $(call gb_CppunitTest_use_libraries,vcl_graphic_test, \
comphelper \
cppu \
cppuhelper \
sal \
svt \
test \
tl \
unotest \
vcl \
utl \
))
$(eval $(call gb_CppunitTest_use_sdk_api,vcl_graphic_test))
$(eval $(call gb_CppunitTest_use_ure,vcl_graphic_test))
$(eval $(call gb_CppunitTest_use_vcl,vcl_graphic_test))
$(eval $(call gb_CppunitTest_use_components,vcl_graphic_test,\
configmgr/source/configmgr \
i18npool/util/i18npool \
ucb/source/core/ucb1 \
unotools/util/utl \
))
$(eval $(call gb_CppunitTest_use_configuration,vcl_graphic_test))
# vim: set noet sw=4 ts=4:
......@@ -180,6 +180,7 @@ $(eval $(call gb_Module_add_check_targets,vcl,\
CppunitTest_vcl_lifecycle \
CppunitTest_vcl_bitmap_test \
CppunitTest_vcl_bitmapprocessor_test \
CppunitTest_vcl_graphic_test \
CppunitTest_vcl_fontcharmap \
CppunitTest_vcl_font \
CppunitTest_vcl_fontmetric \
......
/* -*- 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 <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <vcl/graph.hxx>
#include <vcl/graphicfilter.hxx>
#include <tools/stream.hxx>
using namespace css;
namespace
{
class GraphicDescriptorTest : public CppUnit::TestFixture
{
void testDetectPNG();
void testDetectJPG();
void testDetectGIF();
CPPUNIT_TEST_SUITE(GraphicDescriptorTest);
CPPUNIT_TEST(testDetectPNG);
CPPUNIT_TEST(testDetectJPG);
CPPUNIT_TEST(testDetectGIF);
CPPUNIT_TEST_SUITE_END();
};
BitmapEx createBitmap()
{
Bitmap aBitmap(Size(100, 100), 24);
aBitmap.Erase(COL_LIGHTRED);
return BitmapEx(aBitmap);
}
void createBitmapAndExportForType(SvStream& rStream, OUString const& sType)
{
BitmapEx aBitmapEx = createBitmap();
uno::Sequence<beans::PropertyValue> aFilterData;
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
sal_uInt16 nFilterFormat = rGraphicFilter.GetExportFormatNumberForShortName(sType);
rGraphicFilter.ExportGraphic(aBitmapEx, "none", rStream, nFilterFormat, &aFilterData);
rStream.Seek(STREAM_SEEK_TO_BEGIN);
}
void GraphicDescriptorTest::testDetectPNG()
{
SvMemoryStream aStream;
createBitmapAndExportForType(aStream, "png");
GraphicDescriptor aDescriptor(aStream, nullptr);
aDescriptor.Detect(true);
CPPUNIT_ASSERT_EQUAL(GraphicFileFormat::PNG, aDescriptor.GetFileFormat());
CPPUNIT_ASSERT_EQUAL(100L, aDescriptor.GetSizePixel().Width());
CPPUNIT_ASSERT_EQUAL(100L, aDescriptor.GetSizePixel().Height());
}
void GraphicDescriptorTest::testDetectJPG()
{
SvMemoryStream aStream;
createBitmapAndExportForType(aStream, "jpg");
GraphicDescriptor aDescriptor(aStream, nullptr);
aDescriptor.Detect(true);
CPPUNIT_ASSERT_EQUAL(GraphicFileFormat::JPG, aDescriptor.GetFileFormat());
CPPUNIT_ASSERT_EQUAL(100L, aDescriptor.GetSizePixel().Width());
CPPUNIT_ASSERT_EQUAL(100L, aDescriptor.GetSizePixel().Height());
}
void GraphicDescriptorTest::testDetectGIF()
{
SvMemoryStream aStream;
createBitmapAndExportForType(aStream, "gif");
GraphicDescriptor aDescriptor(aStream, nullptr);
aDescriptor.Detect(true);
CPPUNIT_ASSERT_EQUAL(GraphicFileFormat::GIF, aDescriptor.GetFileFormat());
CPPUNIT_ASSERT_EQUAL(100L, aDescriptor.GetSizePixel().Width());
CPPUNIT_ASSERT_EQUAL(100L, aDescriptor.GetSizePixel().Height());
}
} // namespace
CPPUNIT_TEST_SUITE_REGISTRATION(GraphicDescriptorTest);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment