1
#include <cxxtest/TestSuite.h>
5
#include "preferences.h"
6
#include "svg/svg-color.h"
7
#include "svg/svg-icc-color.h"
9
class SVGColorTest : public CxxTest::TestSuite
11
struct simpleIccCase {
19
void check_rgb24(unsigned const rgb24)
21
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
23
prefs->setBool("/options/svgoutput/usenamedcolors", false);
24
sp_svg_write_color(css, sizeof(css), rgb24 << 8);
25
TS_ASSERT_EQUALS(sp_svg_read_color(css, 0xff),
27
prefs->setBool("/options/svgoutput/usenamedcolors", true);
28
sp_svg_write_color(css, sizeof(css), rgb24 << 8);
29
TS_ASSERT_EQUALS(sp_svg_read_color(css, 0xff),
33
// createSuite and destroySuite get us per-suite setup and teardown
34
// without us having to worry about static initialization order, etc.
35
static SVGColorTest *createSuite() { return new SVGColorTest(); }
36
static void destroySuite( SVGColorTest *suite ) { delete suite; }
40
unsigned const components[] = {0, 0x80, 0xff, 0xc0, 0x77};
41
unsigned const nc = G_N_ELEMENTS(components);
42
for (unsigned i = nc*nc*nc; i--;) {
45
for (unsigned c = 0; c < 3; ++c) {
46
unsigned const component = components[tmp % nc];
47
rgb24 = (rgb24 << 8) | component;
54
/* And a few completely random ones. */
55
for (unsigned i = 500; i--;) { /* Arbitrary number of iterations. */
56
unsigned const rgb24 = (std::rand() >> 4) & 0xffffff;
63
gchar const* val[] = {"#f0f", "#ff00ff", "rgb(255,0,255)", "fuchsia"};
64
size_t const n = sizeof(val)/sizeof(*val);
65
for(size_t i=0; i<n; i++) {
67
guint32 result = sp_svg_read_color( val[i], &end, 0x3 );
68
TS_ASSERT_EQUALS( result, 0xff00ff00 );
69
TS_ASSERT_LESS_THAN( val[i], end );
75
simpleIccCase cases[] = {
76
{1, true, "named", "icc-color(named, 3)"},
77
{0, false, "", "foodle"},
78
{1, true, "a", "icc-color(a, 3)"},
79
{4, true, "named", "icc-color(named, 3, 0, 0.1, 2.5)"},
80
{0, false, "", "icc-color(named, 3"},
81
{0, false, "", "icc-color(space named, 3)"},
82
{0, false, "", "icc-color(tab\tnamed, 3)"},
83
{0, false, "", "icc-color(0name, 3)"},
84
{0, false, "", "icc-color(-name, 3)"},
85
{1, true, "positive", "icc-color(positive, +3)"},
86
{1, true, "negative", "icc-color(negative, -3)"},
87
{1, true, "positive", "icc-color(positive, +0.1)"},
88
{1, true, "negative", "icc-color(negative, -0.1)"},
89
{0, false, "", "icc-color(named, value)"},
92
for ( size_t i = 0; i < G_N_ELEMENTS(cases); i++ ) {
94
gchar const* str = cases[i].str;
95
gchar const* result = 0;
97
std::string testDescr( cases[i].str );
99
bool parseRet = sp_svg_read_icc_color( str, &result, &tmp );
100
TSM_ASSERT_EQUALS( testDescr, parseRet, cases[i].shouldPass );
101
TSM_ASSERT_EQUALS( testDescr, tmp.colors.size(), cases[i].numEntries );
102
if ( cases[i].shouldPass ) {
103
TSM_ASSERT_DIFFERS( testDescr, str, result );
104
TSM_ASSERT_EQUALS( testDescr, tmp.colorProfile, std::string(cases[i].name) );
106
TSM_ASSERT_EQUALS( testDescr, str, result );
107
TSM_ASSERT( testDescr, tmp.colorProfile.empty() );
117
c-file-style:"stroustrup"
118
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
123
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :