[Libreoffice-commits] core.git: Branch 'libreoffice-5-0' - vcl/qa
Michael Meeks
michael.meeks at collabora.com
Wed Sep 2 02:14:49 PDT 2015
vcl/qa/cppunit/BitmapTest.cxx | 60 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
New commits:
commit 072f5090e57ddbc2954efafa38b57056a5e52abb
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Mon Jul 13 15:38:09 2015 +0100
tdf#93532 - Bitmap CRC unit tests.
Change-Id: Ic75801d7ad941ba802ffe418d5c666b1e7b0e94f
Reviewed-on: https://gerrit.libreoffice.org/18202
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx
index 306b0df..2c94e0e 100644
--- a/vcl/qa/cppunit/BitmapTest.cxx
+++ b/vcl/qa/cppunit/BitmapTest.cxx
@@ -12,9 +12,13 @@
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
+#include <unordered_map>
+
#include <vcl/bitmap.hxx>
#include <vcl/bmpacc.hxx>
+#include <vcl/virdev.hxx>
+#include <rtl/strbuf.hxx>
#include <tools/stream.hxx>
#include <vcl/graphicfilter.hxx>
@@ -27,10 +31,12 @@ class BitmapTest : public CppUnit::TestFixture
{
void testConvert();
void testScale();
+ void testCRC();
CPPUNIT_TEST_SUITE(BitmapTest);
CPPUNIT_TEST(testConvert);
CPPUNIT_TEST(testScale);
+ CPPUNIT_TEST(testCRC);
CPPUNIT_TEST_SUITE_END();
};
@@ -129,6 +135,60 @@ void BitmapTest::testScale()
}
}
+typedef std::unordered_map<sal_uInt64, const char *> CRCHash;
+
+void checkAndInsert(CRCHash &rHash, sal_uInt64 nCRC, const char *pLocation)
+{
+ auto it = rHash.find(nCRC);
+ if (it != rHash.end()) {
+ OStringBuffer aBuf("CRC collision between ");
+ aBuf.append(pLocation);
+ aBuf.append(" and ");
+ aBuf.append(it->second);
+ aBuf.append(" hash is 0x");
+ aBuf.append((sal_Int64)nCRC, 16);
+ CPPUNIT_FAIL(aBuf.toString().getStr());
+ }
+ rHash[nCRC] = pLocation;
+}
+
+void checkAndInsert(CRCHash &rHash, Bitmap rBmp, const char *pLocation)
+{
+ checkAndInsert(rHash, rBmp.GetChecksum(), pLocation);
+}
+
+Bitmap getAsBitmap(VclPtr<OutputDevice> pOut)
+{
+ return pOut->GetBitmap(Point(), pOut->GetOutputSizePixel());
+}
+
+void BitmapTest::testCRC()
+{
+ CRCHash aCRCs;
+
+ Bitmap aBitmap(Size(1023,759), 24, 0);
+ aBitmap.Erase(COL_BLACK);
+ checkAndInsert(aCRCs, aBitmap, "black bitmap");
+ aBitmap.Invert();
+ checkAndInsert(aCRCs, aBitmap, "white bitmap");
+
+ ScopedVclPtrInstance<VirtualDevice> aVDev;
+ aVDev->SetBackground(Wallpaper(COL_WHITE));
+ aVDev->SetOutputSizePixel(Size(1023, 759));
+
+#if 0 // disabled for now - it breaks on OS/X and Windows
+ Bitmap aWhiteCheck = getAsBitmap(aVDev);
+ CPPUNIT_ASSERT(aCRCs.find(aWhiteCheck.GetChecksum()) != aCRCs.end());
+#endif
+
+ // a 1x1 black & white checkerboard
+ aVDev->DrawCheckered(Point(), aVDev->GetOutputSizePixel(), 1, 1);
+ Bitmap aChecker = getAsBitmap(aVDev);
+ checkAndInsert(aCRCs, aChecker, "checkerboard");
+ aChecker.Invert();
+ checkAndInsert(aCRCs, aChecker, "inverted checkerboard");
+}
+
} // namespace
CPPUNIT_TEST_SUITE_REGISTRATION(BitmapTest);
More information about the Libreoffice-commits
mailing list