Code

Fix version check for wheel selector.
[inkscape.git] / src / svg / svg-affine-test.h
index 0284402edcd6dba0c5a7ac0b5785468a920b6995..be5a941bb2a40fa54bf52e407763573c70829afd 100644 (file)
@@ -1,6 +1,7 @@
 #include <cxxtest/TestSuite.h>
 
 #include "svg/svg.h"
+#include "streq.h"
 #include <2geom/matrix.h>
 #include <algorithm>
 #include <glib.h>
@@ -8,26 +9,6 @@
 #include <math.h>
 #include <utility>
 
-struct streq_free2 {
-    bool operator()(char const *exp, char const *got) const
-    {
-        bool const ret = (strcmp(exp, got) == 0);
-        g_free((void*)got);
-        return ret;
-    }
-};
-
-struct approx_equal {
-    bool operator()(Geom::Matrix const &ref, Geom::Matrix const &cm) const
-    {
-        double maxabsdiff = 0;
-        for(size_t i=0; i<6; i++) {
-            maxabsdiff = std::max(std::abs(ref[i]-cm[i]), maxabsdiff);
-        }
-        return maxabsdiff < 1e-14;
-    }
-};
-
 class SvgAffineTest : public CxxTest::TestSuite
 {
 private:
@@ -35,12 +16,22 @@ private:
         char const * str;
         Geom::Matrix matrix;
     };
+    struct approx_equal_pred {
+        bool operator()(Geom::Matrix const &ref, Geom::Matrix const &cm) const
+        {
+            double maxabsdiff = 0;
+            for(size_t i=0; i<6; i++) {
+                maxabsdiff = std::max(std::abs(ref[i]-cm[i]), maxabsdiff);
+            }
+            return maxabsdiff < 1e-14;
+        }
+    };
     static test_t const read_matrix_tests[3];
     static test_t const read_translate_tests[3];
     static test_t const read_scale_tests[3];
     static test_t const read_rotate_tests[4];
     static test_t const read_skew_tests[3];
-    static char const * read_fail_tests[25];
+    static char const * const read_fail_tests[25];
     static test_t const write_matrix_tests[2];
     static test_t const write_translate_tests[3];
     static test_t const write_scale_tests[2];
@@ -50,6 +41,11 @@ public:
     SvgAffineTest() {
     }
 
+// createSuite and destroySuite get us per-suite setup and teardown
+// without us having to worry about static initialization order, etc.
+    static SvgAffineTest *createSuite() { return new SvgAffineTest(); }
+    static void destroySuite( SvgAffineTest *suite ) { delete suite; }
+
     void testReadIdentity()
     {
         char const* strs[] = {
@@ -79,7 +75,7 @@ public:
         for(size_t i=0; i<G_N_ELEMENTS(read_matrix_tests); i++) {
             Geom::Matrix cm;
             TSM_ASSERT(read_matrix_tests[i].str , sp_svg_transform_read(read_matrix_tests[i].str, &cm));
-            TSM_ASSERT_RELATION(read_matrix_tests[i].str , approx_equal , read_matrix_tests[i].matrix , cm);
+            TSM_ASSERT_RELATION(read_matrix_tests[i].str , approx_equal_pred , read_matrix_tests[i].matrix , cm);
         }
     }
 
@@ -88,7 +84,7 @@ public:
         for(size_t i=0; i<G_N_ELEMENTS(read_translate_tests); i++) {
             Geom::Matrix cm;
             TSM_ASSERT(read_translate_tests[i].str , sp_svg_transform_read(read_translate_tests[i].str, &cm));
-            TSM_ASSERT_RELATION(read_translate_tests[i].str , approx_equal , read_translate_tests[i].matrix , cm);
+            TSM_ASSERT_RELATION(read_translate_tests[i].str , approx_equal_pred , read_translate_tests[i].matrix , cm);
         }
     }
 
@@ -97,7 +93,7 @@ public:
         for(size_t i=0; i<G_N_ELEMENTS(read_scale_tests); i++) {
             Geom::Matrix cm;
             TSM_ASSERT(read_scale_tests[i].str , sp_svg_transform_read(read_scale_tests[i].str, &cm));
-            TSM_ASSERT_RELATION(read_scale_tests[i].str , approx_equal , read_scale_tests[i].matrix , cm);
+            TSM_ASSERT_RELATION(read_scale_tests[i].str , approx_equal_pred , read_scale_tests[i].matrix , cm);
         }
     }
 
@@ -106,7 +102,7 @@ public:
         for(size_t i=0; i<G_N_ELEMENTS(read_rotate_tests); i++) {
             Geom::Matrix cm;
             TSM_ASSERT(read_rotate_tests[i].str , sp_svg_transform_read(read_rotate_tests[i].str, &cm));
-            TSM_ASSERT_RELATION(read_rotate_tests[i].str , approx_equal , read_rotate_tests[i].matrix , cm);
+            TSM_ASSERT_RELATION(read_rotate_tests[i].str , approx_equal_pred , read_rotate_tests[i].matrix , cm);
         }
     }
 
@@ -115,42 +111,52 @@ public:
         for(size_t i=0; i<G_N_ELEMENTS(read_skew_tests); i++) {
             Geom::Matrix cm;
             TSM_ASSERT(read_skew_tests[i].str , sp_svg_transform_read(read_skew_tests[i].str, &cm));
-            TSM_ASSERT_RELATION(read_skew_tests[i].str , approx_equal , read_skew_tests[i].matrix , cm);
+            TSM_ASSERT_RELATION(read_skew_tests[i].str , approx_equal_pred , read_skew_tests[i].matrix , cm);
         }
     }
 
     void testWriteMatrix()
     {
         for(size_t i=0; i<G_N_ELEMENTS(write_matrix_tests); i++) {
-            TS_ASSERT_RELATION(streq_free2 , sp_svg_transform_write(write_matrix_tests[i].matrix) , write_matrix_tests[i].str);
+            char * str = sp_svg_transform_write(write_matrix_tests[i].matrix);
+            TS_ASSERT_RELATION(streq_rel , str , write_matrix_tests[i].str);
+            g_free(str);
         }
     }
 
     void testWriteTranslate()
     {
         for(size_t i=0; i<G_N_ELEMENTS(write_translate_tests); i++) {
-            TS_ASSERT_RELATION(streq_free2 , sp_svg_transform_write(write_translate_tests[i].matrix) , write_translate_tests[i].str);
+            char * str = sp_svg_transform_write(write_translate_tests[i].matrix);
+            TS_ASSERT_RELATION(streq_rel , str , write_translate_tests[i].str);
+            g_free(str);
         }
     }
 
     void testWriteScale()
     {
         for(size_t i=0; i<G_N_ELEMENTS(write_scale_tests); i++) {
-            TS_ASSERT_RELATION(streq_free2 , sp_svg_transform_write(write_scale_tests[i].matrix) , write_scale_tests[i].str);
+            char * str = sp_svg_transform_write(write_scale_tests[i].matrix);
+            TS_ASSERT_RELATION(streq_rel , str , write_scale_tests[i].str);
+            g_free(str);
         }
     }
 
     void testWriteRotate()
     {
         for(size_t i=0; i<G_N_ELEMENTS(write_rotate_tests); i++) {
-            TS_ASSERT_RELATION(streq_free2 , sp_svg_transform_write(write_rotate_tests[i].matrix) , write_rotate_tests[i].str);
+            char * str = sp_svg_transform_write(write_rotate_tests[i].matrix);
+            TS_ASSERT_RELATION(streq_rel , str , write_rotate_tests[i].str);
+            g_free(str);
         }
     }
 
     void testWriteSkew()
     {
         for(size_t i=0; i<G_N_ELEMENTS(write_skew_tests); i++) {
-            TS_ASSERT_RELATION(streq_free2 , sp_svg_transform_write(write_skew_tests[i].matrix) , write_skew_tests[i].str);
+            char * str = sp_svg_transform_write(write_skew_tests[i].matrix);
+            TS_ASSERT_RELATION(streq_rel , str , write_skew_tests[i].str);
+            g_free(str);
         }
     }
 
@@ -163,7 +169,7 @@ public:
         Geom::Matrix ref(2.0199976232558053, 1.0674773585906016, -0.14125199392774669, 1.9055550612095459, 14.412730624347654, 28.499820929377454); // Precomputed using Mathematica
         Geom::Matrix cm;
         TS_ASSERT(sp_svg_transform_read(str, &cm));
-        TS_ASSERT_RELATION(approx_equal , ref , cm);
+        TS_ASSERT_RELATION(approx_equal_pred , ref , cm);
     }
 
     void testReadFailures()
@@ -198,7 +204,7 @@ SvgAffineTest::test_t const SvgAffineTest::read_skew_tests[3] = {
     {"skewX( 30)",Geom::Matrix(1,0,tan(30.*DEGREE),1,0,0)},
     {"skewX(-30)",Geom::Matrix(1,0,tan(-30.*DEGREE),1,0,0)},
     {"skewY(390)",Geom::Matrix(1,tan(30.*DEGREE),0,1,0,0)}};
-char const * SvgAffineTest::read_fail_tests[25] = {
+char const * const SvgAffineTest::read_fail_tests[25] = {
     "matrix((1,2,3,4,5,6)",
     "matrix((1,2,3,4,5,6))",
     "matrix(1,2,3,4,5,6))",
@@ -252,4 +258,4 @@ SvgAffineTest::test_t const SvgAffineTest::write_skew_tests[3] = {
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :