diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2015-10-16 12:18:50 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2015-10-16 12:19:13 +0200 |
commit | e324766d54ef67625b4ca9ba727a95316c2a1dc5 (patch) | |
tree | 171e9319cb1806829fc6047f780fa10043cf8cea | |
parent | sfx items: Kill the unreadable & misplaced SFX_ITEMSET_ARG too. (diff) | |
download | core-e324766d54ef67625b4ca9ba727a95316c2a1dc5.tar.gz core-e324766d54ef67625b4ca9ba727a95316c2a1dc5.zip |
Use CPPUNIT_ASSERT_EQUAL for better failure reports
Change-Id: If493763369581338325601edba2c12f96367f515
-rw-r--r-- | basebmp/test/basictest.cxx | 198 |
1 files changed, 114 insertions, 84 deletions
diff --git a/basebmp/test/basictest.cxx b/basebmp/test/basictest.cxx index 3531b6a42715..5137fbaeabd8 100644 --- a/basebmp/test/basictest.cxx +++ b/basebmp/test/basictest.cxx @@ -17,7 +17,12 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -// autogenerated file with codegen.pl +#include <sal/config.h> + +#include <iomanip> +#include <ios> +#include <ostream> +#include <type_traits> #include <cppunit/TestAssert.h> #include <cppunit/TestFixture.h> @@ -34,8 +39,31 @@ using namespace ::basebmp; +namespace basebmp { + +template<typename charT, typename traits> +std::basic_ostream<charT, traits> & operator <<( + std::basic_ostream<charT, traits> & stream, Color const & value) +{ + auto f = stream.flags(); + return stream + << std::hex << std::uppercase << std::setw(8) << std::setfill('0') + << value.toInt32() << std::setiosflags(f); +} + +template<typename charT, typename traits> +std::basic_ostream<charT, traits> & operator <<( + std::basic_ostream<charT, traits> & stream, Format value) +{ + return stream + << static_cast<typename std::underlying_type<Format>::type>(value); +} + +} + namespace { + class BasicTest : public CppUnit::TestFixture { public: @@ -44,36 +72,36 @@ public: Color aTestColor; aTestColor = Color(0xDEADBEEF); - CPPUNIT_ASSERT_MESSAGE("unary constructor", - aTestColor.toInt32() == 0xDEADBEEF ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("unary constructor", + sal_uInt32(0xDEADBEEF), aTestColor.toInt32() ); aTestColor = Color( 0x10, 0x20, 0xFF ); - CPPUNIT_ASSERT_MESSAGE("ternary constructor", - aTestColor.toInt32() == 0x001020FF ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("ternary constructor", + sal_uInt32(0x001020FF), aTestColor.toInt32() ); aTestColor.setRed( 0x0F ); - CPPUNIT_ASSERT_MESSAGE("setRed()", - aTestColor.toInt32() == 0x00F20FF ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("setRed()", + sal_uInt32(0x00F20FF), aTestColor.toInt32() ); aTestColor.setGreen( 0x0F ); - CPPUNIT_ASSERT_MESSAGE("setGreen()", - aTestColor.toInt32() == 0x00F0FFF ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("setGreen()", + sal_uInt32(0x00F0FFF), aTestColor.toInt32() ); aTestColor.setBlue( 0x10 ); - CPPUNIT_ASSERT_MESSAGE("setBlue()", - aTestColor.toInt32() == 0x00F0F10 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("setBlue()", + sal_uInt32(0x00F0F10), aTestColor.toInt32() ); aTestColor.setGrey( 0x13 ); - CPPUNIT_ASSERT_MESSAGE("setGrey()", - aTestColor.toInt32() == 0x00131313 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("setGrey()", + sal_uInt32(0x00131313), aTestColor.toInt32() ); aTestColor = Color( 0x10, 0x20, 0xFF ); - CPPUNIT_ASSERT_MESSAGE("getRed()", - aTestColor.getRed() == 0x10 ); - CPPUNIT_ASSERT_MESSAGE("getGreen()", - aTestColor.getGreen() == 0x20 ); - CPPUNIT_ASSERT_MESSAGE("getBlue()", - aTestColor.getBlue() == 0xFF ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("getRed()", + sal_uInt8(0x10), aTestColor.getRed() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("getGreen()", + sal_uInt8(0x20), aTestColor.getGreen() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("getBlue()", + sal_uInt8(0xFF), aTestColor.getBlue() ); } @@ -85,20 +113,20 @@ public: true, Format::OneBitMsbPal, basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX()))); - CPPUNIT_ASSERT_MESSAGE("right size", - pDevice->getSize() == aSize2 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("right size", + aSize2, pDevice->getSize() ); CPPUNIT_ASSERT_MESSAGE("Top down format", pDevice->isTopDown() ); - CPPUNIT_ASSERT_MESSAGE("Scanline format", - pDevice->getScanlineFormat() == Format::OneBitMsbPal ); - CPPUNIT_ASSERT_MESSAGE("Scanline len", - pDevice->getScanlineStride() == (aSize2.getY() + 7)/8 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Scanline format", + Format::OneBitMsbPal, pDevice->getScanlineFormat() ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Scanline len", + (aSize2.getY() + 7)/8, pDevice->getScanlineStride() ); CPPUNIT_ASSERT_MESSAGE("Palette existence", pDevice->getPalette() ); - CPPUNIT_ASSERT_MESSAGE("Palette entry 0 is black", - (*pDevice->getPalette())[0] == Color(0) ); - CPPUNIT_ASSERT_MESSAGE("Palette entry 1 is white", - (*pDevice->getPalette())[1] == Color(0xFFFFFFFF) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Palette entry 0 is black", + Color(0), (*pDevice->getPalette())[0] ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Palette entry 1 is white", + Color(0xFFFFFFFF), (*pDevice->getPalette())[1] ); } void testClone() @@ -113,8 +141,8 @@ public: BitmapDeviceSharedPtr pClone( cloneBitmapDevice( aSize2, pDevice )); - CPPUNIT_ASSERT_MESSAGE("right size", - pClone->getSize() == aSize2 ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("right size", + aSize2, pClone->getSize() ); } void testPixelFuncs() @@ -127,31 +155,31 @@ public: basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX()))); const basegfx::B2IPoint aPt(3,3); - CPPUNIT_ASSERT_MESSAGE("getPixelData for virgin device", - pDevice->getPixelData(aPt) == 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("getPixelData for virgin device", + sal_uInt32(0), pDevice->getPixelData(aPt)); const Color aCol(0xFFFFFFFF); pDevice->setPixel( aPt, aCol, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #1", - pDevice->getPixel(aPt) == aCol); - CPPUNIT_ASSERT_MESSAGE("getPixelData for white pixel", - pDevice->getPixelData(aPt) == 1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #1", + aCol, pDevice->getPixel(aPt)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("getPixelData for white pixel", + sal_uInt32(1), pDevice->getPixelData(aPt)); const basegfx::B2IPoint aPt2(0,0); const Color aCol2(0xFFFFFFFF); pDevice->setPixel( aPt2, aCol2, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #2", - pDevice->getPixel(aPt2) == aCol2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #2", + aCol2, pDevice->getPixel(aPt2)); const basegfx::B2IPoint aPt3(aSize.getX()-1,aSize.getY()-1); const Color aCol3(0x00000000); pDevice->setPixel( aPt3, aCol3, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3", - pDevice->getPixel(aPt3) == aCol3); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #3", + aCol3, pDevice->getPixel(aPt3)); pDevice->setPixel( aPt3, aCol2, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3.5", - pDevice->getPixel(aPt3) == aCol2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #3.5", + aCol2, pDevice->getPixel(aPt3)); const basegfx::B2IPoint aPt4(-100000,-100000); pDevice->setPixel( aPt4, aCol3, DrawMode::Paint ); @@ -161,11 +189,11 @@ public: sal_Int32 nPixel(countPixel(pDevice, aCol2)); const basegfx::B2IPoint aPt6(aSize.getX(),aSize.getY()); pDevice->setPixel( aPt6, aCol2, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("setPixel clipping", - countPixel(pDevice, aCol2) == nPixel); + CPPUNIT_ASSERT_EQUAL_MESSAGE("setPixel clipping", + nPixel, countPixel(pDevice, aCol2)); - CPPUNIT_ASSERT_MESSAGE("raw pixel value #1", - pDevice->getBuffer()[0] == 0x80); + CPPUNIT_ASSERT_EQUAL_MESSAGE("raw pixel value #1", + sal_uInt8(0x80), pDevice->getBuffer()[0]); // 1bit LSB { @@ -175,22 +203,22 @@ public: basebmp::getBitmapDeviceStrideForWidth(Format::OneBitLsbPal, aSize.getX())); pDevice->setPixel( aPt2, aCol, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4", - pDevice->getPixel(aPt2) == aCol); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #4", + aCol, pDevice->getPixel(aPt2)); const basegfx::B2IPoint aPt222(1,1); pDevice->setPixel( aPt222, aCol, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5", - pDevice->getPixel(aPt222) == aCol); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #5", + aCol, pDevice->getPixel(aPt222)); pDevice->setPixel( aPt3, aCol, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6", - pDevice->getPixel(aPt3) == aCol); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #6", + aCol, pDevice->getPixel(aPt3)); - CPPUNIT_ASSERT_MESSAGE("raw pixel value #2", - pDevice->getBuffer()[0] == 0x01); - CPPUNIT_ASSERT_MESSAGE("raw pixel value #3", - pDevice->getBuffer()[8] == 0x02); + CPPUNIT_ASSERT_EQUAL_MESSAGE("raw pixel value #2", + sal_uInt8(0x01), pDevice->getBuffer()[0]); + CPPUNIT_ASSERT_EQUAL_MESSAGE("raw pixel value #3", + sal_uInt8(0x02), pDevice->getBuffer()[8]); } // 8bit alpha @@ -202,18 +230,18 @@ public: const Color aCol4(0x010101); pDevice->setPixel( aPt, aCol4, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4", - pDevice->getPixel(aPt) == aCol4); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #4", + aCol4, pDevice->getPixel(aPt)); const Color aCol5(0x0F0F0F); pDevice->setPixel( aPt2, aCol5, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5", - pDevice->getPixel(aPt2) == aCol5); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #5", + aCol5, pDevice->getPixel(aPt2)); const Color aCol6(0xFFFFFF); pDevice->setPixel( aPt3, aCol6, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6", - pDevice->getPixel(aPt3) == aCol6); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #6", + aCol6, pDevice->getPixel(aPt3)); } // 16bpp @@ -227,8 +255,8 @@ public: const Color aCol4(0x00101010); pDevice->setPixel( aPt, aCol4, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #7", - pDevice->getPixel(aPt) == aCol4); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #7", + aCol4, pDevice->getPixel(aPt)); const Color aCol5(0x00F0F0F0); pDevice->setPixel( aPt2, aCol5, DrawMode::Paint ); @@ -237,8 +265,8 @@ public: const Color aCol6(0x00FFFFFF); pDevice->setPixel( aPt3, aCol6, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #9", - pDevice->getPixel(aPt3) == aCol6); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #9", + aCol6, pDevice->getPixel(aPt3)); } // 24bpp @@ -250,23 +278,25 @@ public: const Color aCol4(0x01010101); pDevice->setPixel( aPt, aCol4, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #10", - pDevice->getPixel(aPt) == aCol4); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #10", + aCol4, pDevice->getPixel(aPt)); const Color aCol5(0x0F3F2F1F); pDevice->setPixel( aPt2, aCol5, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #11", - pDevice->getPixel(aPt2) == aCol5); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #11", + aCol5, pDevice->getPixel(aPt2)); const Color aCol6(0xFFFFFFFF); pDevice->setPixel( aPt3, aCol6, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #12", - pDevice->getPixel(aPt3) == aCol6); - - CPPUNIT_ASSERT_MESSAGE("raw pixel value #4", - pDevice->getBuffer()[2] == 0x3F - && pDevice->getBuffer()[1] == 0x2F - && pDevice->getBuffer()[0] == 0x1F); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #12", + aCol6, pDevice->getPixel(aPt3)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("raw pixel value #4", + sal_uInt8(0x3F), pDevice->getBuffer()[2]); + CPPUNIT_ASSERT_EQUAL_MESSAGE("raw pixel value #4", + sal_uInt8(0x2F), pDevice->getBuffer()[1]); + CPPUNIT_ASSERT_EQUAL_MESSAGE("raw pixel value #4", + sal_uInt8(0x1F), pDevice->getBuffer()[0]); } // 32bpp @@ -278,18 +308,18 @@ public: const Color aCol4(0x01010101); pDevice->setPixel( aPt, aCol4, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #13", - pDevice->getPixel(aPt) == aCol4); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #13", + aCol4, pDevice->getPixel(aPt)); const Color aCol5(0x0F0F0F0F); pDevice->setPixel( aPt2, aCol5, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #14", - pDevice->getPixel(aPt2) == aCol5); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #14", + aCol5, pDevice->getPixel(aPt2)); const Color aCol6(0xFFFFFFFF); pDevice->setPixel( aPt3, aCol6, DrawMode::Paint ); - CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #15", - pDevice->getPixel(aPt3) == aCol6); + CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #15", + aCol6, pDevice->getPixel(aPt3)); } } |