style-test.cpp revision 6b15695578f07a3f72c4c9475c1a261a3021472a
#include <cassert>
#include <cmath>
#include "streq.h"
#include "strneq.h"
#include "style.h"
/// Dummy functions to keep linker happy
int sp_main_gui (int, char const**) { return 0; }
int sp_main_console (int, char const**) { return 0; }
/* Extracted mechanically from http://www.w3.org/TR/SVG11/types.html#ColorKeywords:
*
* tidy -wrap 999 < types.html 2> /dev/null |
* egrep '(prop|color-keyword)-value' |
* sed 's,<td><span class="prop-value">, {",;s/<td><span class="color-keyword-value">rgb(/", {/;s%).*%}},@%;s%</span></td>%%' |
* tr -d \\n |
* tr @ \\n
*/
static struct {
char const *color_keyword;
struct {unsigned r; unsigned g; unsigned b; } rgb;
} const color_keywords[] = {
{"aliceblue", {240, 248, 255}},
{"antiquewhite", {250, 235, 215}},
{"aqua", { 0, 255, 255}},
{"aquamarine", {127, 255, 212}},
{"azure", {240, 255, 255}},
{"beige", {245, 245, 220}},
{"bisque", {255, 228, 196}},
{"black", { 0, 0, 0}},
{"blanchedalmond", {255, 235, 205}},
{"blue", { 0, 0, 255}},
{"blueviolet", {138, 43, 226}},
{"brown", {165, 42, 42}},
{"burlywood", {222, 184, 135}},
{"cadetblue", { 95, 158, 160}},
{"chartreuse", {127, 255, 0}},
{"chocolate", {210, 105, 30}},
{"coral", {255, 127, 80}},
{"cornflowerblue", {100, 149, 237}},
{"cornsilk", {255, 248, 220}},
{"crimson", {220, 20, 60}},
{"cyan", { 0, 255, 255}},
{"darkblue", { 0, 0, 139}},
{"darkcyan", { 0, 139, 139}},
{"darkgoldenrod", {184, 134, 11}},
{"darkgray", {169, 169, 169}},
{"darkgreen", { 0, 100, 0}},
{"darkgrey", {169, 169, 169}},
{"darkkhaki", {189, 183, 107}},
{"darkmagenta", {139, 0, 139}},
{"darkolivegreen", { 85, 107, 47}},
{"darkorange", {255, 140, 0}},
{"darkorchid", {153, 50, 204}},
{"darkred", {139, 0, 0}},
{"darksalmon", {233, 150, 122}},
{"darkseagreen", {143, 188, 143}},
{"darkslateblue", { 72, 61, 139}},
{"darkslategray", { 47, 79, 79}},
{"darkslategrey", { 47, 79, 79}},
{"darkturquoise", { 0, 206, 209}},
{"darkviolet", {148, 0, 211}},
{"deeppink", {255, 20, 147}},
{"deepskyblue", { 0, 191, 255}},
{"dimgray", {105, 105, 105}},
{"dimgrey", {105, 105, 105}},
{"dodgerblue", { 30, 144, 255}},
{"firebrick", {178, 34, 34}},
{"floralwhite", {255, 250, 240}},
{"forestgreen", { 34, 139, 34}},
{"fuchsia", {255, 0, 255}},
{"gainsboro", {220, 220, 220}},
{"ghostwhite", {248, 248, 255}},
{"gold", {255, 215, 0}},
{"goldenrod", {218, 165, 32}},
{"gray", {128, 128, 128}},
{"grey", {128, 128, 128}},
{"green", { 0, 128, 0}},
{"greenyellow", {173, 255, 47}},
{"honeydew", {240, 255, 240}},
{"hotpink", {255, 105, 180}},
{"indianred", {205, 92, 92}},
{"indigo", { 75, 0, 130}},
{"ivory", {255, 255, 240}},
{"khaki", {240, 230, 140}},
{"lavender", {230, 230, 250}},
{"lavenderblush", {255, 240, 245}},
{"lawngreen", {124, 252, 0}},
{"lemonchiffon", {255, 250, 205}},
{"lightblue", {173, 216, 230}},
{"lightcoral", {240, 128, 128}},
{"lightcyan", {224, 255, 255}},
{"lightgoldenrodyellow", {250, 250, 210}},
{"lightgray", {211, 211, 211}},
{"lightgreen", {144, 238, 144}},
{"lightgrey", {211, 211, 211}},
{"lightpink", {255, 182, 193}},
{"lightsalmon", {255, 160, 122}},
{"lightseagreen", { 32, 178, 170}},
{"lightskyblue", {135, 206, 250}},
{"lightslategray", {119, 136, 153}},
{"lightslategrey", {119, 136, 153}},
{"lightsteelblue", {176, 196, 222}},
{"lightyellow", {255, 255, 224}},
{"lime", { 0, 255, 0}},
{"limegreen", { 50, 205, 50}},
{"linen", {250, 240, 230}},
{"magenta", {255, 0, 255}},
{"maroon", {128, 0, 0}},
{"mediumaquamarine", {102, 205, 170}},
{"mediumblue", { 0, 0, 205}},
{"mediumorchid", {186, 85, 211}},
{"mediumpurple", {147, 112, 219}},
{"mediumseagreen", { 60, 179, 113}},
{"mediumslateblue", {123, 104, 238}},
{"mediumspringgreen", { 0, 250, 154}},
{"mediumturquoise", { 72, 209, 204}},
{"mediumvioletred", {199, 21, 133}},
{"midnightblue", { 25, 25, 112}},
{"mintcream", {245, 255, 250}},
{"mistyrose", {255, 228, 225}},
{"moccasin", {255, 228, 181}},
{"navajowhite", {255, 222, 173}},
{"navy", { 0, 0, 128}},
{"oldlace", {253, 245, 230}},
{"olive", {128, 128, 0}},
{"olivedrab", {107, 142, 35}},
{"orange", {255, 165, 0}},
{"orangered", {255, 69, 0}},
{"orchid", {218, 112, 214}},
{"palegoldenrod", {238, 232, 170}},
{"palegreen", {152, 251, 152}},
{"paleturquoise", {175, 238, 238}},
{"palevioletred", {219, 112, 147}},
{"papayawhip", {255, 239, 213}},
{"peachpuff", {255, 218, 185}},
{"peru", {205, 133, 63}},
{"pink", {255, 192, 203}},
{"plum", {221, 160, 221}},
{"powderblue", {176, 224, 230}},
{"purple", {128, 0, 128}},
{"red", {255, 0, 0}},
{"rosybrown", {188, 143, 143}},
{"royalblue", { 65, 105, 225}},
{"saddlebrown", {139, 69, 19}},
{"salmon", {250, 128, 114}},
{"sandybrown", {244, 164, 96}},
{"seagreen", { 46, 139, 87}},
{"seashell", {255, 245, 238}},
{"sienna", {160, 82, 45}},
{"silver", {192, 192, 192}},
{"skyblue", {135, 206, 235}},
{"slateblue", {106, 90, 205}},
{"slategray", {112, 128, 144}},
{"slategrey", {112, 128, 144}},
{"snow", {255, 250, 250}},
{"springgreen", { 0, 255, 127}},
{"steelblue", { 70, 130, 180}},
{"tan", {210, 180, 140}},
{"teal", { 0, 128, 128}},
{"thistle", {216, 191, 216}},
{"tomato", {255, 99, 71}},
{"turquoise", { 64, 224, 208}},
{"violet", {238, 130, 238}},
{"wheat", {245, 222, 179}},
{"white", {255, 255, 255}},
{"whitesmoke", {245, 245, 245}},
{"yellow", {255, 255, 0}},
{"yellowgreen", {154, 205, 50}},
{NULL, {0, 0, 0}}
};
static char const *const display_vals[] = {
"inline", "block", "list-item", "run-in", "compact", "marker", "table", "inline-table",
"table-row-group", "table-header-group", "table-footer-group", "table-row",
};
static char const *const font_stretch_vals[] = {
"normal",
"wider",
"narrower",
"ultra-condensed",
"extra-condensed",
"condensed",
"semi-condensed",
"semi-expanded",
"expanded",
"extra-expanded",
"ultra-expanded",
};
"100", "200", "300", "400", "500",
static char const *const writing_mode_vals[] = {"lr-tb", "rl-tb", "tb-rl", /*"lr", "rl", "tb",*/ NULL};
/* TODO: Inkscape correctly accepts lr,rl,tb, but reports them as lr-tb etc.
Either change inkscape or write custom test. */
static gchar *
{
return ret;
}
static void
{
for (unsigned i = 0; vals[i]; ++i) {
}
}
static void
{
#if 0
for (unsigned i = 0; i < G_N_ELEMENTS(extra_vals); ++i) {
color_vals[i] = extra_vals[i];
}
for (unsigned i = 0; i < G_N_ELEMENTS(color_keywords); ++i) {
}
/* todo: other color stuff (rgb(), #123) */
#endif
}
static void
{
/* Ref: http://www.w3.org/TR/SVG11/painting.html#SpecifyingPaint */
/* todo: uri, `<uri> none' etc. */
}
static void
{
/* TODO */
(1.0 / (1 << 7)),
(1.0 / (1 << 8)),
(1.0 / (1 << 15)),
(1.0 / (1 << 23)),
(1.0 / (1 << 24)),
(1.0 / (1 << 25)),
(1.0 / (1 << 26)),
1e-5, 0.13, 1/7., 2/3., 10/11., 1.0};
for (unsigned i = 0; i < G_N_ELEMENTS(propns); ++i) {
? min
: ( propn == 1
? max
char val_str[35];
char *endptr;
} else {
}
}
}
static void
{
// Ref: http://www.w3.org/TR/SVG11/painting.html#StrokeMiterlimitProperty
#if 0
static char const *const miterlimit_vals[] = {
};
// bad values: <1, percentages, strings (none etc.).
#endif
}
static void
{
static char const *const generic_font_family_vals[] = {"serif", "sans-serif", "cursive", "fantasy", "monospace", NULL};
/* todo: unrecognized fonts, comma-separated lists. */
}
/**
* "unitful length" is used for font-size, which we always write with an explicit unit (typically
* `px') for better CSS interoperability.
*/
static void
{
/* todo */
}
static void
{
/* todo: exponential notation. See http://www.w3.org/TR/SVG11/types.html#DataTypeNumber for
}
static void
{
}
static void
{
/* todo: exponential notation */
}
static void
{
/* todo: uri's */
}
static void
gpointer /*user_data*/)
{
/* todo: We could strncpy message to a static buffer for later testing with
* UTEST_ASSERT(streq(prev_message, exp_message)). */
}
static void
{
("MUL gives 0x%06x=%g, whereas explicit conversions give 0x%06x=%g;\n"
"multiplicands: 0x%06x * 0x%06x (i.e. %g * %g)",
}
static void
{
UTEST_TEST("SP_SCALE24_MUL") {
for (unsigned i = 0; i <= 10; ++i) {
for (unsigned j = 0; j <= 10; ++j) {
}
}
for (unsigned i = 0; i < 10000; ++i) {
}
}
}
static void
{
unsigned const either = 2;
struct {
bool parent_set;
bool parent_inherit;
float parent_float_val;
bool child_set;
bool child_inherit;
float child_float_val;
unsigned exp_set;
unsigned exp_inherit;
double exp_float_val;
} const cases[] = {
{false, false, 1.0, false, false, 1.0, false, false, 1.0},
{false, false, 1.0, true, true, 1.0, false, false, 1.0},
{false, false, 1.0, true, false, 1.0, false, false, 1.0},
{false, false, 1.0, true, false, 0.5, true, false, 0.5},
{false, false, 1.0, true, false, 0.0, true, false, 0.0},
{true, true, 1.0, false, false, 1.0, true, true, 1.0},
{true, true, 0.7, false, false, 1.0, true, true, 0.7},
{true, true, 0.0, false, false, 1.0, true, true, 0.0},
{true, true, 1.0, true, true, 1.0, true, true, 1.0},
/* child computed value isn't required to be up-to-date, so test what happens when it
* isn't up-to-date. */
{true, true, 1.0, true, true, 0.7, true, true, 1.0},
{true, true, 0.6, true, true, 0.3, true, false, 0.36},
{true, true, 0.0, true, true, 0.0, true, true, 0.0},
{true, true, 0.0, true, true, 0.9, true, true, 0.0},
/* parent inherit, child set to number */
{true, true, 1.0, true, false, 1.0, true, true, 1.0},
{true, true, 1.0, true, false, 0.8, true, false, 0.8},
{true, true, 1.0, true, false, 0.0, true, false, 0.0},
{true, true, 0.9, true, false, 1.0, true, true, 0.9},
{true, true, 0.9, true, false, 0.8, true, false, 0.72},
{true, true, 0.9, true, false, 0.0, true, false, 0.0},
{true, true, 0.0, true, false, 1.0, true, true, 0.0},
{true, true, 0.0, true, false, 0.0, true, false, 0.0},
/* parent set to number. */
{true, false, 0.3, false, false, 1.0, true, false, 0.3},
{true, false, 0.3, false, false, 1.0, true, false, 0.3},
{true, false, 0.0, false, false, 1.0, true, false, 0.0},
{true, false, 0.8, true, true, 0.8, true, false, 0.64},
{true, false, 0.8, true, true, 0.5, true, false, 0.64},
{true, false, 0.0, true, true, 0.0, true, false, 0.0},
{true, false, 0.0, true, true, 0.4, true, false, 0.0},
{true, false, 1.0, true, false, 0.4, true, false, 0.4},
{true, false, 1.0, true, false, 0.0, true, false, 0.0},
{true, false, 0.7, true, false, 1.0, true, false, 0.7},
{true, false, 0.7, true, false, 0.4, true, false, 0.28},
{true, false, 0.7, true, false, 0.0, true, false, 0.0},
{true, false, 0.0, true, false, 1.0, true, false, 0.0},
{true, false, 0.0, true, false, 0.6, true, false, 0.0},
{true, false, 0.0, true, false, 0.0, true, false, 0.0}
};
UTEST_TEST("sp_style_merge_from_dying_parent: opacity") {
for (unsigned i = 0; i < G_N_ELEMENTS(cases); ++i) {
}
}
("i=%u, expected 0x%06x=%g but found 0x%06x=%g; "
"parent 0x%06x=%g, child 0x%06x=%g",
}
}
}
static bool
{
struct {
char const *property;
char const *ink_dfl;
char const *spec_dfl;
void (*tst_fn)(char const[], char const *const[]);
char const *const *tst_fn_arg;
bool can_explicitly_inherit;
} const props[] = {
// initial value "depends on user agent"
// initial value depends on user agent
// TODO: abs, rel, pcnt.
// TODO: http://www.w3.org/TR/SVG11/painting.html#StrokeDasharrayProperty
//{"stroke-dashoffset", "0", "0", length_val, NULL, true},
// fixme: dashoffset currently fails a number of tests, but the relevant code
// is being worked on for something else at the time of writing, so I'm
// delaying fixing it. It should be changed to SPILength.
};
char const str0_all_exp[] =
"font-size:medium;"
"font-style:normal;"
"font-variant:normal;"
"font-weight:normal;"
"font-stretch:normal;"
"text-indent:0;"
"text-align:start;"
"text-decoration:none;"
"line-height:normal;"
"letter-spacing:normal;"
"word-spacing:normal;"
"text-transform:none;"
"direction:ltr;"
"block-progression:tb;"
"writing-mode:lr-tb;"
"text-anchor:start;"
"opacity:1;"
"color:#000000;"
"fill:#000000;"
"fill-opacity:1;"
"fill-rule:nonzero;"
"stroke:none;"
"stroke-width:1;"
"stroke-linecap:butt;"
"stroke-linejoin:miter;"
"marker:none;"
"marker-start:none;"
"marker-mid:none;"
"marker-end:none;"
"stroke-miterlimit:4;"
"stroke-dasharray:none;"
"stroke-dashoffset:0;"
"stroke-opacity:1;"
"visibility:visible;"
"display:inline;"
"overflow:visible;"
"font-family:Bitstream Vera Sans";
utest_start("style");
UTEST_TEST("sp_style_new, sp_style_write_string") {
}
UTEST_TEST("sp_style_merge_from_style_string(whitespace, ifset") {
}
UTEST_TEST("sp_style_merge_from_style_string(whitespace, always") {
}
/* Some tests for invalid style strings. We temporarily suppress all g_warning's. (The
current code uses g_warning instead of proper SVG error handling.) */
UTEST_TEST("sp_style_merge_from_style_string(\"fill:\", ifset)") {
}
UTEST_TEST("sp_style_merge_from_style_string(\"font-family:\", always)") {
}
UTEST_TEST("sp_style_merge_from_style_string(\"fill: \", ifset)") {
}
UTEST_TEST("sp_style_merge_from_style_string(\"font-family: \", always)") {
}
UTEST_TEST("sp_style_merge_from_style_string(\":none\", ifset)") {
}
/* The following tests involve invalid style, but aren't expected to trigger
g_log calls. */
/* invalid color setting */
{
for (unsigned i = 0; i < G_N_ELEMENTS(bad); ++i) {
}
}
}
/* End of invalid style string examples. */
#if 1 /* previously failed because of dashoffset:0 vs dashoffset:0.00000000 */
UTEST_TEST("sp_style_merge_from_style_string(default): ifset") {
}
UTEST_TEST("sp_style_merge_from_style_string(default): always") {
}
#endif
UTEST_TEST("sp_style_merge_from_style_string") {
/* Try setting default values, check that the all string is unaffected
but that the ifset string is affected. */
for (unsigned i = 0; i < G_N_ELEMENTS(props); ++i) {
}
/* Check that explicit `inherit' is correctly preserved by write(ifset). */
for (unsigned i = 0; i < G_N_ELEMENTS(props); ++i) {
if (!props[i].can_explicitly_inherit) {
continue;
}
}
for (unsigned i = 0; i < G_N_ELEMENTS(props); ++i) {
}
}
return utest_end();
}
int main()
{
return ( test_style()
: EXIT_FAILURE );
}
/*
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 :