]> Pileus Git - ~andy/gtk/commitdiff
Add some GdkRGBA tests
authorMatthias Clasen <mclasen@redhat.com>
Mon, 25 Oct 2010 16:01:11 +0000 (12:01 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 25 Oct 2010 16:01:11 +0000 (12:01 -0400)
gdk/tests/Makefile.am
gdk/tests/gdk-color.c [new file with mode: 0644]

index 2567627a39de4bc16c48e156e0a381e6cdad8a47..04e5b253fe1d25f09837b477570664218069598f 100644 (file)
@@ -2,26 +2,27 @@ include $(top_srcdir)/Makefile.decl
 
 NULL=
 
-# check_PROGRAMS=check-gdk-cairo
-check_PROGRAMS=
-TESTS=$(check_PROGRAMS)
-TESTS_ENVIRONMENT=GDK_PIXBUF_MODULE_FILE=$(top_builddir)/gdk-pixbuf/loaders.cache
+noinst_PROGRAMS = $(TEST_PROGS)
 
-AM_CPPFLAGS=\
+AM_CPPFLAGS = \
        $(GDK_DEP_CFLAGS) \
        -I$(top_srcdir) \
        -I$(top_builddir)/gdk \
        $(NULL)
 
-check_gdk_cairo_SOURCES=\
-       check-gdk-cairo.c \
-       $(NULL)
-check_gdk_cairo_LDADD=\
+progs_ldadd = \
        $(GDK_DEP_LIBS) \
-       $(top_builddir)/gdk-pixbuf/libgdk_pixbuf-$(GTK_API_VERSION).la \
        $(top_builddir)/gdk/libgdk-$(gdktarget)-$(GTK_API_VERSION).la \
        $(NULL)
 
+#TEST_PROGS              += check-gdk-cairo
+check_gdk_cairo_SOURCES  = check-gdk-cairo.c
+check_gdk_cairo_LDADD    = $(progs_ldadd)
+
+TEST_PROGS        += gdk-color
+gdk_color_SOURCES  = gdk-color.c
+gdk_color_LDADD    = $(progs_ldadd)
+
 CLEANFILES = \
        cairosurface.png        \
        gdksurface.png
diff --git a/gdk/tests/gdk-color.c b/gdk/tests/gdk-color.c
new file mode 100644 (file)
index 0000000..f2346de
--- /dev/null
@@ -0,0 +1,62 @@
+#include <gdk/gdk.h>
+
+static void
+test_color_parse (void)
+{
+  GdkRGBA color;
+  GdkRGBA expected;
+  gboolean res;
+
+  res = gdk_rgba_parse ("foo", &color);
+  g_assert (!res);
+
+  res = gdk_rgba_parse ("", &color);
+  g_assert (!res);
+
+  expected.red = 0.4;
+  expected.green = 0.3;
+  expected.blue = 0.2;
+  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);
+  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);
+  g_assert (res);
+  g_assert (gdk_rgba_equal (&color, &expected));
+
+  expected.red = 1.0;
+  expected.green = 0.0;
+  expected.blue = 0.0;
+  expected.alpha = 1.0;
+  res = gdk_rgba_parse ("red", &color);
+  g_assert (res);
+  g_assert (gdk_rgba_equal (&color, &expected));
+
+  expected.red = 0.0;
+  expected.green = 0x8080 / 65535.;
+  expected.blue = 1.0;
+  expected.alpha = 1.0;
+  res = gdk_rgba_parse ("#0080ff", &color);
+  g_assert (res);
+  g_assert (gdk_rgba_equal (&color, &expected));
+}
+
+int
+main (int argc, char *argv[])
+{
+        g_test_init (&argc, &argv, NULL);
+        gdk_init (&argc, &argv);
+
+        g_test_add_func ("/color/parse", test_color_parse);
+
+        return g_test_run ();
+}