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));
55 test_color_to_string (void)
64 /* Using /255. values for the r, g, b components should
65 * make sure they round-trip exactly without rounding
66 * from the double => integer => double conversions */
68 rgba.green = 128/255.;
72 orig = g_strdup (setlocale (LC_ALL, NULL));
73 res = gdk_rgba_to_string (&rgba);
74 gdk_rgba_parse (&out, res);
75 g_assert (gdk_rgba_equal (&rgba, &out));
77 setlocale (LC_ALL, "de_DE.utf-8");
78 res_de = gdk_rgba_to_string (&rgba);
79 g_assert_cmpstr (res, ==, res_de);
81 setlocale (LC_ALL, "en_US.utf-8");
82 res_en = gdk_rgba_to_string (&rgba);
83 g_assert_cmpstr (res, ==, res_en);
89 setlocale (LC_ALL, orig);
94 main (int argc, char *argv[])
96 g_test_init (&argc, &argv, NULL);
98 g_test_add_func ("/color/parse", test_color_parse);
99 g_test_add_func ("/color/to-string", test_color_to_string);
101 return g_test_run ();