Code

Corrected initialization order.
[inkscape.git] / src / svg / svg-color-test.h
index ad25d506c36fbcaa2714f81892838c19016d2a12..d249c675c9bfeeb8a3db60ed97a0a2100d8e1192 100644 (file)
@@ -1,7 +1,8 @@
-
 #include <cxxtest/TestSuite.h>
 #include <cassert>
+#include <cstdlib>
 
+#include "preferences.h"
 #include "svg/svg-color.h"
 #include "svg/svg-icc-color.h"
 
@@ -17,12 +18,23 @@ class SVGColorTest : public CxxTest::TestSuite
 public:
     void check_rgb24(unsigned const rgb24)
     {
+        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
         char css[8];
+        prefs->setBool("/options/svgoutput/usenamedcolors", false);
+        sp_svg_write_color(css, sizeof(css), rgb24 << 8);
+        TS_ASSERT_EQUALS(sp_svg_read_color(css, 0xff),
+                         rgb24 << 8);
+        prefs->setBool("/options/svgoutput/usenamedcolors", true);
         sp_svg_write_color(css, sizeof(css), rgb24 << 8);
         TS_ASSERT_EQUALS(sp_svg_read_color(css, 0xff),
                          rgb24 << 8);
     }
 
+// createSuite and destroySuite get us per-suite setup and teardown
+// without us having to worry about static initialization order, etc.
+    static SVGColorTest *createSuite() { return new SVGColorTest(); }
+    static void destroySuite( SVGColorTest *suite ) { delete suite; }
+
     void testWrite()
     {
         unsigned const components[] = {0, 0x80, 0xff, 0xc0, 0x77};
@@ -40,6 +52,7 @@ public:
         }
 
         /* And a few completely random ones. */
+        using std::rand;
         for (unsigned i = 500; i--;) {  /* Arbitrary number of iterations. */
             unsigned const rgb24 = (rand() >> 4) & 0xffffff;
             check_rgb24(rgb24);
@@ -48,11 +61,14 @@ public:
 
     void testReadColor()
     {
-        gchar const* val="#f0f";
-        gchar const* end = 0;
-        guint32 result = sp_svg_read_color( val, &end, 0x3 );
-        TS_ASSERT_EQUALS( result, 0xff00ff00 );
-        TS_ASSERT_LESS_THAN( val, end );
+        gchar const* val[] = {"#f0f", "#ff00ff", "rgb(255,0,255)", "fuchsia"};
+        size_t const n = sizeof(val)/sizeof(*val);
+        for(size_t i=0; i<n; i++) {
+            gchar const* end = 0;
+            guint32 result = sp_svg_read_color( val[i], &end, 0x3 );
+            TS_ASSERT_EQUALS( result, 0xff00ff00 );
+            TS_ASSERT_LESS_THAN( val[i], end );
+        }
     }
 
     void testIccColor()