summaryrefslogtreecommitdiff
path: root/gdk/tests
diff options
context:
space:
mode:
authorOwen W. Taylor <otaylor@fishsoup.net>2010-11-02 15:30:44 -0400
committerOwen W. Taylor <otaylor@fishsoup.net>2010-11-03 13:41:45 -0400
commit5daab5266113a6aadd96fdcf504f3aa19c48fe39 (patch)
treed0524287a6f25fe1efeff49feb8908317b034b0c /gdk/tests
parentfbdcf193ae485cb311b31ed9ab1d69d69701598d (diff)
downloadgtk+-5daab5266113a6aadd96fdcf504f3aa19c48fe39.tar.gz
Switch to CSS interpretation of rgb() and rgba() colors
CSS3 defines a somewhat odd syntax for rgba() colors - the rgb values are integers from 0 to 255 or percentages and the a value is a float from 0 to 1. To avoid increasing the total amount of confusion in the world, make gdk_rgb_to_string() and gdk_rgb_parse() follow this syntax rather than using floats for r, g, and b. https://bugzilla.gnome.org/show_bug.cgi?id=633762
Diffstat (limited to 'gdk/tests')
-rw-r--r--gdk/tests/gdk-color.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/gdk/tests/gdk-color.c b/gdk/tests/gdk-color.c
index b0736b8b3e..2dbe2ad248 100644
--- a/gdk/tests/gdk-color.c
+++ b/gdk/tests/gdk-color.c
@@ -14,23 +14,23 @@ test_color_parse (void)
res = gdk_rgba_parse ("", &color);
g_assert (!res);
- expected.red = 0.4;
- expected.green = 0.3;
- expected.blue = 0.2;
+ expected.red = 100/255.;
+ expected.green = 90/255.;
+ expected.blue = 80/255.;
expected.alpha = 0.1;
- res = gdk_rgba_parse ("rgba(0.4,0.3,0.2,0.1)", &color);
- g_assert (res);
- g_assert (gdk_rgba_equal (&color, &expected));
-
- res = gdk_rgba_parse ("rgba ( 0.4 , 0.3 , 0.2 , 0.1 )", &color);
+ res = gdk_rgba_parse ("rgba(100,90,80,0.1)", &color);
g_assert (res);
g_assert (gdk_rgba_equal (&color, &expected));
expected.red = 0.4;
expected.green = 0.3;
expected.blue = 0.2;
- expected.alpha = 1.0;
- res = gdk_rgba_parse ("rgb(0.4,0.3,0.2)", &color);
+ expected.alpha = 0.1;
+ res = gdk_rgba_parse ("rgba(40%,30%,20%,0.1)", &color);
+ g_assert (res);
+ g_assert (gdk_rgba_equal (&color, &expected));
+
+ res = gdk_rgba_parse ("rgba( 40 % , 30 % , 20 % , 0.1 )", &color);
g_assert (res);
g_assert (gdk_rgba_equal (&color, &expected));
@@ -61,10 +61,13 @@ test_color_to_string (void)
gchar *res_en;
gchar *orig;
+ /* Using /255. values for the r, g, b components should
+ * make sure they round-trip exactly without rounding
+ * from the double => integer => double conversions */
rgba.red = 1.0;
- rgba.green = 0.5;
- rgba.blue = 0.1;
- rgba.alpha = 1.0;
+ rgba.green = 128/255.;
+ rgba.blue = 64/255.;
+ rgba.alpha = 0.5;
orig = g_strdup (setlocale (LC_ALL, NULL));
res = gdk_rgba_to_string (&rgba);