X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fsvg%2Fsvg-color-test.h;h=d249c675c9bfeeb8a3db60ed97a0a2100d8e1192;hb=429ce09996dfe0ef44a115a89465c69eb4d376a6;hp=ad25d506c36fbcaa2714f81892838c19016d2a12;hpb=6eda248c0338b5c257b7b940c4cc3cfc1a294892;p=inkscape.git diff --git a/src/svg/svg-color-test.h b/src/svg/svg-color-test.h index ad25d506c..d249c675c 100644 --- a/src/svg/svg-color-test.h +++ b/src/svg/svg-color-test.h @@ -1,7 +1,8 @@ - #include #include +#include +#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