[gimp] app: Have separate output gimpdir for test cases



commit 3612ef2d7656f45b91e5cd15b4b1bf90c5413fc1
Author: Martin Nordholts <martinn src gnome org>
Date:   Fri Jan 29 18:31:55 2010 +0100

    app: Have separate output gimpdir for test cases
    
    Make our test cases write gimpdir files in a dedicate output directory
    by changing GIMP2_DIRECTORY at runtime. This ends the writing to the
    source directory which make distcheck doesn't like, and it also allows
    us to have a separate expected sessionrc for the session management
    test. In that test we load a GIMP 2.6 formated sessionrc but write one
    updated for 2.8.
    
    We perform this change by passing the builddir through an environment
    variable to the test cases. The patch also does some generalizations
    in gimp-app-test-utils.c and adapts test cases accordingly.
    
    Also do an adjustment in sessionrc on the toolbox size since
    GIMP/GTK+/X/whatever has a tendency to adjust that during runs. The
    new size is stable for the moment.

 app/tests/.gitignore                 |    1 +
 app/tests/Makefile.am                |   15 +++++-
 app/tests/gimp-app-test-utils.c      |   70 +++++++++++-------------
 app/tests/gimp-app-test-utils.h      |    7 +--
 app/tests/gimpdir/sessionrc          |    2 +-
 app/tests/gimpdir/sessionrc-expected |   97 ++++++++++++++++++++++++++++++++++
 app/tests/test-layer-grouping.c      |    2 +-
 app/tests/test-layers.c              |    2 +-
 app/tests/test-session-management.c  |   24 +++++++--
 app/tests/test-ui.c                  |    5 ++-
 app/tests/test-window-management.c   |    5 ++-
 app/tests/test-xcf.c                 |    5 ++-
 12 files changed, 181 insertions(+), 54 deletions(-)
---
diff --git a/app/tests/.gitignore b/app/tests/.gitignore
index 3135e4f..71c7b6c 100644
--- a/app/tests/.gitignore
+++ b/app/tests/.gitignore
@@ -1,5 +1,6 @@
 .deps
 .libs
+/gimpdir-output
 Makefile
 Makefile.in
 libgimpapptestutils.a
diff --git a/app/tests/Makefile.am b/app/tests/Makefile.am
index 307e368..4cfe9a0 100644
--- a/app/tests/Makefile.am
+++ b/app/tests/Makefile.am
@@ -7,7 +7,8 @@ SUBDIRS = \
 # tests through an environment variable so they can set the gimpdir
 # they want to use
 TESTS_ENVIRONMENT = \
-	GIMP_TESTING_ABS_TOP_SRCDIR=$(abs_top_srcdir)
+	GIMP_TESTING_ABS_TOP_SRCDIR=$(abs_top_srcdir) \
+	GIMP_TESTING_ABS_TOP_BUILDDIR=$(abs_top_builddir)
 
 TESTS = \
 	test-layer-grouping	\
@@ -17,6 +18,7 @@ TESTS = \
 	test-window-management	\
 	test-xcf
 
+
 EXTRA_PROGRAMS = $(TESTS)
 
 noinst_LIBRARIES = libgimpapptestutils.a
@@ -110,3 +112,14 @@ LDADD = \
 	$(INTLLIBS)						\
 	$(RT_LIBS)
 
+check-local:
+	@mkdir -p gimpdir-output
+	@mkdir -p gimpdir-output/brushes
+	@mkdir -p gimpdir-output/patterns
+	@mkdir -p gimpdir-output/gradients
+
+clean-local:
+	@rm -rf gimpdir-output
+	@rm -rf gimpdir-output/brushes
+	@rm -rf gimpdir-output/patterns
+	@rm -rf gimpdir-output/gradients
diff --git a/app/tests/gimp-app-test-utils.c b/app/tests/gimp-app-test-utils.c
index 7b06129..8c08164 100644
--- a/app/tests/gimp-app-test-utils.c
+++ b/app/tests/gimp-app-test-utils.c
@@ -19,9 +19,34 @@
 
 #include "gimp-app-test-utils.h"
 
+
+static void
+gimp_test_utils_set_env_to_subdir (const gchar *root_env_var,
+                                   const gchar *subdir,
+                                   const gchar *target_env_var)
+{
+  const gchar *root_dir   = NULL;
+  gchar       *target_dir = NULL;
+
+  /* Get root dir */
+  root_dir = g_getenv (root_env_var);
+  if (! root_dir)
+    g_printerr ("The env var %s is not set, you are probably running\n"
+                "in a debugger. Set it manually, e.g.:\n"
+                "set env %s=%s/source/gimp\n",
+                root_env_var,
+                root_env_var, g_get_home_dir ());
+
+  /* Construct path and setup target env var */
+  target_dir = g_build_filename (root_dir, subdir, NULL);
+  g_setenv (target_env_var, target_dir, TRUE);
+  g_free (target_dir);
+}
+
+
 /**
  * gimp_test_utils_set_gimp2_directory:
- * @subdir:
+ * @subdir: Subdir, may be %NULL
  *
  * Sets GIMP2_DIRECTORY to the source dir ./app/tests/@subdir. Make
  * sure to run it before using any of the GIMP functions.
@@ -29,19 +54,12 @@
 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);
+  gimp_test_utils_set_env_to_subdir ("GIMP_TESTING_ABS_TOP_SRCDIR" /*root_env_var*/,
+                                     subdir,
+                                     "GIMP2_DIRECTORY" /*target_env_var*/);
 }
 
 /**
@@ -52,34 +70,10 @@ gimp_test_utils_set_gimp2_directory (const gchar *subdir)
 void
 gimp_test_utils_setup_menus_dir (void)
 {
-  gchar *menus_dir = NULL;
-
-  menus_dir = gimp_test_utils_get_source_subdir ("menus");
-
-  g_setenv ("GIMP_TESTING_MENUS_DIR", menus_dir, TRUE);
-
-  g_free (menus_dir);
-}
-
-/**
- * gimp_test_utils_get_source_subdir:
- * @subdir:
- *
- * Returns: The source directory $top_srcdir/@subdir.
- **/
-gchar *
-gimp_test_utils_get_source_subdir (const gchar *subdir)
-{
-  const gchar *abs_top_srcdir = g_getenv ("GIMP_TESTING_ABS_TOP_SRCDIR");
-
-  if (! abs_top_srcdir)
-    g_printerr ("The env var GIMP_TESTING_ABS_TOP_SRCDIR is not set, you are probably\n"
-                "running in a debugger. Set it manually to e.g. ~/source/gimp");
-
   /* GIMP_TESTING_ABS_TOP_SRCDIR is set by the automake test runner,
    * see Makefile.am
    */
-  return g_build_filename (g_getenv ("GIMP_TESTING_ABS_TOP_SRCDIR"),
-                           subdir,
-                           NULL);
+  gimp_test_utils_set_env_to_subdir ("GIMP_TESTING_ABS_TOP_SRCDIR" /*root_env_var*/,
+                                     "menus" /*subdir*/,
+                                     "GIMP_TESTING_MENUS_DIR" /*target_env_var*/);
 }
diff --git a/app/tests/gimp-app-test-utils.h b/app/tests/gimp-app-test-utils.h
index 0fa33f9..8af81cf 100644
--- a/app/tests/gimp-app-test-utils.h
+++ b/app/tests/gimp-app-test-utils.h
@@ -19,9 +19,8 @@
 #define  __GIMP_RECTANGLE_SELECT_TOOL_H__
 
 
-void    gimp_test_utils_set_gimp2_directory (const gchar *subdir);
-void    gimp_test_utils_setup_menus_dir     (void);
-gchar * gimp_test_utils_get_source_subdir   (const gchar *subdir);
+void  gimp_test_utils_set_gimp2_directory (const gchar *subdir);
+void  gimp_test_utils_setup_menus_dir     (void);
 
 
-#endif /* __GIMP_RECTANGLE_SELECT_TOOL_H__ */
\ No newline at end of file
+#endif /* __GIMP_RECTANGLE_SELECT_TOOL_H__ */
diff --git a/app/tests/gimpdir/sessionrc b/app/tests/gimpdir/sessionrc
index a58f5a4..9aa29d5 100644
--- a/app/tests/gimpdir/sessionrc
+++ b/app/tests/gimpdir/sessionrc
@@ -80,7 +80,7 @@
                     (zoom-factor "2.80"))))))
 (session-info "toolbox" "dock"
     (position 13 37)
-    (size 102 520)
+    (size 96 620)
     (open-on-exit)
     (dock))
 (session-info "toplevel" "gimp-file-open-dialog"
diff --git a/app/tests/gimpdir/sessionrc-expected b/app/tests/gimpdir/sessionrc-expected
new file mode 100644
index 0000000..2b83a24
--- /dev/null
+++ b/app/tests/gimpdir/sessionrc-expected
@@ -0,0 +1,97 @@
+# GIMP sessionrc
+# 
+# This file takes session-specific info (that is info, you want to keep
+# between two GIMP sessions).  You are not supposed to edit it manually, but
+# of course you can do.  The sessionrc will be entirely rewritten every time
+# you quit GIMP.  If this file isn't found, defaults are used.
+
+(session-info "dock" "gimp-dock-window"
+    (position 566 171)
+    (size 210 535)
+    (open-on-exit)
+    (aux-info
+        (show-image-menu "false")
+        (follow-active-image "true"))
+    (gimp-dock
+        (book
+            (current-page 1)
+            (dockable "gimp-layer-list"
+                (tab-style icon)
+                (preview-size 32))
+            (dockable "gimp-undo-history"
+                (tab-style icon)))
+        (book
+            (position 289)
+            (current-page 0)
+            (dockable "gimp-brush-grid"
+                (tab-style preview)))))
+(session-info "dock" "gimp-dock-window"
+    (position 141 291)
+    (size 406 300)
+    (open-on-exit)
+    (aux-info
+        (show-image-menu "false")
+        (follow-active-image "true"))
+    (gimp-dock
+        (book
+            (current-page 0)
+            (dockable "gimp-tool-options"
+                (tab-style icon))))
+    (gimp-dock
+        (book
+            (current-page 0)
+            (dockable "gimp-device-status"
+                (tab-style icon)))))
+(session-info "dock" "gimp-dock-window"
+    (position 795 43)
+    (size 200 265)
+    (open-on-exit)
+    (aux-info
+        (show-image-menu "true")
+        (follow-active-image "true"))
+    (gimp-dock
+        (book
+            (current-page 1)
+            (dockable "gimp-pattern-grid"
+                (tab-style preview))
+            (dockable "gimp-gradient-list"
+                (tab-style preview)))))
+(session-info "dock" "gimp-dock-window"
+    (position 803 344)
+    (size 200 404)
+    (open-on-exit)
+    (aux-info
+        (show-image-menu "true")
+        (follow-active-image "true"))
+    (gimp-dock
+        (book
+            (current-page 0)
+            (dockable "gimp-channel-list"
+                (tab-style icon)
+                (preview-size 32)))
+        (book
+            (position 162)
+            (current-page 0)
+            (dockable "gimp-palette-editor"
+                (tab-style icon)
+                (aux-info
+                    (edit-active "true")
+                    (current-data "Standard")
+                    (zoom-factor "2.80"))))))
+(session-info "dock" "gimp-toolbox-window"
+    (position 13 37)
+    (size 96 620)
+    (open-on-exit)
+    (gimp-toolbox))
+(session-info "toplevel" "gimp-file-open-dialog"
+    (position 392 140)
+    (size 902 816))
+(session-info "toplevel" "gimp-image-new-dialog"
+    (position 100 100))
+(session-info "display" "gimp-empty-image-window"
+    (position 140 32)
+    (size 610 190))
+
+(last-tip-shown 0)
+
+# end of sessionrc
diff --git a/app/tests/test-layer-grouping.c b/app/tests/test-layer-grouping.c
index be1e26a..f30abfb 100644
--- a/app/tests/test-layer-grouping.c
+++ b/app/tests/test-layer-grouping.c
@@ -56,7 +56,7 @@ main (int    argc,
   g_type_init ();
   g_test_init (&argc, &argv, NULL);
 
-  gimp_test_utils_set_gimp2_directory ("gimpdir");
+  gimp_test_utils_set_gimp2_directory ("app/tests/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 9e13858..300fea5 100644
--- a/app/tests/test-layers.c
+++ b/app/tests/test-layers.c
@@ -58,7 +58,7 @@ main (int    argc,
   g_type_init ();
   g_test_init (&argc, &argv, NULL);
 
-  gimp_test_utils_set_gimp2_directory ("gimpdir");
+  gimp_test_utils_set_gimp2_directory ("app/tests/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 05e5ee9..c7e3380 100644
--- a/app/tests/test-session-management.c
+++ b/app/tests/test-session-management.c
@@ -73,10 +73,14 @@ int main(int argc, char **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");
+  gimp_test_utils_set_gimp2_directory ("app/tests/gimpdir");
   gimp_test_utils_setup_menus_dir ();
 
-  sessionrc_filename = gimp_personal_rc_file ("sessionrc");
+  /* Note that we expect the resulting sessionrc to be different from
+   * the read file, which is why we check the MD5 of the -expected
+   * variant
+   */
+  sessionrc_filename = gimp_personal_rc_file ("sessionrc-expected");
   dockrc_filename    = gimp_personal_rc_file ("dockrc");
 
   /* Remeber the modtimes and MD5s */
@@ -90,12 +94,22 @@ int main(int argc, char **argv)
   /* Start up GIMP */
   gimp = gimp_init_for_gui_testing (FALSE, TRUE);
 
-  /* Let the main loop run for a while (quits after a short timeout)
-   * to let things stabilize. This includes parsing sessionrc and
-   * dockrc
+  /* Let the main loop run until idle to let things stabilize. This
+   * includes parsing sessionrc and dockrc
    */
   gimp_test_run_mainloop_until_idle ();
 
+  /* Change the gimp dir to the output dir so files are written there,
+   * we don't want to (can't always) write to files in the source
+   * dir. There is a hook in Makefile.am that makes sure the output
+   * dir exists
+   */
+  gimp_test_utils_set_gimp2_directory ("app/tests/gimpdir-output");
+  g_free (sessionrc_filename);
+  g_free (dockrc_filename);
+  sessionrc_filename = gimp_personal_rc_file ("sessionrc");
+  dockrc_filename    = gimp_personal_rc_file ("dockrc");
+
   /* Exit. This includes writing sessionrc and dockrc*/
   gimp_exit (gimp, TRUE);
 
diff --git a/app/tests/test-ui.c b/app/tests/test-ui.c
index 8a9b255..14c0a55 100644
--- a/app/tests/test-ui.c
+++ b/app/tests/test-ui.c
@@ -70,7 +70,7 @@ int main(int argc, char **argv)
   gtk_init (&argc, &argv);
   g_test_init (&argc, &argv, NULL);
 
-  gimp_test_utils_set_gimp2_directory ("gimpdir");
+  gimp_test_utils_set_gimp2_directory ("app/tests/gimpdir");
   gimp_test_utils_setup_menus_dir ();
 
   /* Start up GIMP */
@@ -106,6 +106,9 @@ int main(int argc, char **argv)
   /* Run the tests and return status */
   result = g_test_run ();
 
+  /* Don't write files to the source dir */
+  gimp_test_utils_set_gimp2_directory ("app/tests/gimpdir-output");
+
   /* Exit properly so we don't break script-fu plug-in wire */
   gimp_exit (gimp, TRUE);
 
diff --git a/app/tests/test-window-management.c b/app/tests/test-window-management.c
index d60c081..d3823c6 100644
--- a/app/tests/test-window-management.c
+++ b/app/tests/test-window-management.c
@@ -55,7 +55,7 @@ int main(int argc, char **argv)
   gtk_init (&argc, &argv);
   g_test_init (&argc, &argv, NULL);
 
-  gimp_test_utils_set_gimp2_directory ("gimpdir-empty");
+  gimp_test_utils_set_gimp2_directory ("app/tests/gimpdir-empty");
 
   /* We share the same application instance across all tests */
   gimp = gimp_init_for_gui_testing (FALSE, FALSE);
@@ -71,6 +71,9 @@ int main(int argc, char **argv)
   /* Run the tests and return status */
   test_result = g_test_run ();
 
+  /* Don't write files to the source dir */
+  gimp_test_utils_set_gimp2_directory ("app/tests/gimpdir-output");
+
   /* Exit somewhat properly to avoid annoying warnings */
   gimp_exit (gimp, TRUE);
 
diff --git a/app/tests/test-xcf.c b/app/tests/test-xcf.c
index 56e0516..397a087 100644
--- a/app/tests/test-xcf.c
+++ b/app/tests/test-xcf.c
@@ -875,7 +875,7 @@ main (int    argc,
   gtk_init (&argc, &argv);
   g_test_init (&argc, &argv, NULL);
 
-  gimp_test_utils_set_gimp2_directory ("gimpdir");
+  gimp_test_utils_set_gimp2_directory ("app/tests/gimpdir");
 
   /* We share the same application instance across all tests. We need
    * the GUI variant for the file procs
@@ -908,6 +908,9 @@ main (int    argc,
               gimp_write_and_read_gimp_2_8_format,
               NULL);
 
+  /* Don't write files to the source dir */
+  gimp_test_utils_set_gimp2_directory ("app/tests/gimpdir-output");
+
   /* Exit so we don't break script-fu plug-in wire */
   gimp_exit (gimp, TRUE);
 



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