[gegl-gtk] Tests: Split off tests for GeglGtk private class
- From: Jon Nordby <jonnor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl-gtk] Tests: Split off tests for GeglGtk private class
- Date: Sun, 9 Oct 2011 13:12:02 +0000 (UTC)
commit ffa3b4fa39602d2a0129f61424335d8d64b2aeb9
Author: Jon Nordby <jononor gmail com>
Date: Sun Oct 9 14:53:34 2011 +0200
Tests: Split off tests for GeglGtk private class
Also fixes failing redraw-on-computed test due to signal
being moved from GeglGtkView to ViewHelper.
tests/.gitignore | 2 +
tests/Makefile.am | 12 ++---
tests/test-view-helper.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++
tests/test-view.c | 93 ++---------------------------------
tests/utils.c | 30 +++++++++++
5 files changed, 164 insertions(+), 96 deletions(-)
---
diff --git a/tests/.gitignore b/tests/.gitignore
index c1627e2..3212334 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,3 +1,5 @@
+*.o
+test-view-helper
test-view
*report.xml
*report.html
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0b699dc..ec62723 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,15 +1,13 @@
-check_PROGRAMS = test-view
+check_PROGRAMS = test-view test-view-helper
test_view_SOURCES = test-view.c
test_view_CPPFLAGS = $(GTK_CFLAGS) $(GEGL_CFLAGS) -I$(top_srcdir)/gegl-gtk
+test_view_LDADD = $(top_builddir)/gegl-gtk/libgegl-gtk GEGL_GTK_GTK_VERSION@- GEGL_GTK_API_VERSION@.la $(GTK_LIBS) $(GEGL_LIBS)
-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
-
+test_view_helper_SOURCES = test-view-helper.c
+test_view_helper_CPPFLAGS = $(GTK_CFLAGS) $(GEGL_CFLAGS) -I$(top_srcdir)/gegl-gtk
+test_view_helper_LDADD = $(top_builddir)/gegl-gtk/libgegl-gtk GEGL_GTK_GTK_VERSION@- GEGL_GTK_API_VERSION@.la $(GTK_LIBS) $(GEGL_LIBS)
# ----------------------------------------------
# Rules for hooking up the unit/functional tests
diff --git a/tests/test-view-helper.c b/tests/test-view-helper.c
new file mode 100644
index 0000000..f9792db
--- /dev/null
+++ b/tests/test-view-helper.c
@@ -0,0 +1,123 @@
+
+#include <string.h>
+
+#include <glib.h>
+#include <gegl.h>
+
+#include <internal/view-helper.h>
+#include "utils.c"
+
+/* Stores the state used in widget tests.*/
+typedef struct {
+ ViewHelper *helper;
+ GeglNode *graph, *out, *loadbuf;
+ GeglBuffer *buffer;
+} ViewHelperTest;
+
+
+static void
+setup_helper_test (ViewHelperTest *test)
+{
+ gpointer buf;
+ GeglRectangle rect = {0, 0, 512, 512};
+
+ /* Create a buffer, fill it with white */
+ test->buffer = gegl_buffer_new (&rect, babl_format("R'G'B' u8"));
+ buf = gegl_buffer_linear_open (test->buffer, NULL, NULL, babl_format ("Y' u8"));
+ memset (buf, 255, rect.width * rect.height);
+ gegl_buffer_linear_close (test->buffer, buf);
+
+ /* Setup a graph with two nodes, one sourcing the buffer and a no-op */
+ test->graph = gegl_node_new ();
+ test->loadbuf = gegl_node_new_child (test->graph,
+ "operation", "gegl:buffer-source",
+ "buffer", test->buffer, NULL);
+ test->out = gegl_node_new_child (test->graph, "operation", "gegl:nop", NULL);
+ gegl_node_link_many (test->loadbuf, test->out, NULL);
+
+ /* Setup the GeglView helper, hook up the output node to it */
+ test->helper = view_helper_new();
+ view_helper_set_node(test->helper, test->out);
+}
+
+static void
+teardown_helper_test (ViewHelperTest *test)
+{
+ g_object_unref (test->graph);
+ gegl_buffer_destroy (test->buffer);
+ g_object_unref (test->helper);
+}
+
+
+typedef struct {
+ gboolean needs_redraw_called;
+ GeglRectangle *expected_result;
+} RedrawTestState;
+
+static void
+needs_redraw_event (ViewHelper *helper,
+ GeglRectangle *rect,
+ RedrawTestState *data)
+{
+ data->needs_redraw_called = TRUE;
+
+ g_assert (test_utils_compare_rect (rect, data->expected_result));
+}
+
+/* Test that the redraw signal is emitted when the GeglNode has been computed.
+ *
+ * NOTE: Does not test that the actual drawing happens, or even
+ * that queue_redraw is called, as this is hard to observe reliably
+ * Redraws can be triggered by other things, and the exposed events
+ * can be coalesced. */
+static void
+test_redraw_on_computed (void)
+{
+ ViewHelperTest test;
+ GeglRectangle computed_rect = {0, 0, 128, 128};
+ RedrawTestState test_data;
+ test_data.needs_redraw_called = FALSE;
+ test_data.expected_result = &computed_rect;
+
+ setup_helper_test(&test);
+ /* Setup will invalidate the node, make sure those events are processed. */
+ while (gtk_events_pending ()) {
+ gtk_main_iteration ();
+ }
+ gegl_node_process (test.out);
+
+ g_assert (IS_VIEW_HELPER (test.helper));
+
+ /* TODO: when adding tests for transformed cases,
+ * split out a function for testing the redrawn area, given
+ * the input area and the transformation (translation, scaling, rotation) */
+ g_signal_connect (G_OBJECT (test.helper), "redraw-needed",
+ G_CALLBACK (needs_redraw_event),
+ &test_data);
+
+
+ g_signal_emit_by_name (test.out, "computed", &computed_rect, NULL);
+
+ g_timeout_add (300, test_utils_quit_gtk_main, NULL);
+ gtk_main ();
+
+ g_assert(test_data.needs_redraw_called);
+
+ teardown_helper_test(&test);
+}
+
+int
+main (int argc, char **argv) {
+
+ int retval = -1;
+
+ g_thread_init(NULL);
+ gegl_init(&argc, &argv);
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/widgets/view/helper/redraw-on-computed", test_redraw_on_computed);
+
+ retval = g_test_run();
+ gegl_exit();
+ return retval;
+}
diff --git a/tests/test-view.c b/tests/test-view.c
index 5be1dff..e996589 100644
--- a/tests/test-view.c
+++ b/tests/test-view.c
@@ -1,40 +1,11 @@
-#include <glib.h>
-
-#include <gegl-gtk-view.h>
-#include <gegl.h>
#include <string.h>
-gboolean
-test_utils_display_is_set () {
- return g_getenv ("DISPLAY") != NULL;
-}
-
-void
-test_utils_print_rect (GeglRectangle *rect) {
-
- g_print ("GeglRectangle: %d,%d %dx%d", rect->x, rect->y, rect->width, rect->height);
-}
-
-static gboolean
-test_utils_quit_gtk_main (gpointer data)
-{
- gtk_main_quit();
-}
-
-/* Compare two rectangles, output */
-gboolean
-test_utils_compare_rect (GeglRectangle *r, GeglRectangle *s)
-{
- gboolean equal = gegl_rectangle_equal (r, s);
- if (!equal) {
- test_utils_print_rect (r);
- g_printf ("%s", " != ");
- test_utils_print_rect (s);
+#include <glib.h>
+#include <gegl.h>
- }
- return equal;
-}
+#include <gegl-gtk-view.h>
+#include "utils.c"
/* Stores the state used in widget tests.*/
typedef struct {
@@ -135,62 +106,7 @@ test_processing (void)
teardown_widget_test(&test);
}
-typedef struct {
- gboolean needs_redraw_called;
- GeglRectangle *expected_result;
-} RedrawTestState;
-
-static void
-needs_redraw_event (GeglGtkView *view,
- GeglRectangle *rect,
- RedrawTestState *data)
-{
- data->needs_redraw_called = TRUE;
- g_assert (test_utils_compare_rect (rect, data->expected_result));
-}
-
-/* Test that the redraw signal is emitted when the GeglNode has been computed.
- *
- * NOTE: Does not test that the actual drawing happens, or even
- * that queue_redraw is called, as this is hard to observe reliably
- * Redraws can be triggered by other things, and the exposed events
- * can be coalesced. */
-static void
-test_redraw_on_computed (void)
-{
- ViewWidgetTest test;
- GeglRectangle computed_rect = {0, 0, 128, 128};
- RedrawTestState test_data;
- test_data.expected_result = &computed_rect;
-
- setup_widget_test(&test);
- /* Setup will invalidate the node, make sure those events are processed. */
- while (gtk_events_pending ()) {
- gtk_main_iteration ();
- }
- gegl_node_process (test.out);
-
- g_assert (GEGL_GTK_IS_VIEW (test.view));
-
- /* TODO: when adding tests for transformed cases,
- * split out a function for testing the redrawn area, given
- * the input area and the transformation (translation, scaling, rotation) */
- g_signal_connect (G_OBJECT (test.view), "redraw",
- G_CALLBACK (needs_redraw_event),
- &test_data);
-
-
-
- g_signal_emit_by_name (test.out, "computed", &computed_rect, NULL);
-
- g_timeout_add (300, test_utils_quit_gtk_main, NULL);
- gtk_main ();
-
- g_assert(test_data.needs_redraw_called);
-
- teardown_widget_test(&test);
-}
/* TODO:
* - Test redraw with translation
@@ -223,7 +139,6 @@ main (int argc, char **argv) {
g_test_add_func("/widgets/view/sanity", test_sanity);
g_test_add_func("/widgets/view/processing", test_processing);
- g_test_add_func("/widgets/view/redraw-on-computed", test_redraw_on_computed);
retval = g_test_run();
gegl_exit();
diff --git a/tests/utils.c b/tests/utils.c
new file mode 100644
index 0000000..b3b5e57
--- /dev/null
+++ b/tests/utils.c
@@ -0,0 +1,30 @@
+gboolean
+test_utils_display_is_set () {
+ return g_getenv ("DISPLAY") != NULL;
+}
+
+void
+test_utils_print_rect (GeglRectangle *rect) {
+
+ g_print ("GeglRectangle: %d,%d %dx%d", rect->x, rect->y, rect->width, rect->height);
+}
+
+static gboolean
+test_utils_quit_gtk_main (gpointer data)
+{
+ gtk_main_quit();
+}
+
+/* Compare two rectangles, output */
+gboolean
+test_utils_compare_rect (GeglRectangle *r, GeglRectangle *s)
+{
+ gboolean equal = gegl_rectangle_equal (r, s);
+ if (!equal) {
+ test_utils_print_rect (r);
+ g_printf ("%s", " != ");
+ test_utils_print_rect (s);
+
+ }
+ return equal;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]