[gegl] tests: Add test case for changing GeglProcessor rect



commit 5811d4f55ea45c90bc27d05908a86b6cd17b0a54
Author: Martin Nordholts <martinn src gnome org>
Date:   Fri Jun 26 07:32:29 2009 +0200

    tests: Add test case for changing GeglProcessor rect
    
    Add test case for changing GeglProcessor processing rect that fails
    without the recent GeglProcessor commits.

 tests/.gitignore                   |    3 +-
 tests/Makefile.am                  |    3 +-
 tests/test-change-processor-rect.c |  148 ++++++++++++++++++++++++++++++++++++
 3 files changed, 152 insertions(+), 2 deletions(-)
---
diff --git a/tests/.gitignore b/tests/.gitignore
index 4857fb1..041e596 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -4,6 +4,7 @@
 /.libs
 /Makefile
 /Makefile.in
+/test-change-processor-rect*
+/test-color-op*
 /test-gegl-rectangle*
 /test-proxynop-processing*
-/test-color-op*
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4f37afe..acc4dce 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,10 +2,11 @@ SUBDIRS = buffer
 
 # Make the tests run against the build and not the installation
 TESTS_ENVIRONMENT = \
-	GEGL_PATH=$(top_builddir)/operations/common:$(top_builddir)/operations/core
+	GEGL_PATH=$(top_builddir)/operations/common:$(top_builddir)/operations/core:$(top_builddir)/operations/external:$(top_builddir)/operations/affine:$(top_builddir)/operations/generated
 
 # The tests
 TESTS = \
+	test-change-processor-rect	\
 	test-proxynop-processing	\
 	test-color-op			\
 	test-gegl-rectangle
diff --git a/tests/test-change-processor-rect.c b/tests/test-change-processor-rect.c
new file mode 100644
index 0000000..50936f7
--- /dev/null
+++ b/tests/test-change-processor-rect.c
@@ -0,0 +1,148 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2009 Martin Nordholts
+ */
+
+#include "config.h"
+#include <string.h>
+
+#include "gegl.h"
+
+#define SUCCESS  0
+#define FAILURE -1
+
+static gboolean
+test_change_processor_rect_do_test (GeglProcessor       *processor,
+                                    const GeglRectangle *rect,
+                                    GeglNode            *sink)
+{
+  gboolean    result                    = FALSE;
+  float       expected_result_buffer[4] = { 1.0, 1.0, 1.0, 1.0 };
+  float       result_buffer[4]          = { 0, };
+  GeglBuffer *buffer                    = NULL;
+
+  gegl_node_set (sink,
+                 "buffer", &buffer,
+                 NULL);
+  
+  gegl_processor_set_rectangle (processor, rect);
+
+  while (gegl_processor_work (processor, NULL));
+
+  gegl_buffer_get (buffer,
+                   1.0,
+                   rect,
+                   babl_format ("RGBA float"),
+                   result_buffer,
+                   GEGL_AUTO_ROWSTRIDE);
+
+  result = memcmp (result_buffer, expected_result_buffer, sizeof (expected_result_buffer)) == 0;
+
+  gegl_node_set (sink,
+                 "buffer", NULL,
+                 NULL);
+
+  gegl_buffer_destroy (buffer);
+
+  return result;
+}
+
+int main(int argc, char *argv[])
+{
+  gint           result       = SUCCESS;
+  GeglRectangle  rect1        = { 0, 0, 1, 1 };
+  GeglRectangle  rect2        = { 1, 0, 1, 1 };
+  GeglRectangle  rect3        = { 1, 1, 1, 1 };
+  GeglRectangle  rect4        = { 0, 1, 1, 1 };
+  GeglColor     *common_color = NULL;
+  GeglNode      *gegl         = NULL;
+  GeglNode      *color        = NULL;
+  GeglNode      *layer        = NULL;
+  GeglNode      *text         = NULL;
+  GeglNode      *sink         = NULL;
+  GeglProcessor *processor    = NULL;
+
+  /* Convenient line to keep around:
+  g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
+   */
+
+  gegl_init (&argc, &argv);
+
+  common_color = gegl_color_new ("rgb(1.0, 1.0, 1.0)");
+
+  gegl         = gegl_node_new ();
+  color        = gegl_node_new_child (gegl,
+                                      "operation", "gegl:color",
+                                      "value", common_color,
+                                      NULL);
+  layer        = gegl_node_new_child (gegl,
+                                      "operation", "gegl:layer",
+                                      "x", 0.0,
+                                      "y", 0.0,
+                                      NULL);
+  text         = gegl_node_new_child (gegl,
+                                      "operation", "gegl:text",
+                                      "color", common_color,
+                                      "string", "â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??",
+                                      "size", 200.0,
+                                      NULL);
+  sink         = gegl_node_new_child (gegl,
+                                      "operation", "gegl:buffer-sink",
+                                      NULL);
+
+  /* We build our graph for processing complexity, not for compositing
+   * complexity
+   */
+  gegl_node_link_many (color, layer, sink, NULL);
+  gegl_node_connect_to (text, "output",  layer, "aux");
+
+  /* Create a processor */
+  processor = gegl_node_new_processor (sink, NULL);
+
+  /* Do the tests */
+  if (!test_change_processor_rect_do_test (processor, &rect1, sink))
+    {
+      g_printerr ("test-change-processor-rect: First compare failed\n");
+      result = FAILURE;
+      goto abort;
+    }
+  if (!test_change_processor_rect_do_test (processor, &rect2, sink))
+    {
+      g_printerr ("test-change-processor-rect: Second compare failed\n");
+      result = FAILURE;
+      goto abort;
+    }
+  if (!test_change_processor_rect_do_test (processor, &rect3, sink))
+    {
+      g_printerr ("test-change-processor-rect: Third compare failed\n");
+      result = FAILURE;
+      goto abort;
+    }
+  if (!test_change_processor_rect_do_test (processor, &rect4, sink))
+    {
+      g_printerr ("test-change-processor-rect: Fourth compare failed\n");
+      result = FAILURE;
+      goto abort;
+    }
+
+  /* Cleanup */
+ abort:
+  g_object_unref (processor);
+  g_object_unref (common_color);
+  g_object_unref (gegl);
+  gegl_exit ();
+
+  return result;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]