]> git.saurik.com Git - wxWidgets.git/commitdiff
Add a unit test for wxAffineMatrix2D class and its support in wxDC.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 26 Apr 2011 22:57:20 +0000 (22:57 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 26 Apr 2011 22:57:20 +0000 (22:57 +0000)
Verify that applying a world transformation to wxDC really does result in the
expected transformation.

See #13092.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67617 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/Makefile.in
tests/graphics/affinematrix.cpp [new file with mode: 0644]
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/test.bkl
tests/test_test_gui.dsp
tests/test_vc7_test_gui.vcproj
tests/test_vc8_test_gui.vcproj
tests/test_vc9_test_gui.vcproj

index 1df92ac2d3974b909ad59751e24cdd993e6882cc..a267e6d5b17b2f449c91a6dfbea1c49db5955131 100644 (file)
@@ -155,6 +155,7 @@ TEST_GUI_OBJECTS =  \
        test_gui_colour.o \
        test_gui_ellipsization.o \
        test_gui_measuring.o \
+       test_gui_affinematrix.o \
        test_gui_config.o \
        test_gui_bitmapcomboboxtest.o \
        test_gui_bitmaptogglebuttontest.o \
@@ -696,6 +697,9 @@ test_gui_ellipsization.o: $(srcdir)/graphics/ellipsization.cpp $(TEST_GUI_ODEP)
 test_gui_measuring.o: $(srcdir)/graphics/measuring.cpp $(TEST_GUI_ODEP)
        $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/measuring.cpp
 
+test_gui_affinematrix.o: $(srcdir)/graphics/affinematrix.cpp $(TEST_GUI_ODEP)
+       $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/graphics/affinematrix.cpp
+
 test_gui_config.o: $(srcdir)/config/config.cpp $(TEST_GUI_ODEP)
        $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/config/config.cpp
 
diff --git a/tests/graphics/affinematrix.cpp b/tests/graphics/affinematrix.cpp
new file mode 100644 (file)
index 0000000..ffa4f58
--- /dev/null
@@ -0,0 +1,140 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/graphics/affinetransform.cpp
+// Purpose:     Unit test for transformations implemented for wxAffineMatrix2D
+// Author:      Catalin Raceanu
+// Created:     2011-04-14
+// Copyright:   (c) 2011 wxWidgets development team
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "testprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#include "wx/dcmemory.h"
+#include "wx/affinematrix2d.h"
+#include "wx/math.h"
+
+#include "testimage.h"
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class AffineTransformTestCase : public CppUnit::TestCase
+{
+public:
+    AffineTransformTestCase()
+    {
+        wxImage::AddHandler(new wxJPEGHandler);
+    }
+
+    virtual void setUp();
+
+private:
+    CPPUNIT_TEST_SUITE( AffineTransformTestCase );
+        CPPUNIT_TEST( InvertMatrix );
+        CPPUNIT_TEST( VMirrorAndTranslate );
+        CPPUNIT_TEST( Rotate90Clockwise );
+    CPPUNIT_TEST_SUITE_END();
+
+    void InvertMatrix();
+    void VMirrorAndTranslate();
+    void Rotate90Clockwise();
+
+    wxImage m_imgOrig;
+    wxBitmap m_bmpOrig;
+
+    DECLARE_NO_COPY_CLASS(AffineTransformTestCase)
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( AffineTransformTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( AffineTransformTestCase, "AffineTransformTestCase" );
+
+void AffineTransformTestCase::setUp()
+{
+    m_imgOrig.LoadFile("horse.jpg");
+
+    CPPUNIT_ASSERT( m_imgOrig.IsOk() );
+
+    m_bmpOrig = wxBitmap(m_imgOrig);
+}
+
+void AffineTransformTestCase::InvertMatrix()
+{
+    wxAffineMatrix2D matrix1;
+    matrix1.Set(wxMatrix2D(2, 1, 1, 1), wxPoint2DDouble(1, 1));
+
+    wxAffineMatrix2D matrix2(matrix1);
+
+    matrix2.Invert();
+
+    wxMatrix2D m;
+    wxPoint2DDouble p;
+    matrix2.Get(&m, &p);
+    CPPUNIT_ASSERT_EQUAL( 1, (int)m.m_11 );
+    CPPUNIT_ASSERT_EQUAL( -1, (int)m.m_12 );
+    CPPUNIT_ASSERT_EQUAL( -1, (int)m.m_21 );
+    CPPUNIT_ASSERT_EQUAL( 2, (int)m.m_22 );
+    CPPUNIT_ASSERT_EQUAL( 0, (int)p.m_x );
+    CPPUNIT_ASSERT_EQUAL( -1, (int)p.m_y );
+
+    matrix2.Concat(matrix1);
+    CPPUNIT_ASSERT( matrix2.IsIdentity() );
+}
+
+void AffineTransformTestCase::VMirrorAndTranslate()
+{
+    wxBitmap bmpUsingMatrix(m_bmpOrig.GetWidth(), m_bmpOrig.GetHeight());
+
+    // build the mirrored image using the transformation matrix
+    {
+        wxMemoryDC dc(bmpUsingMatrix);
+
+        if ( !dc.CanUseTransformMatrix() )
+            return;
+
+        wxAffineMatrix2D matrix;
+        matrix.Mirror(wxVERTICAL);
+        matrix.Translate(0, m_bmpOrig.GetHeight() - 1);
+        dc.SetTransformMatrix(matrix);
+        dc.DrawBitmap(m_bmpOrig, 0, 0);
+    }
+
+    wxImage imgUsingMatrix = bmpUsingMatrix.ConvertToImage();
+    wxImage imgOrigVMirrored = m_imgOrig.Mirror(false);
+
+    CPPUNIT_ASSERT_EQUAL( imgUsingMatrix, imgOrigVMirrored );
+}
+
+void AffineTransformTestCase::Rotate90Clockwise()
+{
+    wxBitmap bmpUsingMatrix(m_bmpOrig.GetHeight(), m_bmpOrig.GetWidth());
+
+    // build the rotated image using the transformation matrix
+    {
+        wxMemoryDC dc(bmpUsingMatrix);
+
+        if ( !dc.CanUseTransformMatrix() )
+            return;
+
+        wxAffineMatrix2D matrix;
+        matrix.Rotate(-0.5 * M_PI);
+        matrix.Translate(m_bmpOrig.GetHeight(), 0);
+        dc.SetTransformMatrix(matrix);
+        dc.DrawBitmap(m_bmpOrig, 0, 0);
+    }
+
+    wxImage imgUsingMatrix = bmpUsingMatrix.ConvertToImage();
+    wxImage imgOrigRotate90Clockwise = m_imgOrig.Rotate90(true);
+
+    CPPUNIT_ASSERT_EQUAL( imgUsingMatrix, imgOrigRotate90Clockwise );
+}
index 2f07c1b1cdbdb4b0c39b4f1bc11df999e41c3f2d..379b9f53151e2851251bc66b07c34e9fb65e8e40 100644 (file)
@@ -140,6 +140,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_colour.obj \\r
        $(OBJS)\test_gui_ellipsization.obj \\r
        $(OBJS)\test_gui_measuring.obj \\r
+       $(OBJS)\test_gui_affinematrix.obj \
        $(OBJS)\test_gui_config.obj \\r
        $(OBJS)\test_gui_bitmapcomboboxtest.obj \\r
        $(OBJS)\test_gui_bitmaptogglebuttontest.obj \\r
@@ -744,6 +745,9 @@ $(OBJS)\test_gui_ellipsization.obj: .\graphics\ellipsization.cpp
 $(OBJS)\test_gui_measuring.obj: .\graphics\measuring.cpp\r
        $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\graphics\measuring.cpp\r
 \r
+$(OBJS)\test_gui_affinematrix.obj: .\graphics\affinematrix.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\graphics\affinematrix.cpp
+
 $(OBJS)\test_gui_config.obj: .\config\config.cpp\r
        $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\config\config.cpp\r
 \r
index d8559c080b706b3924c98d7ebd50b9e643fad2f4..618098b690ffb03c446e86a58ea835deb275e412 100644 (file)
@@ -133,6 +133,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_colour.o \\r
        $(OBJS)\test_gui_ellipsization.o \\r
        $(OBJS)\test_gui_measuring.o \\r
+       $(OBJS)\test_gui_affinematrix.o \
        $(OBJS)\test_gui_config.o \\r
        $(OBJS)\test_gui_bitmapcomboboxtest.o \\r
        $(OBJS)\test_gui_bitmaptogglebuttontest.o \\r
@@ -725,6 +726,9 @@ $(OBJS)\test_gui_ellipsization.o: ./graphics/ellipsization.cpp
 $(OBJS)\test_gui_measuring.o: ./graphics/measuring.cpp\r
        $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<\r
 \r
+$(OBJS)\test_gui_affinematrix.o: ./graphics/affinematrix.cpp
+       $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
+
 $(OBJS)\test_gui_config.o: ./config/config.cpp\r
        $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<\r
 \r
index 7d33b327e63bc143746c05411f9f860c7b63a8df..4edaa5a8160be41ca952fa5226dd941d8bfbb0ec 100644 (file)
@@ -135,6 +135,7 @@ TEST_GUI_OBJECTS =  \
        $(OBJS)\test_gui_colour.obj \\r
        $(OBJS)\test_gui_ellipsization.obj \\r
        $(OBJS)\test_gui_measuring.obj \\r
+       $(OBJS)\test_gui_affinematrix.obj \
        $(OBJS)\test_gui_config.obj \\r
        $(OBJS)\test_gui_bitmapcomboboxtest.obj \\r
        $(OBJS)\test_gui_bitmaptogglebuttontest.obj \\r
@@ -870,6 +871,9 @@ $(OBJS)\test_gui_ellipsization.obj: .\graphics\ellipsization.cpp
 $(OBJS)\test_gui_measuring.obj: .\graphics\measuring.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\measuring.cpp\r
 \r
+$(OBJS)\test_gui_affinematrix.obj: .\graphics\affinematrix.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\graphics\affinematrix.cpp
+
 $(OBJS)\test_gui_config.obj: .\config\config.cpp\r
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\config\config.cpp\r
 \r
index 7c563fdaae3d5842d77e3b9381b8d8d41f832e90..0ae1d53914a3b71846ef84dcd6c48e56d73c1113 100644 (file)
@@ -379,6 +379,7 @@ TEST_GUI_OBJECTS =  &
        $(OBJS)\test_gui_colour.obj &\r
        $(OBJS)\test_gui_ellipsization.obj &\r
        $(OBJS)\test_gui_measuring.obj &\r
+       $(OBJS)\test_gui_affinematrix.obj &
        $(OBJS)\test_gui_config.obj &\r
        $(OBJS)\test_gui_bitmapcomboboxtest.obj &\r
        $(OBJS)\test_gui_bitmaptogglebuttontest.obj &\r
@@ -784,6 +785,9 @@ $(OBJS)\test_gui_ellipsization.obj :  .AUTODEPEND .\graphics\ellipsization.cpp
 $(OBJS)\test_gui_measuring.obj :  .AUTODEPEND .\graphics\measuring.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<\r
 \r
+$(OBJS)\test_gui_affinematrix.obj :  .AUTODEPEND .\graphics\affinematrix.cpp
+       $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
+
 $(OBJS)\test_gui_config.obj :  .AUTODEPEND .\config\config.cpp\r
        $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<\r
 \r
index 2f5d0aa81bfe6da31e1099a633350bd5f1ffbd15..404e15b80a25e97e9cd4e2003d2f0131b23e6fa2 100644 (file)
             graphics/colour.cpp
             graphics/ellipsization.cpp
             graphics/measuring.cpp
+            graphics/affinematrix.cpp
             config/config.cpp
             controls/bitmapcomboboxtest.cpp
             controls/bitmaptogglebuttontest.cpp
index 89461de8e366c8a3b1e4e190fe2d92484548997a..f412c8d6a836f10b24c49d5d5520e5c2a69f70dc 100644 (file)
@@ -239,6 +239,10 @@ SOURCE=.\menu\accelentry.cpp
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\graphics\affinematrix.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\asserthelper.cpp\r
 # End Source File\r
 # Begin Source File\r
index 8694367444289b5c0bb1099c8f5f40bf5a5611c2..77ba87227003d2d5c070b05a5234428af4d26f13 100644 (file)
                                RelativePath=".\menu\accelentry.cpp">\r
                        </File>\r
                        <File\r
+                               RelativePath=".\graphics\affinematrix.cpp">
+                       </File>
+                       <File
                                RelativePath=".\asserthelper.cpp">\r
                        </File>\r
                        <File\r
index 19d026ee2e356205f0b75aed4fda5135616f8dce..3bc2ce80f3b1fc78c8f4a3b04ebf6d3ccc055c49 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath=".\graphics\affinematrix.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\asserthelper.cpp"\r
                                >\r
                        </File>\r
index a6b4a266a35375b19cd92732726ea254cb26cb69..d312302f26f7ef0b3a6d110f961ea07852019bb1 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath=".\graphics\affinematrix.cpp"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\asserthelper.cpp"\r
                                >\r
                        </File>\r