[gimp] Add a layers test



commit a17f7e0d4f9b925cc6df52065ea41989ed807d47
Author: Michael Natterer <mitch gimp org>
Date:   Mon Sep 7 19:09:48 2009 +0200

    Add a layers test
    
    Contains the add-layers test from the "template" test and also a
    remove-layers one.

 app/tests/Makefile.am   |   10 ++-
 app/tests/test-layers.c |  180 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 187 insertions(+), 3 deletions(-)
---
diff --git a/app/tests/Makefile.am b/app/tests/Makefile.am
index 55512f2..db2d400 100644
--- a/app/tests/Makefile.am
+++ b/app/tests/Makefile.am
@@ -1,8 +1,12 @@
-TESTS = test-layer-grouping
+TESTS = \
+	test-layers		\
+	test-layer-grouping
+
 EXTRA_PROGRAMS = $(TESTS)
 
-test_layer_grouping_SOURCES = \
-	test-layer-grouping.c
+test_layers_SOURCES = test-layers.c
+
+test_layer_grouping_SOURCES = test-layer-grouping.c
 
 libgimpbase = $(top_builddir)/libgimpbase/libgimpbase-$(GIMP_API_VERSION).la
 libgimpconfig = $(top_builddir)/libgimpconfig/libgimpconfig-$(GIMP_API_VERSION).la
diff --git a/app/tests/test-layers.c b/app/tests/test-layers.c
new file mode 100644
index 0000000..a0c4511
--- /dev/null
+++ b/app/tests/test-layers.c
@@ -0,0 +1,180 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 2009 Martin Nordholts
+ *
+ * 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/>.
+ */
+
+#include <gegl.h>
+
+#include "core/core-types.h"
+
+#include "core/gimp.h"
+#include "core/gimpimage.h"
+#include "core/gimplayer.h"
+
+#include "tests.h"
+
+
+#define GIMP_TEST_IMAGE_SIZE 100
+
+
+typedef struct
+{
+  GimpImage *image;
+} GimpTestFixture;
+
+
+static void gimp_test_image_setup    (GimpTestFixture *fixture,
+                                      gconstpointer    data);
+static void gimp_test_image_teardown (GimpTestFixture *fixture,
+                                      gconstpointer    data);
+static void gimp_test_add_layer      (GimpTestFixture *fixture,
+                                      gconstpointer    data);
+static void gimp_test_remove_layer   (GimpTestFixture *fixture,
+                                      gconstpointer    data);
+
+
+static Gimp *gimp = NULL;
+
+
+int
+main (int    argc,
+      char **argv)
+{
+  g_thread_init (NULL);
+  g_type_init ();
+
+  g_test_init (&argc, &argv, NULL);
+
+  /* We share the same application instance across all tests */
+  gimp = gimp_init_for_testing (TRUE);
+
+  /* Setup the tests */
+  g_test_add ("/gimp-layers/add-layer",
+              GimpTestFixture,
+              NULL,
+              gimp_test_image_setup,
+              gimp_test_add_layer,
+              gimp_test_image_teardown);
+
+  g_test_add ("/gimp-layers/remove-layer",
+              GimpTestFixture,
+              NULL,
+              gimp_test_image_setup,
+              gimp_test_remove_layer,
+              gimp_test_image_teardown);
+
+  /* Run the tests and return status */
+  return g_test_run ();
+}
+
+/**
+ * gimp_test_image_setup:
+ * @fixture:
+ * @data:
+ *
+ * Test fixture setup for a single image.
+ **/
+static void
+gimp_test_image_setup (GimpTestFixture *fixture,
+                       gconstpointer    data)
+{
+  fixture->image = gimp_image_new (gimp,
+                                   GIMP_TEST_IMAGE_SIZE,
+                                   GIMP_TEST_IMAGE_SIZE,
+                                   GIMP_RGB);
+}
+
+/**
+ * gimp_test_image_teardown:
+ * @fixture:
+ * @data:
+ *
+ * Test fixture teardown for a single image.
+ **/
+static void
+gimp_test_image_teardown (GimpTestFixture *fixture,
+                          gconstpointer    data)
+{
+  g_object_unref (fixture->image);
+}
+
+/**
+ * gimp_test_add_layer:
+ * @fixture:
+ * @data:
+ *
+ * Super basic test that makes sure we can add a layer.
+ **/
+static void
+gimp_test_add_layer (GimpTestFixture *fixture,
+                     gconstpointer    data)
+{
+  GimpImage *image = fixture->image;
+  GimpLayer *layer = gimp_layer_new (image,
+                                     GIMP_TEST_IMAGE_SIZE,
+                                     GIMP_TEST_IMAGE_SIZE,
+                                     GIMP_RGBA_IMAGE,
+                                     "Test Layer",
+                                     1.0,
+                                     GIMP_NORMAL_MODE);
+
+  g_assert_cmpint (gimp_image_get_n_layers (image), ==, 0);
+
+  gimp_image_add_layer (image,
+                        layer,
+                        GIMP_IMAGE_ACTIVE_PARENT,
+                        0,
+                        FALSE);
+
+  g_assert_cmpint (gimp_image_get_n_layers (image), ==, 1);
+}
+
+/**
+ * gimp_test_remove_layer:
+ * @fixture:
+ * @data:
+ *
+ * Super basic test that makes sure we can remove a layer.
+ **/
+static void
+gimp_test_remove_layer (GimpTestFixture *fixture,
+                        gconstpointer    data)
+{
+  GimpImage *image = fixture->image;
+  GimpLayer *layer = gimp_layer_new (image,
+                                     GIMP_TEST_IMAGE_SIZE,
+                                     GIMP_TEST_IMAGE_SIZE,
+                                     GIMP_RGBA_IMAGE,
+                                     "Test Layer",
+                                     1.0,
+                                     GIMP_NORMAL_MODE);
+
+  g_assert_cmpint (gimp_image_get_n_layers (image), ==, 0);
+
+  gimp_image_add_layer (image,
+                        layer,
+                        GIMP_IMAGE_ACTIVE_PARENT,
+                        0,
+                        FALSE);
+
+  g_assert_cmpint (gimp_image_get_n_layers (image), ==, 1);
+
+  gimp_image_remove_layer (image,
+                           layer,
+                           FALSE,
+                           NULL);
+
+  g_assert_cmpint (gimp_image_get_n_layers (image), ==, 0);
+}



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