2009-09-05 21:52:01 +08:00
|
|
|
/* 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"
|
|
|
|
|
2010-10-03 17:14:35 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-05-03 04:32:41 +08:00
|
|
|
#include <gegl.h>
|
2009-09-09 01:28:43 +08:00
|
|
|
#include <gtk/gtk.h>
|
2009-09-05 21:52:01 +08:00
|
|
|
|
2009-09-09 01:28:43 +08:00
|
|
|
#include "gui/gui-types.h"
|
|
|
|
|
|
|
|
#include "gui/gui.h"
|
|
|
|
|
|
|
|
#include "actions/actions.h"
|
|
|
|
|
|
|
|
#include "menus/menus.h"
|
2009-09-05 21:52:01 +08:00
|
|
|
|
2010-06-20 05:24:23 +08:00
|
|
|
#include "widgets/gimpsessioninfo.h"
|
|
|
|
|
2012-05-15 04:57:58 +08:00
|
|
|
#include "config/gimpgeglconfig.h"
|
2009-09-08 01:06:57 +08:00
|
|
|
|
2009-09-05 21:52:01 +08:00
|
|
|
#include "core/gimp.h"
|
2009-09-09 01:28:43 +08:00
|
|
|
#include "core/gimp-contexts.h"
|
2009-09-05 21:52:01 +08:00
|
|
|
|
2012-05-03 04:32:41 +08:00
|
|
|
#include "gegl/gimp-gegl.h"
|
|
|
|
|
2010-10-26 19:48:36 +08:00
|
|
|
#include "gimp-log.h"
|
2009-09-05 21:52:01 +08:00
|
|
|
#include "tests.h"
|
|
|
|
#include "units.h"
|
|
|
|
|
|
|
|
|
2010-10-22 03:11:06 +08:00
|
|
|
static void
|
|
|
|
gimp_status_func_dummy (const gchar *text1,
|
|
|
|
const gchar *text2,
|
|
|
|
gdouble percentage)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-05 21:52:01 +08:00
|
|
|
/**
|
|
|
|
* 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 *
|
2010-10-09 23:59:44 +08:00
|
|
|
gimp_init_for_testing (void)
|
2009-09-05 21:52:01 +08:00
|
|
|
{
|
2010-10-26 19:48:36 +08:00
|
|
|
Gimp *gimp;
|
2012-05-15 04:57:58 +08:00
|
|
|
|
2010-10-26 19:48:36 +08:00
|
|
|
gimp_log_init ();
|
2012-08-25 05:23:55 +08:00
|
|
|
gegl_init (NULL, NULL);
|
2010-10-26 19:48:36 +08:00
|
|
|
|
2012-12-15 07:34:15 +08:00
|
|
|
gimp = gimp_new ("Unit Tested GIMP", NULL, NULL, FALSE, TRUE, TRUE, TRUE,
|
2013-06-20 02:42:56 +08:00
|
|
|
FALSE, FALSE, TRUE, TRUE, FALSE);
|
2009-09-05 21:52:01 +08:00
|
|
|
|
|
|
|
units_init (gimp);
|
|
|
|
|
|
|
|
gimp_load_config (gimp, NULL, NULL);
|
|
|
|
|
2012-05-03 04:32:41 +08:00
|
|
|
gimp_gegl_init (gimp);
|
2010-10-22 03:11:06 +08:00
|
|
|
gimp_initialize (gimp, gimp_status_func_dummy);
|
|
|
|
gimp_restore (gimp, gimp_status_func_dummy);
|
2009-09-08 01:06:57 +08:00
|
|
|
|
2009-09-05 21:52:01 +08:00
|
|
|
return gimp;
|
|
|
|
}
|
2009-09-09 01:28:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef GIMP_CONSOLE_COMPILATION
|
|
|
|
|
2014-05-17 02:46:52 +08:00
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
|
2014-05-13 23:07:32 +08:00
|
|
|
static void
|
|
|
|
gimp_init_icon_theme_for_testing (void)
|
|
|
|
{
|
|
|
|
const gchar *top_srcdir = g_getenv ("GIMP_TESTING_ABS_TOP_SRCDIR");
|
|
|
|
gchar *icon_root;
|
|
|
|
gchar *link_name;
|
|
|
|
gchar *link_target;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
static const gchar *sizes[] = { "12x12", "16x16", "18x18", "20x20", "22x22",
|
|
|
|
"24x24", "32x32", "48x48", "64x64" };
|
|
|
|
|
|
|
|
if (! top_srcdir)
|
|
|
|
{
|
|
|
|
g_printerr ("*\n"
|
|
|
|
"* The env var GIMP_TESTING_ABS_TOP_SRCDIR is not set,\n"
|
|
|
|
"* you are probably running in a debugger.\n"
|
|
|
|
"* Set it manually, e.g.:\n"
|
|
|
|
"*\n"
|
|
|
|
"* set env GIMP_TESTING_ABS_TOP_SRCDIR=%s/source/gimp\n"
|
|
|
|
"*\n",
|
|
|
|
g_get_home_dir ());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
icon_root = g_dir_make_tmp ("gimp-test-icon-theme-XXXXXX", NULL);
|
|
|
|
if (! icon_root)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (sizes); i++)
|
|
|
|
{
|
|
|
|
gchar *icon_dir;
|
|
|
|
|
|
|
|
icon_dir = g_build_filename (icon_root, "hicolor", sizes[i], NULL);
|
|
|
|
g_mkdir_with_parents (icon_dir, 0700);
|
|
|
|
|
|
|
|
link_name = g_build_filename (icon_dir, "apps", NULL);
|
|
|
|
link_target = g_build_filename (top_srcdir, "icons", sizes[i] + 3, NULL);
|
|
|
|
|
|
|
|
symlink (link_target, link_name);
|
|
|
|
|
|
|
|
g_free (link_target);
|
|
|
|
g_free (link_name);
|
|
|
|
|
|
|
|
g_free (icon_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
link_name = g_build_filename (icon_root, "hicolor", "index.theme", NULL);
|
|
|
|
link_target = g_build_filename (top_srcdir, "icons", "index.theme", NULL);
|
|
|
|
|
|
|
|
symlink (link_target, link_name);
|
|
|
|
|
|
|
|
g_free (link_target);
|
|
|
|
g_free (link_name);
|
|
|
|
|
|
|
|
gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (),
|
|
|
|
icon_root);
|
|
|
|
|
|
|
|
g_free (icon_root);
|
|
|
|
}
|
|
|
|
|
2014-05-17 02:46:52 +08:00
|
|
|
#endif /* G_OS_WIN32 */
|
|
|
|
|
2011-06-07 02:04:20 +08:00
|
|
|
static Gimp *
|
|
|
|
gimp_init_for_gui_testing_internal (gboolean show_gui,
|
|
|
|
const gchar *gimprc)
|
2009-09-09 01:28:43 +08:00
|
|
|
{
|
2010-06-20 05:24:23 +08:00
|
|
|
GimpSessionInfoClass *klass;
|
|
|
|
Gimp *gimp;
|
2009-09-09 01:28:43 +08:00
|
|
|
|
|
|
|
/* from main() */
|
2010-10-26 19:48:36 +08:00
|
|
|
gimp_log_init ();
|
2012-08-25 05:23:55 +08:00
|
|
|
gegl_init (NULL, NULL);
|
2009-09-09 01:28:43 +08:00
|
|
|
|
2010-06-20 05:24:23 +08:00
|
|
|
/* Introduce an error margin for positions written to sessionrc */
|
|
|
|
klass = g_type_class_ref (GIMP_TYPE_SESSION_INFO);
|
|
|
|
gimp_session_info_class_set_position_accuracy (klass, 5);
|
|
|
|
|
2009-09-09 01:28:43 +08:00
|
|
|
/* from app_run() */
|
2012-12-15 07:34:15 +08:00
|
|
|
gimp = gimp_new ("Unit Tested GIMP", NULL, NULL, FALSE, TRUE, TRUE, !show_gui,
|
2013-06-20 02:42:56 +08:00
|
|
|
FALSE, FALSE, TRUE, TRUE, FALSE);
|
2009-09-17 04:58:41 +08:00
|
|
|
gimp_set_show_gui (gimp, show_gui);
|
2009-09-09 01:28:43 +08:00
|
|
|
units_init (gimp);
|
2011-06-07 02:04:20 +08:00
|
|
|
gimp_load_config (gimp, gimprc, NULL);
|
2012-05-03 04:32:41 +08:00
|
|
|
gimp_gegl_init (gimp);
|
2009-09-09 01:28:43 +08:00
|
|
|
gui_init (gimp, TRUE);
|
2014-05-17 02:46:52 +08:00
|
|
|
#ifndef G_OS_WIN32
|
2014-05-13 23:07:32 +08:00
|
|
|
gimp_init_icon_theme_for_testing ();
|
2014-05-17 02:46:52 +08:00
|
|
|
#endif
|
2009-09-09 01:28:43 +08:00
|
|
|
gimp_initialize (gimp, gimp_status_func_dummy);
|
|
|
|
gimp_restore (gimp, gimp_status_func_dummy);
|
|
|
|
|
2010-06-20 05:24:23 +08:00
|
|
|
g_type_class_unref (klass);
|
|
|
|
|
2009-09-09 01:28:43 +08:00
|
|
|
return gimp;
|
|
|
|
}
|
|
|
|
|
2011-06-07 02:04:20 +08:00
|
|
|
/**
|
|
|
|
* gimp_init_for_gui_testing:
|
|
|
|
* @show_gui:
|
|
|
|
*
|
|
|
|
* 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 show_gui)
|
|
|
|
{
|
|
|
|
return gimp_init_for_gui_testing_internal (show_gui, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_init_for_gui_testing:
|
|
|
|
* @show_gui:
|
|
|
|
* @gimprc:
|
|
|
|
*
|
|
|
|
* Like gimp_init_for_gui_testing(), but also allows a custom gimprc
|
|
|
|
* filename to be specified.
|
|
|
|
*
|
|
|
|
* Returns: The #Gimp instance.
|
|
|
|
**/
|
|
|
|
Gimp *
|
|
|
|
gimp_init_for_gui_testing_with_rc (gboolean show_gui,
|
|
|
|
const gchar *gimprc)
|
|
|
|
{
|
|
|
|
return gimp_init_for_gui_testing_internal (show_gui, gimprc);
|
|
|
|
}
|
|
|
|
|
2009-09-09 01:28:43 +08:00
|
|
|
#endif /* GIMP_CONSOLE_COMPILATION */
|
2009-09-17 06:12:23 +08:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_tests_quit_mainloop (GMainLoop *loop)
|
|
|
|
{
|
|
|
|
g_main_loop_quit (loop);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_test_run_temp_mainloop:
|
|
|
|
* @running_time: The time to run the main loop.
|
|
|
|
*
|
|
|
|
* Helper function for tests that wants to run a main loop for a
|
|
|
|
* while. Useful when you want GIMP's state to settle before doing
|
|
|
|
* tests.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_test_run_temp_mainloop (guint32 running_time)
|
|
|
|
{
|
|
|
|
GMainLoop *loop;
|
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
|
|
|
g_timeout_add (running_time,
|
|
|
|
(GSourceFunc) gimp_tests_quit_mainloop,
|
|
|
|
loop);
|
|
|
|
|
|
|
|
g_main_loop_run (loop);
|
|
|
|
|
|
|
|
g_main_loop_unref (loop);
|
|
|
|
}
|
|
|
|
|
2009-12-24 06:44:33 +08:00
|
|
|
/**
|
|
|
|
* gimp_test_run_mainloop_until_idle:
|
|
|
|
*
|
|
|
|
* Creates and runs a main loop until it is idle, i.e. has no more
|
|
|
|
* work to do.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_test_run_mainloop_until_idle (void)
|
|
|
|
{
|
|
|
|
GMainLoop *loop = g_main_loop_new (NULL, FALSE);
|
2009-09-17 06:12:23 +08:00
|
|
|
|
2009-12-24 06:44:33 +08:00
|
|
|
g_idle_add ((GSourceFunc) gimp_tests_quit_mainloop, loop);
|
|
|
|
|
|
|
|
g_main_loop_run (loop);
|
|
|
|
|
|
|
|
g_main_loop_unref (loop);
|
|
|
|
}
|
2010-10-03 17:14:35 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_test_bail_if_no_display:
|
|
|
|
* @void:
|
|
|
|
*
|
|
|
|
* If no DISPLAY is set, call exit(EXIT_SUCCESS). There is no use in
|
|
|
|
* having UI tests failing in DISPLAY-less environments.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_test_bail_if_no_display (void)
|
|
|
|
{
|
|
|
|
if (! g_getenv ("DISPLAY"))
|
|
|
|
{
|
|
|
|
g_message ("No DISPLAY set, not running UI tests\n");
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|