summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdk/tests/Makefile.am21
-rw-r--r--gdk/tests/gdk-color.c62
2 files changed, 73 insertions, 10 deletions
diff --git a/gdk/tests/Makefile.am b/gdk/tests/Makefile.am
index 2567627a39..04e5b253fe 100644
--- a/gdk/tests/Makefile.am
+++ b/gdk/tests/Makefile.am
@@ -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
index 0000000000..f2346de251
--- /dev/null
+++ b/gdk/tests/gdk-color.c
@@ -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 ();
+}