5 test_color_parse (void)
11 res = gdk_rgba_parse (&color, "foo");
14 res = gdk_rgba_parse (&color, "");
17 expected.red = 100/255.;
18 expected.green = 90/255.;
19 expected.blue = 80/255.;
21 res = gdk_rgba_parse (&color, "rgba(100,90,80,0.1)");
23 g_assert (gdk_rgba_equal (&color, &expected));
29 res = gdk_rgba_parse (&color, "rgba(40%,30%,20%,0.1)");
31 g_assert (gdk_rgba_equal (&color, &expected));
33 res = gdk_rgba_parse (&color, "rgba( 40 % , 30 % , 20 % , 0.1 )");
35 g_assert (gdk_rgba_equal (&color, &expected));
41 res = gdk_rgba_parse (&color, "red");
43 g_assert (gdk_rgba_equal (&color, &expected));
46 expected.green = 0x8080 / 65535.;
49 res = gdk_rgba_parse (&color, "#0080ff");
51 g_assert (gdk_rgba_equal (&color, &expected));
57 res = gdk_rgba_parse (&color, "rgb(0,0,0)");
59 g_assert (gdk_rgba_equal (&color, &expected));
63 test_color_to_string (void)
72 /* Using /255. values for the r, g, b components should
73 * make sure they round-trip exactly without rounding
74 * from the double => integer => double conversions */
76 rgba.green = 128/255.;
80 orig = g_strdup (setlocale (LC_ALL, NULL));
81 res = gdk_rgba_to_string (&rgba);
82 gdk_rgba_parse (&out, res);
83 g_assert (gdk_rgba_equal (&rgba, &out));
85 setlocale (LC_ALL, "de_DE.utf-8");
86 res_de = gdk_rgba_to_string (&rgba);
87 g_assert_cmpstr (res, ==, res_de);
89 setlocale (LC_ALL, "en_US.utf-8");
90 res_en = gdk_rgba_to_string (&rgba);
91 g_assert_cmpstr (res, ==, res_en);
97 setlocale (LC_ALL, orig);
102 test_color_copy (void)
112 out = gdk_rgba_copy (&rgba);
113 g_assert (gdk_rgba_equal (&rgba, out));
119 test_color_parse_nonsense (void)
124 g_test_bug ("667485");
126 res = gdk_rgba_parse (&color, "rgb(,,)");
129 res = gdk_rgba_parse (&color, "rgb(%,%,%)");
132 res = gdk_rgba_parse (&color, "rgb(nan,nan,nan)");
135 res = gdk_rgba_parse (&color, "rgb(inf,inf,inf)");
138 res = gdk_rgba_parse (&color, "rgb(1p12,0,0)");
141 res = gdk_rgba_parse (&color, "rgb(5d1%,1,1)");
144 res = gdk_rgba_parse (&color, "rgb(0,0,0)moo");
147 res = gdk_rgba_parse (&color, "rgb(0,0,0) moo");
152 main (int argc, char *argv[])
154 g_test_init (&argc, &argv, NULL);
156 g_test_bug_base ("http://bugzilla.gnome.org");
158 g_test_add_func ("/rgba/parse", test_color_parse);
159 g_test_add_func ("/rgba/parse/nonsense", test_color_parse_nonsense);
160 g_test_add_func ("/rgba/to-string", test_color_to_string);
161 g_test_add_func ("/rgba/copy", test_color_copy);
163 return g_test_run ();