summaryrefslogtreecommitdiff
path: root/tests/testcolor.c
blob: e41b053e30608ff9c84c11c0e1b3e54429eda8a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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;
}