[gimp] app/tests: Fix warnings about files not existing



commit 780ebd7c242020bacf632b93dd58c932b3296ec1
Author: Martin Nordholts <martinn src gnome org>
Date:   Thu Dec 24 23:01:48 2009 +0100

    app/tests: Fix warnings about files not existing
    
    Let each test sets GIMP2_DIRECTORY on their own through the help of a
    new test utility function gimp_test_utils_set_gimp2_directory() that
    is compiled into its own lib which tests are then linked with. Also,
    instead of using "/tmp/gimpdir", we use "gimpdir-empty" in the source
    dir. This way we get rid of a bunch of annoying warnings when running
    the tests and have more control.

 app/tests/Makefile.am                        |   12 ++++++-
 app/tests/gimp-app-test-utils.c              |   45 ++++++++++++++++++++++++++
 app/tests/gimp-app-test-utils.h              |   25 ++++++++++++++
 app/tests/gimpdir-empty/.gitignore           |   11 ++++++
 app/tests/gimpdir-empty/tags.xml             |   24 ++++++++++++++
 app/tests/test-layer-grouping.c              |    5 ++-
 app/tests/test-layers.c                      |    5 ++-
 app/tests/test-session-management.c          |   12 ++++++-
 app/tests/test-ui.c                          |    4 ++
 app/tests/test-window-management.c           |    7 ++--
 app/tests/test-xcf.c                         |    4 ++
 11 files changed, 145 insertions(+), 9 deletions(-)
---
diff --git a/app/tests/Makefile.am b/app/tests/Makefile.am
index b0383ee..bd4e9a9 100644
--- a/app/tests/Makefile.am
+++ b/app/tests/Makefile.am
@@ -1,6 +1,8 @@
-# Don't mess with user's dir
+# Don't mess with user's gimpdir. Pass in the abs top srcdir to the
+# tests through an environment variable so they can set the gimpdir
+# they want to use
 TESTS_ENVIRONMENT = \
-	GIMP2_DIRECTORY=$(abs_top_srcdir)/app/tests/gimpdir
+	GIMP_TESTING_ABS_TOP_SRCDIR=$(abs_top_srcdir)
 
 TESTS = \
 	test-layer-grouping	\
@@ -12,6 +14,11 @@ TESTS = \
 
 EXTRA_PROGRAMS = $(TESTS)
 
+noinst_LIBRARIES = libgimpapptestutils.a
+libgimpapptestutils_a_SOURCES = \
+	gimp-app-test-utils.c	\
+	gimp-app-test-utils.h
+
 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
@@ -77,6 +84,7 @@ LDADD = \
 	$(top_builddir)/app/paint-funcs/libapppaint-funcs.a	\
 	$(top_builddir)/app/base/libappbase.a			\
 	$(top_builddir)/app/libapp.a				\
+	libgimpapptestutils.a					\
 	$(libgimpwidgets)					\
 	$(libgimpconfig)					\
 	$(libgimpmath)						\
diff --git a/app/tests/gimp-app-test-utils.c b/app/tests/gimp-app-test-utils.c
new file mode 100644
index 0000000..203f1ab
--- /dev/null
+++ b/app/tests/gimp-app-test-utils.c
@@ -0,0 +1,45 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 2009 Martin Nordholts <martinn src gnome org>
+ *
+ * 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 <glib.h>
+
+#include "gimp-app-test-utils.h"
+
+/**
+ * gimp_test_utils_set_gimp2_directory:
+ * @subdir:
+ *
+ * Sets GIMP2_DIRECTORY to the source dir ./app/tests/@subdir. Make
+ * sure to run it before using any of the GIMP functions.
+ **/
+void
+gimp_test_utils_set_gimp2_directory (const gchar *subdir)
+{
+  gchar *gimpdir = NULL;
+
+  /* GIMP_TESTING_ABS_TOP_SRCDIR is set by the automake test runner,
+   * see Makefile.am
+   */
+  gimpdir = g_build_filename (g_getenv ("GIMP_TESTING_ABS_TOP_SRCDIR"),
+                              "app/tests",
+                              subdir,
+                              NULL);
+
+  g_setenv ("GIMP2_DIRECTORY", gimpdir, TRUE);
+
+  g_free (gimpdir);
+}
diff --git a/app/tests/gimp-app-test-utils.h b/app/tests/gimp-app-test-utils.h
new file mode 100644
index 0000000..75a6b15
--- /dev/null
+++ b/app/tests/gimp-app-test-utils.h
@@ -0,0 +1,25 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 2009 Martin Nordholts <martinn src gnome org>
+ *
+ * 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  __GIMP_RECTANGLE_SELECT_TOOL_H__
+#define  __GIMP_RECTANGLE_SELECT_TOOL_H__
+
+
+void   gimp_test_utils_set_gimp2_directory (const gchar *subdir);
+
+
+#endif /* __GIMP_RECTANGLE_SELECT_TOOL_H__ */
\ No newline at end of file
diff --git a/app/tests/gimpdir-empty/.gitignore b/app/tests/gimpdir-empty/.gitignore
new file mode 100644
index 0000000..fa44da7
--- /dev/null
+++ b/app/tests/gimpdir-empty/.gitignore
@@ -0,0 +1,11 @@
+/colorrc
+/controllerrc
+/dockrc
+/menurc
+/parasiterc
+/pluginrc
+/sessionrc
+/templaterc
+/themerc
+/toolrc
+/unitrc
diff --git a/app/tests/gimpdir-empty/brushes/.gitignore b/app/tests/gimpdir-empty/brushes/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/app/tests/gimpdir-empty/gradients/.gitignore b/app/tests/gimpdir-empty/gradients/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/app/tests/gimpdir-empty/patterns/.gitignore b/app/tests/gimpdir-empty/patterns/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/app/tests/gimpdir-empty/tags.xml b/app/tests/gimpdir-empty/tags.xml
new file mode 100644
index 0000000..3570c4d
--- /dev/null
+++ b/app/tests/gimpdir-empty/tags.xml
@@ -0,0 +1,24 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<tags>
+
+  <resource identifier="gimp-brush-clipboard" checksum="157dcef48665ab465439cfaf10d6feeb">
+  </resource>
+
+  <resource identifier="gimp-pattern-clipboard" checksum="eff9598f9f61c1dc78d842f1798c2ab8">
+  </resource>
+
+  <resource identifier="gimp-gradient-fg-bg-rgb" checksum="12ad9439c57e897e50fb0399439e5b2b">
+  </resource>
+
+  <resource identifier="gimp-gradient-fg-bg-hsv-cw" checksum="86589f70c8a7777c6e2d1d14b99e3759">
+  </resource>
+
+  <resource identifier="gimp-gradient-fg-bg-hsv-ccw" checksum="65aacbbd72d99ff20ca1bd310f0a21a5">
+  </resource>
+
+  <resource identifier="gimp-gradient-fg-bg-rgb" checksum="4a878c6cfae0b0e03c0834723daadf92">
+  </resource>
+
+  <resource identifier="gimp-gradient-fg-transparent" checksum="1491f74caf057a39c8193470da2d2a29">
+  </resource>
+</tags>
diff --git a/app/tests/test-layer-grouping.c b/app/tests/test-layer-grouping.c
index 59010cc..be1e26a 100644
--- a/app/tests/test-layer-grouping.c
+++ b/app/tests/test-layer-grouping.c
@@ -25,6 +25,8 @@
 
 #include "tests.h"
 
+#include "gimp-app-test-utils.h"
+
 
 #define GIMP_TEST_IMAGE_SIZE 100
 
@@ -52,9 +54,10 @@ main (int    argc,
 {
   g_thread_init (NULL);
   g_type_init ();
-
   g_test_init (&argc, &argv, NULL);
 
+  gimp_test_utils_set_gimp2_directory ("gimpdir");
+
   /* We share the same application instance across all tests */
   gimp = gimp_init_for_testing (TRUE);
 
diff --git a/app/tests/test-layers.c b/app/tests/test-layers.c
index 4b42533..9e13858 100644
--- a/app/tests/test-layers.c
+++ b/app/tests/test-layers.c
@@ -25,6 +25,8 @@
 
 #include "tests.h"
 
+#include "gimp-app-test-utils.h"
+
 
 #define GIMP_TEST_IMAGE_SIZE 100
 
@@ -54,9 +56,10 @@ main (int    argc,
 {
   g_thread_init (NULL);
   g_type_init ();
-
   g_test_init (&argc, &argv, NULL);
 
+  gimp_test_utils_set_gimp2_directory ("gimpdir");
+
   /* We share the same application instance across all tests */
   gimp = gimp_init_for_testing (TRUE);
 
diff --git a/app/tests/test-session-management.c b/app/tests/test-session-management.c
index 84de7b4..03fefc6 100644
--- a/app/tests/test-session-management.c
+++ b/app/tests/test-session-management.c
@@ -35,6 +35,8 @@
 
 #include "tests.h"
 
+#include "gimp-app-test-utils.h"
+
 
 typedef struct
 {
@@ -63,13 +65,19 @@ int main(int argc, char **argv)
   GimpTestFileState  initial_dockrc_state    = { NULL, { 0, 0 } };
   GimpTestFileState  final_sessionrc_state   = { NULL, { 0, 0 } };
   GimpTestFileState  final_dockrc_state      = { NULL, { 0, 0 } };
-  gchar             *sessionrc_filename      = gimp_personal_rc_file ("sessionrc");
-  gchar             *dockrc_filename         = gimp_personal_rc_file ("dockrc");
+  gchar             *sessionrc_filename      = NULL;
+  gchar             *dockrc_filename         = NULL;
 
   g_type_init ();
   gtk_init (&argc, &argv);
   g_test_init (&argc, &argv, NULL);
 
+  /* Make sure to run this before we use any GIMP functions */
+  gimp_test_utils_set_gimp2_directory ("gimpdir");
+
+  sessionrc_filename = gimp_personal_rc_file ("sessionrc");
+  dockrc_filename    = gimp_personal_rc_file ("dockrc");
+
   /* Remeber the modtimes and MD5s */
   if (!gimp_test_get_file_state_verbose (sessionrc_filename,
                                          &initial_sessionrc_state))
diff --git a/app/tests/test-ui.c b/app/tests/test-ui.c
index 9011ddb..023a79d 100644
--- a/app/tests/test-ui.c
+++ b/app/tests/test-ui.c
@@ -40,6 +40,8 @@
 
 #include "tests.h"
 
+#include "gimp-app-test-utils.h"
+
 
 typedef struct
 {
@@ -65,6 +67,8 @@ int main(int argc, char **argv)
   gtk_init (&argc, &argv);
   g_test_init (&argc, &argv, NULL);
 
+  gimp_test_utils_set_gimp2_directory ("gimpdir");
+
   /* Start up GIMP */
   gimp = gimp_init_for_gui_testing (FALSE, TRUE);
   gimp_test_run_mainloop_until_idle ();
diff --git a/app/tests/test-window-management.c b/app/tests/test-window-management.c
index 9b9292d..45dde24 100644
--- a/app/tests/test-window-management.c
+++ b/app/tests/test-window-management.c
@@ -31,6 +31,8 @@
 
 #include "tests.h"
 
+#include "gimp-app-test-utils.h"
+
 
 typedef struct
 {
@@ -49,13 +51,12 @@ int main(int argc, char **argv)
 {
   int test_result;
 
-  /* Disable the user dir for this test */
-  g_setenv ("GIMP2_DIRECTORY", "/tmp/gimpdir", TRUE);
-
   g_type_init ();
   gtk_init (&argc, &argv);
   g_test_init (&argc, &argv, NULL);
 
+  gimp_test_utils_set_gimp2_directory ("gimpdir-empty");
+
   /* We share the same application instance across all tests */
   gimp = gimp_init_for_gui_testing (FALSE, FALSE);
 
diff --git a/app/tests/test-xcf.c b/app/tests/test-xcf.c
index fd07041..a27c846 100644
--- a/app/tests/test-xcf.c
+++ b/app/tests/test-xcf.c
@@ -42,6 +42,8 @@
 
 #include "tests.h"
 
+#include "gimp-app-test-utils.h"
+
 
 #define GIMP_MAINIMAGE_WIDTH           100
 #define GIMP_MAINIMAGE_HEIGHT          90
@@ -429,6 +431,8 @@ main (int    argc,
   gtk_init (&argc, &argv);
   g_test_init (&argc, &argv, NULL);
 
+  gimp_test_utils_set_gimp2_directory ("gimpdir");
+
   /* We share the same application instance across all tests. We need
    * the GUI variant for the file procs
    */



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