diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2018-04-28 13:37:17 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-04-28 09:54:46 +0200 |
commit | 031c2771245dea800eb5f975660ed06e0afae05b (patch) | |
tree | 93dfd07608edda67ee82fd63e25a2704862e6c0c /vcl/qa | |
parent | edd0d35590fc368c6c06a9bb5c108aacbc742371 (diff) |
add test for ImportUnloadedGraphic and GraphicDescriptor
Change-Id: Ibe4d7661462b0a7039fdd09b6a7b619bd0c0362b
Reviewed-on: https://gerrit.libreoffice.org/53584
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r-- | vcl/qa/cppunit/GraphicDescriptorTest.cxx | 105 | ||||
-rw-r--r-- | vcl/qa/cppunit/GraphicTest.cxx | 90 |
2 files changed, 195 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/GraphicDescriptorTest.cxx b/vcl/qa/cppunit/GraphicDescriptorTest.cxx new file mode 100644 index 000000000000..c858fe2e942c --- /dev/null +++ b/vcl/qa/cppunit/GraphicDescriptorTest.cxx @@ -0,0 +1,105 @@ +/* -*- 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: */ diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx new file mode 100644 index 000000000000..d039ba1dec25 --- /dev/null +++ b/vcl/qa/cppunit/GraphicTest.cxx @@ -0,0 +1,90 @@ +/* -*- 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: */ |