[gegl-gtk] Add test infrastructure, and a sanity test
- From: Jon Nordby <jonnor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl-gtk] Add test infrastructure, and a sanity test
- Date: Thu, 21 Jul 2011 19:49:44 +0000 (UTC)
commit b8cce89cabf84e08fadd9ad4e9a086bd71b8ce67
Author: Jon Nordby <jononor gmail com>
Date: Thu Jun 23 20:07:11 2011 +0200
Add test infrastructure, and a sanity test
Makefile.am | 3 +-
configure.ac | 1 +
tests/.gitignore | 3 ++
tests/Makefile.am | 58 ++++++++++++++++++++++++++++++++++++++++++
tests/test-view.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 136 insertions(+), 1 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 0ef1542..f0ddf69 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,7 +5,8 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
SUBDIRS=\
gegl-gtk \
operations \
- examples
+ examples \
+ tests
pkgconfigdir = $(libdir)/pkgconfig
diff --git a/configure.ac b/configure.ac
index 71bd27b..badcc20 100644
--- a/configure.ac
+++ b/configure.ac
@@ -274,6 +274,7 @@ Makefile
gegl-gtk/Makefile
operations/Makefile
examples/Makefile
+tests/Makefile
gegl-gtk2-0.1.pc
gegl-gtk3-0.1.pc
])
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..c1627e2
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,3 @@
+test-view
+*report.xml
+*report.html
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..ccad802
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,58 @@
+
+check_PROGRAMS = test-view
+
+test_view_SOURCES = test-view.c
+test_view_CPPFLAGS = $(GTK_CFLAGS) $(GEGL_CFLAGS) -I$(top_srcdir)/gegl-gtk
+
+if HAVE_GTK2
+test_view_LDADD = $(top_builddir)/gegl-gtk/libgegl-gtk2-0.1.la $(GTK_LIBS) $(GEGL_LIBS)
+else
+test_view_LDADD = $(top_builddir)/gegl-gtk/libgegl-gtk3-0.1.la $(GTK_LIBS) $(GEGL_LIBS)
+endif
+
+
+# ----------------------------------------------
+# Rules for hooking up the unit/functional tests
+GTESTER = gtester
+GTESTER_REPORT = gtester-report
+
+# test: run all tests
+test: ${check_PROGRAMS}
+ @test -z "${check_PROGRAMS}" || top_srcdir=${top_srcdir} ${GTESTER} --verbose ${check_PROGRAMS}
+
+# test-report: run tests and generate report
+# perf-report: run tests with -m perf and generate report
+# full-report: like test-report: with -m perf and -m slow
+test-report perf-report full-report: ${check_PROGRAMS}
+ @ignore_logdir=true; \
+ if test -z "$$GTESTER_LOGDIR"; then \
+ GTESTER_LOGDIR=`mktemp -d "\`pwd\`/.testlogs-XXXXXX"`; export GTESTER_LOGDIR; \
+ ignore_logdir=false; \
+ fi; \
+ test -z "${check_PROGRAMS}" || { \
+ case $@ in \
+ test-report) test_options="-k";; \
+ perf-report) test_options="-k -m=perf";; \
+ full-report) test_options="-k -m=perf -m=slow";; \
+ esac; \
+ if test -z "$$GTESTER_LOGDIR"; then \
+ top_srcdir=${top_srcdir} ${GTESTER} --verbose $$test_options -o test-report.xml ${check_PROGRAMS}; \
+ elif test -n "${check_PROGRAMS}"; then \
+ top_srcdir=${top_srcdir} ${GTESTER} --verbose $$test_options -o `mktemp "$$GTESTER_LOGDIR/log-XXXXXX"` ${check_PROGRAMS}; \
+ fi; \
+ }; \
+ $$ignore_logdir || { \
+ echo '<?xml version="1.0"?>' > $ xml; \
+ echo '<report-collection>' >> $ xml; \
+ for lf in `ls -L "$$GTESTER_LOGDIR"/.`; do \
+ sed '1,1s/^<?xml\b[^>?]*?>//' <"$$GTESTER_LOGDIR"/"$$lf" >> $ xml; \
+ done; \
+ echo >> $ xml; \
+ echo '</report-collection>' >> $ xml; \
+ rm -rf "$$GTESTER_LOGDIR"/; \
+ ${GTESTER_REPORT} --version 2>/dev/null 1>&2; test "$$?" != 0 || ${GTESTER_REPORT} $ xml >$ html; \
+ }
+# run make test as part of make check
+check-local: test
+
+.PHONY: test test-report perf-report full-report
diff --git a/tests/test-view.c b/tests/test-view.c
new file mode 100644
index 0000000..af4c079
--- /dev/null
+++ b/tests/test-view.c
@@ -0,0 +1,72 @@
+
+#include <glib.h>
+
+#include <gegl-gtk-view.h>
+#include <gegl.h>
+
+static gboolean
+quit_gtk_main (gpointer data)
+{
+ gtk_main_quit();
+}
+
+/* Test that instantiating the widget and hooking up a gegl graph
+ * does not cause any crashes, criticals or warnings. */
+static void
+test_sanity (void) {
+
+ GtkWidget *window, *view;
+ GeglNode *gegl, *out, *loadbuf;
+ GeglBuffer *buffer;
+ gpointer buf;
+ GeglRectangle rect = {0, 0, 512, 512};
+
+ buffer = gegl_buffer_new (&rect, babl_format("R'G'B' u8"));
+ buf = gegl_buffer_linear_open (buffer, NULL, NULL, babl_format ("Y' u8"));
+ memset (buf, 255, 512 * 512);
+ gegl_buffer_linear_close (buffer, buf);
+
+ gegl = gegl_node_new ();
+ loadbuf = gegl_node_new_child (gegl, "operation", "gegl:buffer-source", "buffer", buffer, NULL);
+ out = gegl_node_new_child (gegl, "operation", "gegl:nop", NULL);
+ gegl_node_link_many (loadbuf, out, NULL);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ view = GTK_WIDGET (g_object_new (GEGL_GTK_TYPE_VIEW, "node", out, NULL));
+ gtk_container_add (GTK_CONTAINER (window), view);
+ gtk_widget_set_size_request (view, 512, 512);
+ gtk_widget_show_all (window);
+
+ // XXX: Better to do on/after expose event instead?
+ g_timeout_add(300, quit_gtk_main, NULL);
+ gtk_main ();
+
+ g_object_unref (gegl);
+ gegl_buffer_destroy (buffer);
+ gtk_widget_destroy (window);
+}
+
+/* TODO:
+ * - Test redraw logic
+ * - Test redraw with translation
+ * - Test redraw with scaling
+ * - Test redraw with rotation
+ * Benchmarks for cases above
+ */
+
+int
+main (int argc, char **argv) {
+
+ int retval = -1;
+
+ g_thread_init(NULL);
+ gtk_init(&argc, &argv);
+ gegl_init(&argc, &argv);
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/widgets/view/sanity", test_sanity);
+
+ retval = g_test_run();
+ gegl_exit();
+ return retval;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]