00001 #ifndef IMAGE_TEST_CASE_H
00002 #define IMAGE_TEST_CASE_H
00003
00004
00005 #include "TestFramework.h"
00006
00007
00008 class ImageTestCase : public CppUnit::TestCase {
00009 public:
00010 struct Comparison {
00011 const char* image;
00012 const char* reference;
00013 };
00014
00015 void AssertImagesEqual(
00016 const string& image_file,
00017 const string& reference_file)
00018 {
00019 auto_ptr<Image> img1(OpenImage(image_file.c_str(), PF_R8G8B8A8));
00020 CPPUNIT_ASSERT_MESSAGE("opening " + image_file, img1.get() != 0);
00021
00022 auto_ptr<Image> img2(OpenImage(reference_file.c_str(), PF_R8G8B8A8));
00023 CPPUNIT_ASSERT_MESSAGE("opening " + reference_file, img2.get() != 0);
00024
00025 AssertImagesEqual("testing " + image_file, img1.get(), img2.get());
00026 }
00027
00028 void AssertImagesEqual(
00029 const string& message,
00030 Image* i1,
00031 Image* i2)
00032 {
00033
00034 CPPUNIT_ASSERT(i1->getWidth() == i2->getWidth() &&
00035 i1->getHeight() == i2->getHeight());
00036
00037
00038 int width = i1->getWidth();
00039 int height = i1->getHeight();
00040
00041
00042 PixelFormat i1_format = i1->getFormat();
00043 CPPUNIT_ASSERT_MESSAGE(message, i1_format == i2->getFormat());
00044
00045
00046 int pixel_comparison = memcmp(
00047 i1->getPixels(),
00048 i2->getPixels(),
00049 width * height * GetPixelSize(i1_format));
00050 CPPUNIT_ASSERT_MESSAGE(message, pixel_comparison == 0);
00051
00052
00053 PixelFormat i1_plt_format = i1->getPaletteFormat();
00054 PixelFormat i2_plt_format = i2->getPaletteFormat();
00055 CPPUNIT_ASSERT_MESSAGE(message, i1_plt_format == i2_plt_format);
00056
00057
00058 int i1_plt_size = i1->getPaletteSize();
00059 int i2_plt_size = i2->getPaletteSize();
00060 CPPUNIT_ASSERT_MESSAGE(message, i1_plt_size == i2_plt_size);
00061
00062
00063 int palette_comparison = memcmp(
00064 i1->getPalette(),
00065 i2->getPalette(),
00066 i1_plt_size * GetPixelSize(i1_plt_format));
00067 CPPUNIT_ASSERT_MESSAGE(message, palette_comparison == 0);
00068 }
00069 };
00070
00071
00072 #endif