app: Introduce error margin in sessionrc in test cases
Introduce a few pixels of error margin in sessionrc, otherwise the tests are too fragile, widgets have a tendency to change size a bit and window managers have a tendency to move windows a bit. Still needs more work, should probably do the same on book positions too...
This commit is contained in:
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include "menus/menus.h"
|
#include "menus/menus.h"
|
||||||
|
|
||||||
|
#include "widgets/gimpsessioninfo.h"
|
||||||
|
|
||||||
#include "base/base.h"
|
#include "base/base.h"
|
||||||
|
|
||||||
#include "config/gimpbaseconfig.h"
|
#include "config/gimpbaseconfig.h"
|
||||||
@ -81,12 +83,17 @@ gimp_status_func_dummy (const gchar *text1,
|
|||||||
Gimp *
|
Gimp *
|
||||||
gimp_init_for_gui_testing (gboolean use_cpu_accel, gboolean show_gui)
|
gimp_init_for_gui_testing (gboolean use_cpu_accel, gboolean show_gui)
|
||||||
{
|
{
|
||||||
|
GimpSessionInfoClass *klass;
|
||||||
Gimp *gimp;
|
Gimp *gimp;
|
||||||
|
|
||||||
/* from main() */
|
/* from main() */
|
||||||
g_thread_init(NULL);
|
g_thread_init(NULL);
|
||||||
g_type_init();
|
g_type_init();
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
|
||||||
/* from app_run() */
|
/* from app_run() */
|
||||||
gimp = gimp_new ("Unit Tested GIMP", NULL, FALSE, TRUE, TRUE, !show_gui,
|
gimp = gimp_new ("Unit Tested GIMP", NULL, FALSE, TRUE, TRUE, !show_gui,
|
||||||
FALSE, TRUE, TRUE, FALSE);
|
FALSE, TRUE, TRUE, FALSE);
|
||||||
@ -98,6 +105,8 @@ gimp_init_for_gui_testing (gboolean use_cpu_accel, gboolean show_gui)
|
|||||||
gimp_initialize (gimp, gimp_status_func_dummy);
|
gimp_initialize (gimp, gimp_status_func_dummy);
|
||||||
gimp_restore (gimp, gimp_status_func_dummy);
|
gimp_restore (gimp, gimp_status_func_dummy);
|
||||||
|
|
||||||
|
g_type_class_unref (klass);
|
||||||
|
|
||||||
return gimp;
|
return gimp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
(GimpSessionInfo "Palettes - FG/BG - Images"
|
(GimpSessionInfo "Palettes - FG/BG - Images"
|
||||||
(factory-entry "gimp-dock-window")
|
(factory-entry "gimp-dock-window")
|
||||||
(position 586 116)
|
(position 585 115)
|
||||||
(size 200 573)
|
(size 200 575)
|
||||||
(open-on-exit)
|
(open-on-exit)
|
||||||
(aux-info
|
(aux-info
|
||||||
(show-image-menu "false")
|
(show-image-menu "false")
|
||||||
@ -27,7 +27,7 @@
|
|||||||
(tab-style preview)))))
|
(tab-style preview)))))
|
||||||
(GimpSessionInfo "Selection, Fonts"
|
(GimpSessionInfo "Selection, Fonts"
|
||||||
(factory-entry "gimp-dock-window")
|
(factory-entry "gimp-dock-window")
|
||||||
(position 200 179)
|
(position 200 180)
|
||||||
(size 200 300)
|
(size 200 300)
|
||||||
(open-on-exit)
|
(open-on-exit)
|
||||||
(aux-info
|
(aux-info
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
(session-info "toplevel"
|
(session-info "toplevel"
|
||||||
(factory-entry "gimp-dock-window")
|
(factory-entry "gimp-dock-window")
|
||||||
(position 566 171)
|
(position 565 170)
|
||||||
(size 210 535)
|
(size 210 535)
|
||||||
(open-on-exit)
|
(open-on-exit)
|
||||||
(aux-info
|
(aux-info
|
||||||
@ -28,8 +28,8 @@
|
|||||||
(tab-style preview)))))
|
(tab-style preview)))))
|
||||||
(session-info "toplevel"
|
(session-info "toplevel"
|
||||||
(factory-entry "gimp-dock-window")
|
(factory-entry "gimp-dock-window")
|
||||||
(position 141 291)
|
(position 140 290)
|
||||||
(size 406 300)
|
(size 405 300)
|
||||||
(open-on-exit)
|
(open-on-exit)
|
||||||
(aux-info
|
(aux-info
|
||||||
(show-image-menu "false")
|
(show-image-menu "false")
|
||||||
@ -46,7 +46,7 @@
|
|||||||
(tab-style icon)))))
|
(tab-style icon)))))
|
||||||
(session-info "toplevel"
|
(session-info "toplevel"
|
||||||
(factory-entry "gimp-dock-window")
|
(factory-entry "gimp-dock-window")
|
||||||
(position 795 43)
|
(position 795 45)
|
||||||
(size 200 265)
|
(size 200 265)
|
||||||
(open-on-exit)
|
(open-on-exit)
|
||||||
(aux-info
|
(aux-info
|
||||||
@ -61,8 +61,8 @@
|
|||||||
(tab-style preview)))))
|
(tab-style preview)))))
|
||||||
(session-info "toplevel"
|
(session-info "toplevel"
|
||||||
(factory-entry "gimp-dock-window")
|
(factory-entry "gimp-dock-window")
|
||||||
(position 803 344)
|
(position 805 345)
|
||||||
(size 200 421)
|
(size 200 420)
|
||||||
(open-on-exit)
|
(open-on-exit)
|
||||||
(aux-info
|
(aux-info
|
||||||
(show-image-menu "true")
|
(show-image-menu "true")
|
||||||
@ -74,7 +74,7 @@
|
|||||||
(tab-style automatic)
|
(tab-style automatic)
|
||||||
(preview-size 32)))
|
(preview-size 32)))
|
||||||
(book
|
(book
|
||||||
(position 174)
|
(position 162)
|
||||||
(current-page 0)
|
(current-page 0)
|
||||||
(dockable "gimp-palette-editor"
|
(dockable "gimp-palette-editor"
|
||||||
(tab-style icon)
|
(tab-style icon)
|
||||||
@ -84,14 +84,14 @@
|
|||||||
(zoom-factor "2.80"))))))
|
(zoom-factor "2.80"))))))
|
||||||
(session-info "toplevel"
|
(session-info "toplevel"
|
||||||
(factory-entry "gimp-file-open-dialog")
|
(factory-entry "gimp-file-open-dialog")
|
||||||
(position 392 140)
|
(position 390 140)
|
||||||
(size 902 816))
|
(size 900 815))
|
||||||
(session-info "toplevel"
|
(session-info "toplevel"
|
||||||
(factory-entry "gimp-image-new-dialog")
|
(factory-entry "gimp-image-new-dialog")
|
||||||
(position 100 100))
|
(position 100 100))
|
||||||
(session-info "toplevel"
|
(session-info "toplevel"
|
||||||
(factory-entry "gimp-empty-image-window")
|
(factory-entry "gimp-empty-image-window")
|
||||||
(position 140 32)
|
(position 140 30)
|
||||||
(size 610 190))
|
(size 610 190))
|
||||||
|
|
||||||
(last-tip-shown 0)
|
(last-tip-shown 0)
|
||||||
|
@ -139,7 +139,12 @@ gimp_session_info_serialize (GimpConfig *config,
|
|||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GimpSessionInfo *info = GIMP_SESSION_INFO (config);
|
GimpSessionInfo *info = GIMP_SESSION_INFO (config);
|
||||||
|
GimpSessionInfoClass *klass = GIMP_SESSION_INFO_GET_CLASS (info);
|
||||||
GList *iter = NULL;
|
GList *iter = NULL;
|
||||||
|
gint x_to_write;
|
||||||
|
gint y_to_write;
|
||||||
|
gint w_to_write;
|
||||||
|
gint h_to_write;
|
||||||
|
|
||||||
if (info->p->factory_entry && info->p->factory_entry->identifier)
|
if (info->p->factory_entry && info->p->factory_entry->identifier)
|
||||||
{
|
{
|
||||||
@ -148,14 +153,23 @@ gimp_session_info_serialize (GimpConfig *config,
|
|||||||
gimp_config_writer_close (writer);
|
gimp_config_writer_close (writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
x_to_write = gimp_session_info_class_apply_position_accuracy (klass,
|
||||||
|
info->p->x);
|
||||||
|
y_to_write = gimp_session_info_class_apply_position_accuracy (klass,
|
||||||
|
info->p->y);
|
||||||
|
w_to_write = gimp_session_info_class_apply_position_accuracy (klass,
|
||||||
|
info->p->width);
|
||||||
|
h_to_write = gimp_session_info_class_apply_position_accuracy (klass,
|
||||||
|
info->p->height);
|
||||||
|
|
||||||
gimp_config_writer_open (writer, "position");
|
gimp_config_writer_open (writer, "position");
|
||||||
gimp_config_writer_printf (writer, "%d %d", info->p->x, info->p->y);
|
gimp_config_writer_printf (writer, "%d %d", x_to_write, y_to_write);
|
||||||
gimp_config_writer_close (writer);
|
gimp_config_writer_close (writer);
|
||||||
|
|
||||||
if (info->p->width > 0 && info->p->height > 0)
|
if (info->p->width > 0 && info->p->height > 0)
|
||||||
{
|
{
|
||||||
gimp_config_writer_open (writer, "size");
|
gimp_config_writer_open (writer, "size");
|
||||||
gimp_config_writer_printf (writer, "%d %d", info->p->width, info->p->height);
|
gimp_config_writer_printf (writer, "%d %d", w_to_write, h_to_write);
|
||||||
gimp_config_writer_close (writer);
|
gimp_config_writer_close (writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -851,3 +865,44 @@ gimp_session_info_get_height (GimpSessionInfo *info)
|
|||||||
|
|
||||||
return info->p->height;
|
return info->p->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_session_info_class_set_position_accuracy:
|
||||||
|
* @accuracy:
|
||||||
|
*
|
||||||
|
* When writing sessionrc, make positions and sizes a multiple of
|
||||||
|
* @accuracy. Meant to be used by test cases that does regression
|
||||||
|
* testing on session managed window positions and sizes, to allow for
|
||||||
|
* some deviations from the original setup, that the window manager
|
||||||
|
* might impose.
|
||||||
|
**/
|
||||||
|
void
|
||||||
|
gimp_session_info_class_set_position_accuracy (GimpSessionInfoClass *klass,
|
||||||
|
gint accuracy)
|
||||||
|
{
|
||||||
|
g_return_if_fail (GIMP_IS_SESSION_INFO_CLASS (klass));
|
||||||
|
|
||||||
|
klass->position_accuracy = accuracy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_session_info_class_apply_position_accuracy:
|
||||||
|
* @position:
|
||||||
|
*
|
||||||
|
* Rounds @position to the nearest multiple of what was set with
|
||||||
|
* gimp_session_info_class_set_position_accuracy().
|
||||||
|
*
|
||||||
|
* Returns: Result.
|
||||||
|
**/
|
||||||
|
gint
|
||||||
|
gimp_session_info_class_apply_position_accuracy (GimpSessionInfoClass *klass,
|
||||||
|
gint position)
|
||||||
|
{
|
||||||
|
gint n = klass->position_accuracy;
|
||||||
|
gint to_floor;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GIMP_IS_SESSION_INFO_CLASS (klass), position);
|
||||||
|
|
||||||
|
to_floor = position + n / 2;
|
||||||
|
return to_floor - to_floor % n;
|
||||||
|
}
|
||||||
|
@ -52,6 +52,8 @@ struct _GimpSessionInfo
|
|||||||
struct _GimpSessionInfoClass
|
struct _GimpSessionInfoClass
|
||||||
{
|
{
|
||||||
GimpObjectClass parent_class;
|
GimpObjectClass parent_class;
|
||||||
|
|
||||||
|
gint position_accuracy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -80,6 +82,10 @@ gint gimp_session_info_get_x (GimpSessionInfo
|
|||||||
gint gimp_session_info_get_y (GimpSessionInfo *info);
|
gint gimp_session_info_get_y (GimpSessionInfo *info);
|
||||||
gint gimp_session_info_get_width (GimpSessionInfo *info);
|
gint gimp_session_info_get_width (GimpSessionInfo *info);
|
||||||
gint gimp_session_info_get_height (GimpSessionInfo *info);
|
gint gimp_session_info_get_height (GimpSessionInfo *info);
|
||||||
|
void gimp_session_info_class_set_position_accuracy (GimpSessionInfoClass *klass,
|
||||||
|
gint accuracy);
|
||||||
|
gint gimp_session_info_class_apply_position_accuracy (GimpSessionInfoClass *klass,
|
||||||
|
gint position);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __GIMP_SESSION_INFO_H__ */
|
#endif /* __GIMP_SESSION_INFO_H__ */
|
||||||
|
Reference in New Issue
Block a user