diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2016-06-26 11:31:07 +0800 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2016-11-16 11:10:27 +0100 |
commit | ee4afce1bd51e78114c44efdeed3f77ff4592e62 (patch) | |
tree | 17a4e19b83ec393db753c6c9f910ec116e484789 | |
parent | 0b6b7bc71d358794146295e255d6d14d4bbb9452 (diff) |
vcl: Test for PngReader - reading of various PNG formats
Change-Id: I2469751806e03c791c1882a32c31c090d7dac39f
-rw-r--r-- | vcl/CppunitTest_vcl_png_test.mk | 52 | ||||
-rw-r--r-- | vcl/Module_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/qa/cppunit/png/PngFilterTest.cxx | 136 | ||||
-rw-r--r-- | vcl/qa/cppunit/png/data/alpha-rect-8bit-RGBA.png | bin | 0 -> 158 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/png/data/color-rect-4bit-pal.png | bin | 0 -> 104 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/png/data/color-rect-8bit-RGB.png | bin | 0 -> 90 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/png/data/rect-1bit-pal.png | bin | 0 -> 89 bytes |
7 files changed, 189 insertions, 0 deletions
diff --git a/vcl/CppunitTest_vcl_png_test.mk b/vcl/CppunitTest_vcl_png_test.mk new file mode 100644 index 000000000000..1f88209313a0 --- /dev/null +++ b/vcl/CppunitTest_vcl_png_test.mk @@ -0,0 +1,52 @@ +# -*- 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_png_test)) + +$(eval $(call gb_CppunitTest_add_exception_objects,vcl_png_test, \ + vcl/qa/cppunit/png/PngFilterTest \ +)) + +$(eval $(call gb_CppunitTest_set_include,vcl_png_test,\ + $$(INCLUDE) \ + -I$(SRCDIR)/vcl/inc \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,vcl_png_test, \ + comphelper \ + cppu \ + cppuhelper \ + sal \ + svt \ + test \ + tl \ + unotest \ + vcl \ + utl \ + $(gb_UWINAPI) \ +)) + +$(eval $(call gb_CppunitTest_use_api,vcl_png_test,\ + udkapi \ + offapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,vcl_png_test)) +$(eval $(call gb_CppunitTest_use_vcl,vcl_png_test)) + +$(eval $(call gb_CppunitTest_use_components,vcl_png_test,\ + configmgr/source/configmgr \ + i18npool/util/i18npool \ + ucb/source/core/ucb1 \ + unotools/util/utl \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,vcl_png_test)) + +# vim: set noet sw=4 ts=4: diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk index 97e20f013f8e..3bc4f648d488 100644 --- a/vcl/Module_vcl.mk +++ b/vcl/Module_vcl.mk @@ -109,6 +109,7 @@ $(eval $(call gb_Module_add_check_targets,vcl,\ CppunitTest_vcl_app_test \ $(if $(MERGELIBS),,CppunitTest_vcl_wmf_test) \ CppunitTest_vcl_jpeg_read_write_test \ + CppunitTest_vcl_png_test \ )) diff --git a/vcl/qa/cppunit/png/PngFilterTest.cxx b/vcl/qa/cppunit/png/PngFilterTest.cxx new file mode 100644 index 000000000000..14e32a6a2ebd --- /dev/null +++ b/vcl/qa/cppunit/png/PngFilterTest.cxx @@ -0,0 +1,136 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <test/bootstrapfixture.hxx> +#include <vcl/filter/PngReader.hxx> +#include <vcl/bitmapaccess.hxx> + +using namespace css; + +class PngFilterTest : public test::BootstrapFixture +{ + OUString maDataUrl; + + OUString getFullUrl(const OUString& sFileName) + { + return m_directories.getURLFromSrc(maDataUrl) + sFileName; + } + +public: + PngFilterTest() : + BootstrapFixture(true, false), + maDataUrl("/vcl/qa/cppunit/png/data/") + {} + + void testPng(); + + CPPUNIT_TEST_SUITE(PngFilterTest); + CPPUNIT_TEST(testPng); + CPPUNIT_TEST_SUITE_END(); +}; + +void PngFilterTest::testPng() +{ + for (const OUString& aFileName: { OUString("rect-1bit-pal.png") }) + { + SvFileStream aFileStream(getFullUrl(aFileName), StreamMode::READ); + + Graphic aGraphic; + vcl::PngReader aPngReader(aFileStream); + aPngReader.Read(aGraphic); + + Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap(); + { + Bitmap::ScopedReadAccess pAccess(aBitmap); + CPPUNIT_ASSERT_EQUAL(32, int(pAccess->GetBitCount())); + CPPUNIT_ASSERT_EQUAL(4l, pAccess->Width()); + CPPUNIT_ASSERT_EQUAL(4l, pAccess->Height()); + + CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(0,0)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(3,3)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(3,0)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(0,3)).GetColor()); + + CPPUNIT_ASSERT_EQUAL(ColorData(0x00000000), Color(pAccess->GetPixel(1,1)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x00000000), Color(pAccess->GetPixel(1,2)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x00000000), Color(pAccess->GetPixel(2,1)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x00000000), Color(pAccess->GetPixel(2,2)).GetColor()); + } + } + for (const OUString& aFileName: { OUString("color-rect-8bit-RGB.png"), OUString("color-rect-4bit-pal.png") }) + { + SvFileStream aFileStream(getFullUrl(aFileName), StreamMode::READ); + + Graphic aGraphic; + vcl::PngReader aPngReader(aFileStream); + aPngReader.Read(aGraphic); + + Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap(); + { + Bitmap::ScopedReadAccess pAccess(aBitmap); + CPPUNIT_ASSERT_EQUAL(32, int(pAccess->GetBitCount())); + CPPUNIT_ASSERT_EQUAL(4l, pAccess->Width()); + CPPUNIT_ASSERT_EQUAL(4l, pAccess->Height()); + + CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(0,0)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(3,3)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(3,0)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFFFF), Color(pAccess->GetPixel(0,3)).GetColor()); + + CPPUNIT_ASSERT_EQUAL(ColorData(0x00FF0000), Color(pAccess->GetPixel(1,1)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x0000FF00), Color(pAccess->GetPixel(1,2)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x000000FF), Color(pAccess->GetPixel(2,1)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x00FFFF00), Color(pAccess->GetPixel(2,2)).GetColor()); + } + } + for (const OUString& aFileName: { OUString("alpha-rect-8bit-RGBA.png") }) + { + SvFileStream aFileStream(getFullUrl(aFileName), StreamMode::READ); + + Graphic aGraphic; + vcl::PngReader aPngReader(aFileStream); + aPngReader.Read(aGraphic); + + Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap(); + { + Bitmap::ScopedReadAccess pAccess(aBitmap); + CPPUNIT_ASSERT_EQUAL(32, int(pAccess->GetBitCount())); + CPPUNIT_ASSERT_EQUAL(4l, pAccess->Width()); + CPPUNIT_ASSERT_EQUAL(4l, pAccess->Height()); + + printf("%08X\n", Color(pAccess->GetPixel(1,1)).GetColor()); + + CPPUNIT_ASSERT_EQUAL(ColorData(0x80FFFFFF), Color(pAccess->GetPixel(0,0)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x80FFFFFF), Color(pAccess->GetPixel(3,3)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x80FFFFFF), Color(pAccess->GetPixel(3,0)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x80FFFFFF), Color(pAccess->GetPixel(0,3)).GetColor()); + + CPPUNIT_ASSERT_EQUAL(ColorData(0x40FF0000), Color(pAccess->GetPixel(1,1)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0xC000FF00), Color(pAccess->GetPixel(1,2)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0xC00000FF), Color(pAccess->GetPixel(2,1)).GetColor()); + CPPUNIT_ASSERT_EQUAL(ColorData(0x40FFFF00), Color(pAccess->GetPixel(2,2)).GetColor()); + } + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(PngFilterTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qa/cppunit/png/data/alpha-rect-8bit-RGBA.png b/vcl/qa/cppunit/png/data/alpha-rect-8bit-RGBA.png Binary files differnew file mode 100644 index 000000000000..1e90e1a6cfed --- /dev/null +++ b/vcl/qa/cppunit/png/data/alpha-rect-8bit-RGBA.png diff --git a/vcl/qa/cppunit/png/data/color-rect-4bit-pal.png b/vcl/qa/cppunit/png/data/color-rect-4bit-pal.png Binary files differnew file mode 100644 index 000000000000..740eede512d1 --- /dev/null +++ b/vcl/qa/cppunit/png/data/color-rect-4bit-pal.png diff --git a/vcl/qa/cppunit/png/data/color-rect-8bit-RGB.png b/vcl/qa/cppunit/png/data/color-rect-8bit-RGB.png Binary files differnew file mode 100644 index 000000000000..727859d8a7c1 --- /dev/null +++ b/vcl/qa/cppunit/png/data/color-rect-8bit-RGB.png diff --git a/vcl/qa/cppunit/png/data/rect-1bit-pal.png b/vcl/qa/cppunit/png/data/rect-1bit-pal.png Binary files differnew file mode 100644 index 000000000000..cf7ac3e7c31b --- /dev/null +++ b/vcl/qa/cppunit/png/data/rect-1bit-pal.png |