[gimp] app: Add gimp_init_for_gui_testing()



commit 86f8e996d7f077880724b293092a24a1f6466fe5
Author: Martin Nordholts <martinn src gnome org>
Date:   Tue Sep 8 19:28:43 2009 +0200

    app: Add gimp_init_for_gui_testing()
    
    In order to allow test cases to test GUI code, add
    gimp_init_for_gui_testing() which is like gimp_init_for_testing() but
    includes initializations of GUI parts.

 app/tests.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 app/tests.h |    3 ++-
 2 files changed, 57 insertions(+), 3 deletions(-)
---
diff --git a/app/tests.c b/app/tests.c
index 6c71373..d13b367 100644
--- a/app/tests.c
+++ b/app/tests.c
@@ -17,15 +17,24 @@
 
 #include "config.h"
 
-#include <glib-object.h>
+#include <gtk/gtk.h>
 
-#include "core/core-types.h"
+#include "gui/gui-types.h"
+
+#include "gui/gui.h"
+
+#include "actions/actions.h"
+
+#include "dialogs/dialogs.h"
+
+#include "menus/menus.h"
 
 #include "base/base.h"
 
 #include "config/gimpbaseconfig.h"
 
 #include "core/gimp.h"
+#include "core/gimp-contexts.h"
 
 #include "tests.h"
 #include "units.h"
@@ -51,3 +60,47 @@ gimp_init_for_testing (gboolean use_cpu_accel)
 
   return gimp;
 }
+
+
+#ifndef GIMP_CONSOLE_COMPILATION
+
+static void
+gimp_status_func_dummy (const gchar *text1,
+                        const gchar *text2,
+                        gdouble      percentage)
+{
+}
+
+/**
+ * gimp_init_for_gui_testing:
+ * @use_cpu_accel:
+ *
+ * Initializes a #Gimp instance for use in test cases that rely on GUI
+ * code to be initialized.
+ *
+ * Returns: The #Gimp instance.
+ **/
+Gimp *
+gimp_init_for_gui_testing (gboolean use_cpu_accel)
+{
+  Gimp *gimp;
+
+  /* from main() */
+  g_thread_init(NULL);
+  g_type_init();
+
+  /* from app_run() */
+  gimp = gimp_new ("Unit Tested GIMP", NULL, FALSE, TRUE, TRUE, TRUE,
+                   FALSE, TRUE, TRUE, FALSE);
+  gimp_set_show_gui (gimp, FALSE);
+  units_init (gimp);
+  gimp_load_config (gimp, NULL, NULL);
+  base_init (GIMP_BASE_CONFIG (gimp->config), FALSE, use_cpu_accel);
+  gui_init (gimp, TRUE);
+  gimp_initialize (gimp, gimp_status_func_dummy);
+  gimp_restore (gimp, gimp_status_func_dummy);
+
+  return gimp;
+}
+
+#endif /* GIMP_CONSOLE_COMPILATION */
diff --git a/app/tests.h b/app/tests.h
index 3fd9376..654e048 100644
--- a/app/tests.h
+++ b/app/tests.h
@@ -19,7 +19,8 @@
 #define __TESTS_H__
 
 
-Gimp * gimp_init_for_testing (gboolean use_cpu_accel);
+Gimp * gimp_init_for_testing     (gboolean use_cpu_accel);
+Gimp * gimp_init_for_gui_testing (gboolean use_cpu_accel);
 
 
 #endif /* __TESTS_H__ */



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