[gtk+] Add tests for GdkRGBA serialization
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Add tests for GdkRGBA serialization
- Date: Mon, 25 Oct 2010 16:12:00 +0000 (UTC)
commit 377e7179b8a5fb5036b0015424a08707457ab75c
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Oct 25 12:10:48 2010 -0400
Add tests for GdkRGBA serialization
In particular, test that serialization is not dependent on the
locale.
gdk/gdkrgba.c | 16 +++++++++++-----
gdk/tests/gdk-color.c | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 5 deletions(-)
---
diff --git a/gdk/gdkrgba.c b/gdk/gdkrgba.c
index 68f602d..e26de98 100644
--- a/gdk/gdkrgba.c
+++ b/gdk/gdkrgba.c
@@ -269,9 +269,15 @@ gdk_rgba_equal (gconstpointer p1,
gchar *
gdk_rgba_to_string (GdkRGBA *rgba)
{
- return g_strdup_printf ("rgba(%f,%f,%f,%f)",
- CLAMP (rgba->red, 0, 1),
- CLAMP (rgba->green, 0, 1),
- CLAMP (rgba->blue, 0, 1),
- CLAMP (rgba->alpha, 0, 1));
+ gchar red[G_ASCII_DTOSTR_BUF_SIZE];
+ gchar green[G_ASCII_DTOSTR_BUF_SIZE];
+ gchar blue[G_ASCII_DTOSTR_BUF_SIZE];
+ gchar alpha[G_ASCII_DTOSTR_BUF_SIZE];
+
+ g_ascii_dtostr (red, G_ASCII_DTOSTR_BUF_SIZE, CLAMP (rgba->red, 0, 1));
+ g_ascii_dtostr (green, G_ASCII_DTOSTR_BUF_SIZE, CLAMP (rgba->green, 0, 1));
+ g_ascii_dtostr (blue, G_ASCII_DTOSTR_BUF_SIZE, CLAMP (rgba->blue, 0, 1));
+ g_ascii_dtostr (alpha, G_ASCII_DTOSTR_BUF_SIZE, CLAMP (rgba->alpha, 0, 1));
+
+ return g_strdup_printf ("rgba(%s,%s,%s,%s)", red, green, blue, alpha);
}
diff --git a/gdk/tests/gdk-color.c b/gdk/tests/gdk-color.c
index f2346de..b0736b8 100644
--- a/gdk/tests/gdk-color.c
+++ b/gdk/tests/gdk-color.c
@@ -1,3 +1,4 @@
+#include <locale.h>
#include <gdk/gdk.h>
static void
@@ -50,6 +51,42 @@ test_color_parse (void)
g_assert (gdk_rgba_equal (&color, &expected));
}
+static void
+test_color_to_string (void)
+{
+ GdkRGBA rgba;
+ GdkRGBA out;
+ gchar *res;
+ gchar *res_de;
+ gchar *res_en;
+ gchar *orig;
+
+ rgba.red = 1.0;
+ rgba.green = 0.5;
+ rgba.blue = 0.1;
+ rgba.alpha = 1.0;
+
+ orig = g_strdup (setlocale (LC_ALL, NULL));
+ res = gdk_rgba_to_string (&rgba);
+ gdk_rgba_parse (res, &out);
+ g_assert (gdk_rgba_equal (&rgba, &out));
+
+ setlocale (LC_ALL, "de_DE.utf-8");
+ res_de = gdk_rgba_to_string (&rgba);
+ g_assert_cmpstr (res, ==, res_de);
+
+ setlocale (LC_ALL, "en_US.utf-8");
+ res_en = gdk_rgba_to_string (&rgba);
+ g_assert_cmpstr (res, ==, res_en);
+
+ g_free (res);
+ g_free (res_de);
+ g_free (res_en);
+
+ setlocale (LC_ALL, orig);
+ g_free (orig);
+}
+
int
main (int argc, char *argv[])
{
@@ -57,6 +94,7 @@ main (int argc, char *argv[])
gdk_init (&argc, &argv);
g_test_add_func ("/color/parse", test_color_parse);
+ g_test_add_func ("/color/to-string", test_color_to_string);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]