From: pjrm Date: Mon, 13 Mar 2006 05:38:33 +0000 (+0000) Subject: svg-color-test.h: New unit test file. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8c6c581aacfd89518bfb0c0ab7054183972ef997;p=inkscape.git svg-color-test.h: New unit test file. --- diff --git a/src/svg/Makefile_insert b/src/svg/Makefile_insert index c3219d705..ee3ee2518 100644 --- a/src/svg/Makefile_insert +++ b/src/svg/Makefile_insert @@ -43,7 +43,8 @@ svg/test-svg.cpp: $(svg_test_svg_includes) svg/Makefile_insert svg_test_svg_includes = \ $(srcdir)/svg/css-ostringstream-test.h \ - $(srcdir)/svg/stringstream-test.h + $(srcdir)/svg/stringstream-test.h \ + $(srcdir)/svg/svg-color-test.h svg_libtest_svg_a_SOURCES = \ svg/test-svg.cpp \ @@ -56,4 +57,5 @@ svg_test_svg_SOURCES = \ svg_test_svg_LDADD = \ svg/libspsvg.a \ svg/libtest-svg.a \ + libinkpost.a \ -lglib-2.0 diff --git a/src/svg/svg-color-test.h b/src/svg/svg-color-test.h new file mode 100644 index 000000000..4d9b2e854 --- /dev/null +++ b/src/svg/svg-color-test.h @@ -0,0 +1,55 @@ +#include +#include "svg/svg-color.h" + +static void +test_rgb24(unsigned const rgb24) +{ + char css[8]; + sp_svg_write_color(css, sizeof(css), rgb24 << 8); + TS_ASSERT_EQUALS(sp_svg_read_color(css, 0xff), + rgb24 << 8); +} + +static void +test_sp_svg_write_color() +{ + unsigned const components[] = {0, 0x80, 0xff, 0xc0, 0x77}; + unsigned const nc = G_N_ELEMENTS(components); + for (unsigned i = nc*nc*nc; i--;) { + unsigned tmp = i; + unsigned rgb24 = 0; + for (unsigned c = 0; c < 3; ++c) { + unsigned const component = components[tmp % nc]; + rgb24 = (rgb24 << 8) | component; + tmp /= nc; + } + assert(tmp == 0); + test_rgb24(rgb24); + } + + /* And a few completely random ones. */ + for (unsigned i = 500; i--;) { /* Arbitrary number of iterations. */ + unsigned const rgb24 = (rand() >> 4) & 0xffffff; + test_rgb24(rgb24); + } +} + +class SVGColorTest : public CxxTest::TestSuite +{ +public: + void testWrite() + { + test_sp_svg_write_color(); + } +}; + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :