diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-03-25 11:35:55 +0900 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-03-27 10:45:15 +0900 |
commit | 44c6c4da9545d69ad02f5e8ea1314388e1eacec7 (patch) | |
tree | a5dd6a504abf7ae9374df22692d7357c2b8b7ce4 /vcl/qa/cppunit | |
parent | 389bf9e196aa7b783a325d7c00d41d943511d5ba (diff) |
vcl: tests for Bitmap, check for symmetry when scaling bitmaps
Change-Id: I53d6e70018477abb9f98140a52697c1de0f90934
Diffstat (limited to 'vcl/qa/cppunit')
-rw-r--r-- | vcl/qa/cppunit/BitmapTest.cxx | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx new file mode 100644 index 000000000000..cc8534f22a6a --- /dev/null +++ b/vcl/qa/cppunit/BitmapTest.cxx @@ -0,0 +1,88 @@ +/* -*- 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/bitmap.hxx> +#include <vcl/bmpacc.hxx> + +#include <tools/stream.hxx> +#include <vcl/graphicfilter.hxx> + +#include "BitmapSymmetryCheck.hxx" + +namespace +{ + +class BitmapTest : public CppUnit::TestFixture +{ + void testScale(); + + CPPUNIT_TEST_SUITE(BitmapTest); + CPPUNIT_TEST(testScale); + CPPUNIT_TEST_SUITE_END(); +}; + +void BitmapTest::testScale() +{ + bool bExportBitmap(false); + + Bitmap aBitmap24Bit(Size(10, 10), 24); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(24), aBitmap24Bit.GetBitCount()); + + { + Bitmap::ScopedWriteAccess aWriteAccess(aBitmap24Bit); + aWriteAccess->Erase(COL_WHITE); + aWriteAccess->SetLineColor(COL_BLACK); + aWriteAccess->DrawRect(Rectangle(1, 1, 8, 8)); + aWriteAccess->DrawRect(Rectangle(3, 3, 6, 6)); + } + + BitmapSymmetryCheck aBitmapSymmetryCheck; + + CPPUNIT_ASSERT_EQUAL(static_cast<long>(10), aBitmap24Bit.GetSizePixel().Width()); + CPPUNIT_ASSERT_EQUAL(static_cast<long>(10), aBitmap24Bit.GetSizePixel().Height()); + + // Check symmetry of the bitmap + CPPUNIT_ASSERT(aBitmapSymmetryCheck.check(aBitmap24Bit)); + + if (bExportBitmap) + { + SvFileStream aStream(OUString("~/scale_before.png"), StreamMode::WRITE | StreamMode::TRUNC); + GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); + rFilter.compressAsPNG(aBitmap24Bit, aStream, 9); + } + + aBitmap24Bit.Scale(2, 2, BMP_SCALE_FAST); + + CPPUNIT_ASSERT_EQUAL(static_cast<long>(20), aBitmap24Bit.GetSizePixel().Width()); + CPPUNIT_ASSERT_EQUAL(static_cast<long>(20), aBitmap24Bit.GetSizePixel().Height()); + + // After scaling the bitmap should still be symmetrical. This check guarantees that + // scaling doesn't misalign the bitmap. + CPPUNIT_ASSERT(aBitmapSymmetryCheck.check(aBitmap24Bit)); + + if (bExportBitmap) + { + SvFileStream aStream(OUString("~/scale_after.png"), StreamMode::WRITE | StreamMode::TRUNC); + GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); + rFilter.compressAsPNG(aBitmap24Bit, aStream, 9); + } +} + +} // namespace + +CPPUNIT_TEST_SUITE_REGISTRATION(BitmapTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |