diff options
author | Matthias Clasen <matthiasc@src.gnome.org> | 2002-09-22 22:42:47 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2002-09-22 22:42:47 +0000 |
commit | 9534f3311d23e1ff48fd747b8568064946350e4d (patch) | |
tree | 5f4c1cfb04006ee7913ea4079de77b757b3875e1 /tests/testcolor.c | |
parent | cd8f626345fdf182a927e36eb1af613590a9bdce (diff) | |
download | pango-9534f3311d23e1ff48fd747b8568064946350e4d.tar.gz |
Make color parsing more robust and correct. (#93804)
* pango/pango-color.c (pango_color_parse): Make color parsing
more robust and correct. (#93804)
* tests/testcolor.c: Tests for pango_color_parse.
* tests/Makefile.am: Build testcolor.
* tests/runtests.sh: Run testcolor.
Diffstat (limited to 'tests/testcolor.c')
-rw-r--r-- | tests/testcolor.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/testcolor.c b/tests/testcolor.c new file mode 100644 index 00000000..e41b053e --- /dev/null +++ b/tests/testcolor.c @@ -0,0 +1,76 @@ +#include <glib.h> +#include <pango/pango.h> + +typedef struct _ColorSpec { + const gchar *spec; + gboolean valid; + guint16 red; + guint16 green; + guint16 blue; +} ColorSpec; + +gboolean test_color (ColorSpec *spec) +{ + PangoColor color; + gboolean accepted; + + 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; +} + + +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 }, + { "#aa bb ccc", 0 }, + { "#ab", 0 }, + { "#aabb", 0 }, + { "#aaabb", 0 }, + { "aaabb", 0 }, + { "", 0 }, + { "#", 0 }, + { "##fff", 0 }, + { "#0000ff+", 0 }, + { "#0000f+", 0 }, + { "#0x00x10x2", 0 }, + { NULL, 0 } +}; + +int +main (int argc, char *argv[]) +{ + gboolean success; + ColorSpec *spec; + gchar *blob; + + success = TRUE; + for (spec = specs; spec->spec; spec++) + success &= test_color (spec); + + return !success; +} + + + + |