Git init
[external/pango1.0.git] / tests / testcolor.c
1 /* Pango
2  * test-color.c: Test program for pango_color_parse()
3  *
4  * Copyright (C) 2002 Matthias Clasen
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #include <glib.h>
23 #include <pango/pango.h>
24
25 typedef struct _ColorSpec {
26   const gchar *spec;
27   gboolean valid;
28   guint16 red;
29   guint16 green;
30   guint16 blue;
31 } ColorSpec;
32
33 static gboolean test_color (ColorSpec *spec)
34 {
35   PangoColor color;
36   gboolean accepted;
37
38   accepted = pango_color_parse (&color, spec->spec);
39
40   if (accepted == spec->valid &&
41       (!accepted ||
42       (color.red == spec->red &&
43        color.green == spec->green &&
44        color.blue == spec->blue)))
45     return TRUE;
46   else
47     return FALSE;
48 }
49
50
51 ColorSpec specs [] = {
52   { "#abc",          1, 0xaaaa, 0xbbbb, 0xcccc },
53   { "#aabbcc",       1, 0xaaaa, 0xbbbb, 0xcccc },
54   { "#aaabbbccc",    1, 0xaaaa, 0xbbbb, 0xcccc },
55   { "#100100100",    1, 0x1001, 0x1001, 0x1001 },
56   { "#aaaabbbbcccc", 1, 0xaaaa, 0xbbbb, 0xcccc },
57   { "#fff",          1, 0xffff, 0xffff, 0xffff },
58   { "#ffffff",       1, 0xffff, 0xffff, 0xffff },
59   { "#fffffffff",    1, 0xffff, 0xffff, 0xffff },
60   { "#ffffffffffff", 1, 0xffff, 0xffff, 0xffff },
61   { "#000",          1, 0x0000, 0x0000, 0x0000 },
62   { "#000000",       1, 0x0000, 0x0000, 0x0000 },
63   { "#000000000",    1, 0x0000, 0x0000, 0x0000 },
64   { "#000000000000", 1, 0x0000, 0x0000, 0x0000 },
65   { "#AAAABBBBCCCC", 1, 0xaaaa, 0xbbbb, 0xcccc },
66   { "#aa bb cc ",    0, 0, 0, 0 },
67   { "#aa bb ccc",    0, 0, 0, 0 },
68   { "#ab",           0, 0, 0, 0 },
69   { "#aabb",         0, 0, 0, 0 },
70   { "#aaabb",        0, 0, 0, 0 },
71   { "aaabb",         0, 0, 0, 0 },
72   { "",              0, 0, 0, 0 },
73   { "#",             0, 0, 0, 0 },
74   { "##fff",         0, 0, 0, 0 },
75   { "#0000ff+",      0, 0, 0, 0 },
76   { "#0000f+",       0, 0, 0, 0 },
77   { "#0x00x10x2",    0, 0, 0, 0 },
78   { NULL,            0, 0, 0, 0 }
79 };
80
81 int
82 main (int argc, char *argv[])
83 {
84   gboolean success;
85   ColorSpec *spec;
86
87   g_setenv ("PANGO_RC_FILE", "./pangorc", TRUE);
88
89   success = TRUE;
90   for (spec = specs; spec->spec; spec++)
91     success &= test_color (spec);
92
93   return !success;
94 }