gegl r2952 - in trunk: . tests



Author: martinn
Date: Sun Mar  1 09:38:10 2009
New Revision: 2952
URL: http://svn.gnome.org/viewvc/gegl?rev=2952&view=rev

Log:
Add a simple tests case to ensure processing and caching sanity

Add a simple tests case to ensure processing and caching sanity. The
test case constructs a simple graph, processes it, checks the result,
changes input, processes again and finally checks the result a second
time. This test will immediately catch severe regressions.

Added:
   trunk/tests/.gitignore
   trunk/tests/Makefile.am
   trunk/tests/test-proxynop-processing.c
Modified:
   trunk/ChangeLog
   trunk/Makefile.am
   trunk/configure.ac

Modified: trunk/Makefile.am
==============================================================================
--- trunk/Makefile.am	(original)
+++ trunk/Makefile.am	Sun Mar  1 09:38:10 2009
@@ -5,7 +5,8 @@
 	operations \
 	bin \
 	tools \
-	examples
+	examples \
+	tests
 
 if ENABLE_DOCS
 SUBDIRS+= docs

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Sun Mar  1 09:38:10 2009
@@ -987,6 +987,7 @@
 docs/gallery/data/Makefile
 examples/Makefile
 examples/data/Makefile
+tests/Makefile
 gegl.pc
 gegl-uninstalled.pc
 ])

Added: trunk/tests/.gitignore
==============================================================================
--- (empty file)
+++ trunk/tests/.gitignore	Sun Mar  1 09:38:10 2009
@@ -0,0 +1,7 @@
+/Makefile
+/Makefile.in
+/.deps
+/.libs
+/*.lo
+/*.la
+/test-proxynop-processing*
\ No newline at end of file

Added: trunk/tests/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/tests/Makefile.am	Sun Mar  1 09:38:10 2009
@@ -0,0 +1,20 @@
+TESTS = \
+	test-proxynop-processing$(EXEEXT)
+
+test_proxynop_processing_SOURCES = \
+	test-proxynop-processing.c
+
+test_proxynop_processing_CPPFLAGS = \
+	-I$(top_srcdir)				\
+	-I$(top_srcdir)/gegl/			\
+	-I$(top_srcdir)/gegl/buffer		\
+	-I$(top_srcdir)/gegl/property-types	\
+	-I$(top_srcdir)/gegl/operation		\
+	@DEP_CFLAGS@ @BABL_CFLAGS@
+
+test_proxynop_processing_LDADD = \
+	$(top_srcdir)/gegl/libgegl- GEGL_API_VERSION@.la \
+	@DEP_LIBS@ @BABL_LIBS@
+
+EXTRA_PROGRAMS = \
+	$(TESTS)

Added: trunk/tests/test-proxynop-processing.c
==============================================================================
--- (empty file)
+++ trunk/tests/test-proxynop-processing.c	Sun Mar  1 09:38:10 2009
@@ -0,0 +1,120 @@
+/*
+ * 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 "gegl.h"
+
+#define RED      0
+#define GREEN    1
+#define BLUE     2
+
+#define SUCCESS  0
+#define FAILURE -1
+
+int main(int argc, char *argv[])
+{
+  int           result             = SUCCESS;
+  GeglNode     *graph              = NULL;
+  GeglNode     *color_in_graph     = NULL;
+  GeglNode     *crop_in_graph      = NULL;
+  GeglNode     *graph_output_proxy = NULL;
+  GeglRectangle roi                = { 0, 0, 1, 1 };
+  guchar        result_buffer[3]   = { 0, 0, 0 };
+  GeglColor    *color1             = NULL;
+  GeglColor    *color2             = NULL;
+
+  /* Init */
+  gegl_init (&argc, &argv);
+
+  color1 = gegl_color_new ("rgb(1.0, 0.0, 1.0)");
+  color2 = gegl_color_new ("rgb(0.0, 0.0, 1.0)");
+
+  /* Construct graph */
+  graph          = gegl_node_new ();
+  color_in_graph = gegl_node_new_child (graph,
+                                        "operation", "gegl:color",
+                                        "value",     color1,
+                                        NULL);
+  crop_in_graph  = gegl_node_new_child (graph,
+                                        "operation", "gegl:crop",
+                                        "x",         0.0,
+                                        "y",         0.0,
+                                        "width",     1.0,
+                                        "height",    1.0,
+                                        NULL);
+  graph_output_proxy = gegl_node_get_output_proxy (graph,
+                                                   "output");
+  gegl_node_link_many (color_in_graph,
+                       crop_in_graph,
+                       graph_output_proxy,
+                       NULL);
+
+  /* Process the graph and make sure we get the expected result */
+  gegl_node_blit (graph_output_proxy,
+                  1.0,
+                  &roi,
+                  babl_format ("RGB u8"),
+                  result_buffer,
+                  GEGL_AUTO_ROWSTRIDE,
+                  GEGL_BLIT_DEFAULT);
+  if (result_buffer[RED]   == 255 &&
+      result_buffer[GREEN] == 0   &&
+      result_buffer[BLUE]  == 255)
+    {
+      result = SUCCESS;
+    }
+  else
+    {
+      result = FAILURE;
+      g_printerr ("Initial processing failed, you messed up GEGL pretty badly :(");
+      goto abort;
+    }
+
+  /* Process the graph AGAIN and make sure we get the expected result
+   * as this puts some stress on the caching mechanisms
+   */
+  gegl_node_set (color_in_graph,
+                 "value", color2,
+                 NULL);
+  gegl_node_blit (graph_output_proxy,
+                  1.0,
+                  &roi,
+                  babl_format ("RGB u8"),
+                  result_buffer,
+                  GEGL_AUTO_ROWSTRIDE,
+                  GEGL_BLIT_DEFAULT);
+  if (result_buffer[RED]   == 0   &&
+      result_buffer[GREEN] == 0   &&
+      result_buffer[BLUE]  == 255)
+    {
+      result = SUCCESS;
+    }
+  else
+    {
+      result = FAILURE;
+      g_printerr ("Second processing failed, looks like you messed up caching. Fix!");
+      goto abort;
+    }
+
+abort:
+  /* Cleanup */
+  g_object_unref (graph);
+  g_object_unref (color1);
+  g_object_unref (color2);
+  gegl_exit ();
+
+  return result;
+}



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