diff options
| author | Peter Moulder <peter.moulder@monash.edu> | 2006-03-13 05:38:33 +0000 |
|---|---|---|
| committer | pjrm <pjrm@users.sourceforge.net> | 2006-03-13 05:38:33 +0000 |
| commit | d315cd25a56c4ab0f6bd1a3ae5ddef708c1b10f1 (patch) | |
| tree | 5f655f428b126995324f399a3c3440fb2c6dca1d /src | |
| parent | Set svn:eol-style to native on all *.cpp *.h files (i.e. on the few .cpp/.h f... (diff) | |
| download | inkscape-d315cd25a56c4ab0f6bd1a3ae5ddef708c1b10f1.tar.gz inkscape-d315cd25a56c4ab0f6bd1a3ae5ddef708c1b10f1.zip | |
svg-color-test.h: New unit test file.
(bzr r235)
Diffstat (limited to 'src')
| -rw-r--r-- | src/svg/Makefile_insert | 4 | ||||
| -rw-r--r-- | src/svg/svg-color-test.h | 55 |
2 files changed, 58 insertions, 1 deletions
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 <cxxtest/TestSuite.h> +#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 : |
