[gtk+] Add more tests for GdkRGBA parsing



commit ef1bc2923e4184c854730fea269ac44ffabf9906
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 8 22:18:46 2012 -0500

    Add more tests for GdkRGBA parsing
    
    These examples are taken from bug 667485.

 gdk/tests/rgba.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/gdk/tests/rgba.c b/gdk/tests/rgba.c
index d23bb96..fa2da62 100644
--- a/gdk/tests/rgba.c
+++ b/gdk/tests/rgba.c
@@ -49,6 +49,14 @@ test_color_parse (void)
   res = gdk_rgba_parse (&color, "#0080ff");
   g_assert (res);
   g_assert (gdk_rgba_equal (&color, &expected));
+
+  expected.red = 0.0;
+  expected.green = 0.0;
+  expected.blue = 0.0;
+  expected.alpha = 1.0;
+  res = gdk_rgba_parse (&color, "rgb(0,0,0)");
+  g_assert (res);
+  g_assert (gdk_rgba_equal (&color, &expected));
 }
 
 static void
@@ -107,12 +115,48 @@ test_color_copy (void)
   gdk_rgba_free (out);
 }
 
+static void
+test_color_parse_nonsense (void)
+{
+  GdkRGBA color;
+  gboolean res;
+
+  g_test_bug ("667485");
+
+  res = gdk_rgba_parse (&color, "rgb(,,)");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(%,%,%)");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(nan,nan,nan)");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(inf,inf,inf)");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(1p12,0,0)");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(5d1%,1,1)");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(0,0,0)moo");
+  g_assert (!res);
+
+  res = gdk_rgba_parse (&color, "rgb(0,0,0)  moo");
+  g_assert (!res);
+}
+
 int
 main (int argc, char *argv[])
 {
         g_test_init (&argc, &argv, NULL);
 
+        g_test_bug_base ("http://bugzilla.gnome.org";);
+
         g_test_add_func ("/rgba/parse", test_color_parse);
+        g_test_add_func ("/rgba/parse/nonsense", test_color_parse_nonsense);
         g_test_add_func ("/rgba/to-string", test_color_to_string);
         g_test_add_func ("/rgba/copy", test_color_copy);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]