// SPDX-License-Identifier: GPL-2.0-or-later /** @file * TODO: insert short description here *//* * Authors: see git history * * Copyright (C) 2010 Authors * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ #include #include #include #include "preferences.h" #include "svg/svg-color.h" #include "svg/svg-icc-color.h" class SVGColorTest : public CxxTest::TestSuite { struct simpleIccCase { unsigned numEntries; bool shouldPass; char const* name; char const* str; }; 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}; 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 ); check_rgb24(rgb24); } /* And a few completely random ones. */ for (unsigned i = 500; i--;) { /* Arbitrary number of iterations. */ unsigned const rgb24 = (std::rand() >> 4) & 0xffffff; check_rgb24(rgb24); } } void testReadColor() { gchar const* val[] = {"#f0f", "#ff00ff", "rgb(255,0,255)", "fuchsia"}; size_t const n = sizeof(val)/sizeof(*val); for(size_t i=0; i