#endif // WX_PRECOMP
#include "wx/anidecod.h" // wxImageArray
-#include "wx/image.h"
#include "wx/palette.h"
#include "wx/url.h"
#include "wx/log.h"
#include "wx/zstream.h"
#include "wx/wfstream.h"
+#include "testimage.h"
+
struct testData {
const char* file;
wxBitmapType type;
CPPUNIT_ASSERT_EQUAL( actual.GetSize().x, expected.GetSize().x );
CPPUNIT_ASSERT_EQUAL( actual.GetSize().y, expected.GetSize().y );
- const unsigned data_len = 3 * expected.GetHeight() * expected.GetWidth();
-
- WX_ASSERT_MESSAGE
+ WX_ASSERT_EQUAL_MESSAGE
(
("Resize test #%u: (%d, %d), (%d, %d)", i, st.w, st.h, st.dx, st.dy),
- memcmp(actual.GetData(), expected.GetData(), data_len) == 0
+ expected, actual
);
}
}
wxImage expected24("horse.png");
CPPUNIT_ASSERT( expected24.IsOk() );
- const size_t dataLen = expected8.GetWidth() * expected8.GetHeight() * 3;
-
for (size_t i=0; i<WXSIZEOF(g_testfiles); i++)
{
if ( !(g_testfiles[i].bitDepth == 8 || g_testfiles[i].bitDepth == 24)
}
- WX_ASSERT_MESSAGE
+ WX_ASSERT_EQUAL_MESSAGE
(
("Compare test '%s' for loading failed", g_testfiles[i].file),
-
- memcmp(actual.GetData(),
- (g_testfiles[i].bitDepth == 8)
- ? expected8.GetData()
- : expected24.GetData(),
- dataLen) == 0
+ g_testfiles[i].bitDepth == 8 ? expected8 : expected24,
+ actual
);
}
CPPUNIT_ASSERT( actual.GetSize() == expected->GetSize() );
unsigned bitsPerPixel = testPalette ? 8 : (testAlpha ? 32 : 24);
- WX_ASSERT_MESSAGE
+ WX_ASSERT_EQUAL_MESSAGE
(
("Compare test '%s (%d-bit)' for saving failed",
handler.GetExtension(), bitsPerPixel),
-
- memcmp(actual.GetData(), expected->GetData(),
- expected->GetWidth() * expected->GetHeight() * 3) == 0
+ *expected,
+ actual
);
#if wxUSE_PALETTE
return;
}
- WX_ASSERT_MESSAGE
+ WX_ASSERT_EQUAL_MESSAGE
(
("Compare alpha test '%s' for saving failed", handler.GetExtension()),
-
- memcmp(actual.GetAlpha(), expected->GetAlpha(),
- expected->GetWidth() * expected->GetHeight()) == 0
+ *expected,
+ actual
);
}
CPPUNIT_ASSERT( handler.LoadFile(&image, memIn, true, i) );
memIn.SeekI(pos);
- WX_ASSERT_MESSAGE
+ WX_ASSERT_EQUAL_MESSAGE
(
("Compare test for GIF frame number %d failed", i),
- memcmp(image.GetData(), images[i].GetData(),
- images[i].GetWidth() * images[i].GetHeight() * 3) == 0
+ images[i],
+ image
);
}
#endif // #if wxUSE_PALETTE
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: tests/testimage.h
+// Purpose: Unit test helpers for dealing with wxImage.
+// Author: Vadim Zeitlin
+// RCS-ID: $Id$
+// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
+// Licence: wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_TESTS_TESTIMAGE_H_
+#define _WX_TESTS_TESTIMAGE_H_
+
+#include "wx/image.h"
+
+CPPUNIT_NS_BEGIN
+
+template <>
+struct assertion_traits<wxImage>
+{
+ static bool equal(const wxImage& i1, const wxImage& i2)
+ {
+ if ( i1.GetWidth() != i2.GetWidth() )
+ return false;
+
+ if ( i1.GetHeight() != i2.GetHeight() )
+ return false;
+
+ return memcmp(i1.GetData(), i2.GetData(),
+ i1.GetWidth()*i1.GetHeight()*3) == 0;
+ }
+
+ static std::string toString(const wxImage& image)
+ {
+ return wxString::Format("image of size %d*%d",
+ image.GetWidth(),
+ image.GetHeight())
+ .ToStdString();
+ }
+};
+
+CPPUNIT_NS_END
+
+#endif // _WX_TESTS_TESTIMAGE_H_