diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-07-31 14:28:34 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-07-31 14:28:34 -0400 |
commit | 77c8408675c6e8aaded386932aad66004004060a (patch) | |
tree | 241100ecc21bd3e7600604bd8b7326272491c8e1 /tests | |
parent | 09111969bd5aef2b424c515a1f41bb857ca436d6 (diff) | |
download | pango-77c8408675c6e8aaded386932aad66004004060a.tar.gz |
tests: Add tests for pango_parse_color_with_alpha
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testcolor.c | 114 |
1 files changed, 74 insertions, 40 deletions
diff --git a/tests/testcolor.c b/tests/testcolor.c index 36f2dbf3..62bbe4bf 100644 --- a/tests/testcolor.c +++ b/tests/testcolor.c @@ -25,57 +25,92 @@ typedef struct _ColorSpec { const gchar *spec; gboolean valid; + int color_or_alpha; guint16 red; guint16 green; guint16 blue; + guint16 alpha; } ColorSpec; -static gboolean test_one_color (ColorSpec *spec) +#define COLOR 1 +#define ALPHA 2 +#define BOTH 3 + +static void +test_one_color (ColorSpec *spec) { PangoColor color; gboolean accepted; + guint16 alpha; - accepted = pango_color_parse (&color, spec->spec); + if (spec->color_or_alpha & COLOR) + { + accepted = pango_color_parse (&color, spec->spec); - if (accepted == spec->valid && - (!accepted || - (color.red == spec->red && - color.green == spec->green && - color.blue == spec->blue))) - return TRUE; - else - return FALSE; -} + if (!spec->valid) + { + g_assert_false (accepted); + } + else + { + g_assert_true (accepted); + g_assert_cmpuint (color.red, ==, spec->red); + g_assert_cmpuint (color.green, ==, spec->green); + g_assert_cmpuint (color.blue, ==, spec->blue); + } + } + if (spec->color_or_alpha & ALPHA) + { + accepted = pango_color_parse_with_alpha (&color, &alpha, spec->spec); + + if (!spec->valid) + { + g_assert_false (accepted); + } + else + { + g_assert_true (accepted); + g_assert_cmpuint (color.red, ==, spec->red); + g_assert_cmpuint (color.green, ==, spec->green); + g_assert_cmpuint (color.blue, ==, spec->blue); + g_assert_cmpuint (alpha, ==, spec->alpha); + } + } +} ColorSpec specs [] = { - { "#abc", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#aabbcc", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#aaabbbccc", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#100100100", 1, 0x1001, 0x1001, 0x1001 }, - { "#aaaabbbbcccc", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#fff", 1, 0xffff, 0xffff, 0xffff }, - { "#ffffff", 1, 0xffff, 0xffff, 0xffff }, - { "#fffffffff", 1, 0xffff, 0xffff, 0xffff }, - { "#ffffffffffff", 1, 0xffff, 0xffff, 0xffff }, - { "#000", 1, 0x0000, 0x0000, 0x0000 }, - { "#000000", 1, 0x0000, 0x0000, 0x0000 }, - { "#000000000", 1, 0x0000, 0x0000, 0x0000 }, - { "#000000000000", 1, 0x0000, 0x0000, 0x0000 }, - { "#AAAABBBBCCCC", 1, 0xaaaa, 0xbbbb, 0xcccc }, - { "#aa bb cc ", 0, 0, 0, 0 }, - { "#aa bb ccc", 0, 0, 0, 0 }, - { "#ab", 0, 0, 0, 0 }, - { "#aabb", 0, 0, 0, 0 }, - { "#aaabb", 0, 0, 0, 0 }, - { "aaabb", 0, 0, 0, 0 }, - { "", 0, 0, 0, 0 }, - { "#", 0, 0, 0, 0 }, - { "##fff", 0, 0, 0, 0 }, - { "#0000ff+", 0, 0, 0, 0 }, - { "#0000f+", 0, 0, 0, 0 }, - { "#0x00x10x2", 0, 0, 0, 0 }, - { NULL, 0, 0, 0, 0 } + { "#abc", 1, BOTH, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#aabbcc", 1, BOTH, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#aaabbbccc", 1, BOTH, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#100100100", 1, BOTH, 0x1001, 0x1001, 0x1001, 0xffff }, + { "#aaaabbbbcccc", 1, COLOR, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#fff", 1, BOTH, 0xffff, 0xffff, 0xffff, 0xffff }, + { "#ffffff", 1, BOTH, 0xffff, 0xffff, 0xffff, 0xffff }, + { "#fffffffff", 1, BOTH, 0xffff, 0xffff, 0xffff, 0xffff }, + { "#ffffffffffff", 1, COLOR, 0xffff, 0xffff, 0xffff, 0xffff }, + { "#000", 1, BOTH, 0x0000, 0x0000, 0x0000, 0xffff }, + { "#000000", 1, BOTH, 0x0000, 0x0000, 0x0000, 0xffff }, + { "#000000000", 1, BOTH, 0x0000, 0x0000, 0x0000, 0xffff }, + { "#000000000000", 1, COLOR, 0x0000, 0x0000, 0x0000, 0xffff }, + { "#AAAABBBBCCCC", 1, COLOR, 0xaaaa, 0xbbbb, 0xcccc, 0xffff }, + { "#aa bb cc ", 0, BOTH, 0, 0, 0, 0 }, + { "#aa bb ccc", 0, BOTH, 0, 0, 0, 0 }, + { "#ab", 0, BOTH, 0, 0, 0, 0 }, + { "#aabb", 0, COLOR, 0, 0, 0, 0 }, + { "#aaabb", 0, BOTH, 0, 0, 0, 0 }, + { "aaabb", 0, BOTH, 0, 0, 0, 0 }, + { "", 0, BOTH, 0, 0, 0, 0 }, + { "#", 0, BOTH, 0, 0, 0, 0 }, + { "##fff", 0, BOTH, 0, 0, 0, 0 }, + { "#0000ff+", 0, BOTH, 0, 0, 0, 0 }, + { "#0000f+", 0, BOTH, 0, 0, 0, 0 }, + { "#0x00x10x2", 0, BOTH, 0, 0, 0, 0 }, + { "#abcd", 1, ALPHA, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd }, + { "#aabbccdd", 1, ALPHA, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd }, + { "#aaaabbbbccccdddd", + 1, ALPHA, 0xaaaa, 0xbbbb, 0xcccc, 0xdddd }, + { NULL, 0, BOTH, 0, 0, 0, 0 } }; static void @@ -84,8 +119,7 @@ test_color (void) ColorSpec *spec; for (spec = specs; spec->spec; spec++) - g_assert (test_one_color (spec)); - + test_one_color (spec); } int |