[gegl-gtk] Tests: Put setup/teardown code in separate functions
- From: Jon Nordby <jonnor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl-gtk] Tests: Put setup/teardown code in separate functions
- Date: Thu, 21 Jul 2011 19:49:49 +0000 (UTC)
commit 867889c0699caac063f4243d9d046effab35767f
Author: Jon Nordby <jononor gmail com>
Date: Thu Jul 21 21:08:47 2011 +0200
Tests: Put setup/teardown code in separate functions
tests/test-view.c | 72 +++++++++++++++++++++++++++++++++++-----------------
1 files changed, 48 insertions(+), 24 deletions(-)
---
diff --git a/tests/test-view.c b/tests/test-view.c
index af4c079..722af9a 100644
--- a/tests/test-view.c
+++ b/tests/test-view.c
@@ -5,47 +5,71 @@
#include <gegl.h>
static gboolean
-quit_gtk_main (gpointer data)
+test_utils_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) {
-
+/* Stores the state used in widget tests.*/
+typedef struct {
GtkWidget *window, *view;
- GeglNode *gegl, *out, *loadbuf;
+ GeglNode *graph, *out, *loadbuf;
GeglBuffer *buffer;
+} ViewWidgetTest;
+
+static void
+setup_widget_test (ViewWidgetTest *test)
+{
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);
+ /* 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 widget, and a window for it */
+ test->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ test->view = GTK_WIDGET (g_object_new (GEGL_GTK_TYPE_VIEW, "node", test->out, NULL));
+ gtk_container_add (GTK_CONTAINER (test->window), test->view);
+ gtk_widget_set_size_request (test->view, rect.width, rect.height);
+ gtk_widget_show_all (test->window);
+}
- 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);
+static void
+teardown_widget_test (ViewWidgetTest *test)
+{
+ g_object_unref (test->graph);
+ gegl_buffer_destroy (test->buffer);
+ gtk_widget_destroy (test->window);
+}
+
+/* Test that instantiating the widget and hooking up a gegl graph
+ * does not cause any crashes, criticals or warnings. */
+static void
+test_sanity (void)
+{
+ ViewWidgetTest test;
- 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);
+ setup_widget_test(&test);
// XXX: Better to do on/after expose event instead?
- g_timeout_add(300, quit_gtk_main, NULL);
+ g_timeout_add(300, test_utils_quit_gtk_main, NULL);
gtk_main ();
- g_object_unref (gegl);
- gegl_buffer_destroy (buffer);
- gtk_widget_destroy (window);
+ teardown_widget_test(&test);
}
+
/* TODO:
* - Test redraw logic
* - Test redraw with translation
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]