Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ImageTestCase.h

Go to the documentation of this file.
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     // compare sizes
00034     CPPUNIT_ASSERT(i1->getWidth()  == i2->getWidth() &&
00035                    i1->getHeight() == i2->getHeight());
00036     
00037     // by this point, we can assume they have the same size
00038     int width  = i1->getWidth();
00039     int height = i1->getHeight();
00040     
00041     // compare formats
00042     PixelFormat i1_format = i1->getFormat();
00043     CPPUNIT_ASSERT_MESSAGE(message, i1_format == i2->getFormat());
00044 
00045     // compare pixel data
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     // compare palette formats
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     // compare palette sizes
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     // compare palette data
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

Generated on Thu Oct 2 12:59:30 2003 for corona by doxygen1.3-rc1