Code

svg-color-test.h: New unit test file.
[inkscape.git] / src / svg / svg-color-test.h
1 #include <cxxtest/TestSuite.h>
2 #include "svg/svg-color.h"
4 static void
5 test_rgb24(unsigned const rgb24)
6 {
7     char css[8];
8     sp_svg_write_color(css, sizeof(css), rgb24 << 8);
9     TS_ASSERT_EQUALS(sp_svg_read_color(css, 0xff),
10                      rgb24 << 8);
11 }
13 static void
14 test_sp_svg_write_color()
15 {
16     unsigned const components[] = {0, 0x80, 0xff, 0xc0, 0x77};
17     unsigned const nc = G_N_ELEMENTS(components);
18     for (unsigned i = nc*nc*nc; i--;) {
19         unsigned tmp = i;
20         unsigned rgb24 = 0;
21         for (unsigned c = 0; c < 3; ++c) {
22             unsigned const component = components[tmp % nc];
23             rgb24 = (rgb24 << 8) | component;
24             tmp /= nc;
25         }
26         assert(tmp == 0);
27         test_rgb24(rgb24);
28     }
30     /* And a few completely random ones. */
31     for (unsigned i = 500; i--;) {  /* Arbitrary number of iterations. */
32         unsigned const rgb24 = (rand() >> 4) & 0xffffff;
33         test_rgb24(rgb24);
34     }
35 }
37 class SVGColorTest : public CxxTest::TestSuite
38 {
39 public:
40     void testWrite()
41     {
42         test_sp_svg_write_color();
43     }
44 };
46 /*
47   Local Variables:
48   mode:c++
49   c-file-style:"stroustrup"
50   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
51   indent-tabs-mode:nil
52   fill-column:99
53   End:
54 */
55 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :