Commit 14aa5314 authored by Martin Nordholts's avatar Martin Nordholts

app: Add GIMP core unit testing framework and a simple first test

Enable us to have regression testing by introducing a core testing
framework that uses the GLib JUnit-like test library.

Do this by adding a new subdir app/tests that will contain all our
tests (it contains one trivial test already). Also add app/tests.[ch]
with a new function gimp_init_for_testing() so that test cases can
easily setup the core object system.
parent df9e9e26
......@@ -11,6 +11,7 @@ libgimpthumb = $(top_builddir)/libgimpthumb/libgimpthumb-$(GIMP_API_VERSION).la
# Sort this by architectural depenendencies
SUBDIRS = \
tests \
gui \
menus \
actions \
......@@ -51,6 +52,8 @@ app_sources = \
sanity.h \
signals.c \
signals.h \
tests.c \
tests.h \
unique.c \
unique.h \
units.c \
......
/* 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 "config.h"
#include <glib-object.h>
#include "core/core-types.h"
#include "core/gimp.h"
#include "tests.h"
#include "units.h"
/**
* gimp_init_for_testing:
*
* Initialize the GIMP object system for unit testing. This is a
* selected subset of the initialization happning in app_run().
**/
Gimp *
gimp_init_for_testing (void)
{
Gimp *gimp = gimp_new ("Unit Tested GIMP", NULL, TRUE, TRUE, TRUE, TRUE,
FALSE, TRUE, TRUE, FALSE);
units_init (gimp);
gimp_load_config (gimp, NULL, NULL);
return gimp;
}
/* 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/>.
*/
#ifndef __TESTS_H__
#define __TESTS_H__
Gimp * gimp_init_for_testing (void);
#endif /* __TESTS_H__ */
/.deps
/Makefile
/Makefile.in
TESTS = test-layer-grouping
EXTRA_PROGRAMS = $(TESTS)
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
libgimpcolor = $(top_builddir)/libgimpcolor/libgimpcolor-$(GIMP_API_VERSION).la
libgimpmath = $(top_builddir)/libgimpmath/libgimpmath-$(GIMP_API_VERSION).la
libgimpmodule = $(top_builddir)/libgimpmodule/libgimpmodule-$(GIMP_API_VERSION).la
libgimpwidgets = $(top_builddir)/libgimpwidgets/libgimpwidgets-$(GIMP_API_VERSION).la
libgimpthumb = $(top_builddir)/libgimpthumb/libgimpthumb-$(GIMP_API_VERSION).la
AM_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/app \
$(PANGOCAIRO_CFLAGS) \
$(GDK_PIXBUF_CFLAGS) \
$(GEGL_CFLAGS) \
-I$(includedir)
# We need this due to circular dependencies, see more detailed
# comments about it in app/Makefile.am
AM_LDFLAGS = \
-u $(SYMPREFIX)xcf_init \
-u $(SYMPREFIX)internal_procs_init \
-u $(SYMPREFIX)gimp_plug_in_manager_restore \
-u $(SYMPREFIX)gimp_pdb_compat_param_spec \
-u $(SYMPREFIX)plug_in_icc_profile_apply_rgb \
-u $(SYMPREFIX)gimp_image_map_config_get_type \
-u $(SYMPREFIX)gimp_vectors_undo_get_type \
-u $(SYMPREFIX)gimp_vectors_mod_undo_get_type \
-u $(SYMPREFIX)gimp_vectors_prop_undo_get_type \
-u $(SYMPREFIX)gimp_curve_map_pixels
LDADD = \
$(top_builddir)/app/display/libappdisplay.a \
$(top_builddir)/app/widgets/widgets-enums.o \
$(top_builddir)/app/xcf/libappxcf.a \
$(top_builddir)/app/pdb/libappinternal-procs.a \
$(top_builddir)/app/pdb/libapppdb.a \
$(top_builddir)/app/plug-in/libappplug-in.a \
$(top_builddir)/app/vectors/libappvectors.a \
$(top_builddir)/app/core/libappcore.a \
$(top_builddir)/app/file/libappfile.a \
$(top_builddir)/app/text/libapptext.a \
$(top_builddir)/app/paint/libapppaint.a \
$(top_builddir)/app/composite/libappcomposite.a \
$(top_builddir)/app/gegl/libappgegl.a \
$(top_builddir)/app/config/libappconfig.a \
$(top_builddir)/app/display/libappdisplay.a \
$(top_builddir)/app/paint-funcs/libapppaint-funcs.a \
$(top_builddir)/app/base/libappbase.a \
$(top_builddir)/app/gimp-log.o \
$(top_builddir)/app/tests.o \
$(top_builddir)/app/units.o \
$(libgimpconfig) \
$(libgimpmath) \
$(libgimpthumb) \
$(libgimpcolor) \
$(libgimpmodule) \
$(libgimpbase) \
$(GIMPICONRC) \
$(GDK_PIXBUF_LIBS) \
$(FREETYPE_LIBS) \
$(FONTCONFIG_LIBS) \
$(PANGOCAIRO_LIBS) \
$(CAIRO_LIBS) \
$(GEGL_LIBS) \
$(GLIB_LIBS) \
$(INTLLIBS) \
$(RT_LIBS)
/* 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 Gimp *gimp = NULL;
int main(int argc, char **argv)
{
g_type_init ();
g_test_init (&argc, &argv, NULL);
/* We share the same application instance across all tests */
gimp = gimp_init_for_testing ();
/* Setup the tests */
g_test_add ("/gimp-layer-grouping/add-layer",
GimpTestFixture,
NULL,
gimp_test_image_setup,
gimp_test_add_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);
}
......@@ -1979,6 +1979,7 @@ app/tools/Makefile
app/vectors/Makefile
app/widgets/Makefile
app/xcf/Makefile
app/tests/Makefile
plug-ins/Makefile
plug-ins/color-rotate/Makefile
plug-ins/color-rotate/images/Makefile
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment