app: Add 'crop_set_width_without_pending_rect' regression test

Add regression test 'crop_set_width_without_pending_rect' for "Bug
322396 - Crop dimension entering causes crash".
This commit is contained in:
Martin Nordholts 2010-10-31 15:09:03 +01:00
parent 48690d60e1
commit df0772fcde
3 changed files with 85 additions and 4 deletions

View file

@ -28,6 +28,7 @@
#include "tools/tools-types.h"
#include "tools/gimprectangleoptions.h"
#include "tools/tool_manager.h"
#include "display/gimpdisplay.h"
@ -125,6 +126,26 @@ gimp_tools_teardown_image (GimpTestFixture *fixture,
gimp_test_run_mainloop_until_idle ();
}
/**
* gimp_tools_set_tool:
* @gimp:
* @tool_id:
* @display:
*
* Makes sure the given tool is the active tool and that the passed
* display is the focused tool display.
**/
static void
gimp_tools_set_tool (Gimp *gimp,
const gchar *tool_id,
GimpDisplay *display)
{
/* Activate tool and setup active display for the new tool */
gimp_context_set_tool (gimp_get_user_context (gimp),
gimp_get_tool_info (gimp, tool_id));
tool_manager_focus_display_active (gimp, display);
}
/**
* gimp_test_get_only_display:
* @gimp:
@ -376,10 +397,8 @@ crop_tool_can_crop (GimpTestFixture *fixture,
gimp_test_run_mainloop_until_idle ();
gimp_test_run_mainloop_until_idle ();
/* Activate tool and setup active display for the new tool */
gimp_context_set_tool (gimp_get_user_context (gimp),
gimp_get_tool_info (gimp, "gimp-crop-tool"));
tool_manager_focus_display_active (gimp, shell->display);
/* Activate crop tool */
gimp_tools_set_tool (gimp, "gimp-crop-tool", shell->display);
/* Do the crop rect */
gimp_tools_synthesize_image_click_drag_release (shell,
@ -399,6 +418,45 @@ crop_tool_can_crop (GimpTestFixture *fixture,
g_assert_cmpint (cropped_h, ==, gimp_image_get_height (image));
}
/**
* crop_tool_can_crop:
* @fixture:
* @data:
*
* Make sure it's possible to change width of crop rect in tool
* options without there being a pending rectangle. Regression test
* for "Bug 322396 - Crop dimension entering causes crash".
**/
static void
crop_set_width_without_pending_rect (GimpTestFixture *fixture,
gconstpointer data)
{
Gimp *gimp = GIMP (data);
GimpDisplay *display = gimp_test_get_only_display (gimp);
GimpToolInfo *tool_info;
GimpRectangleOptions *rectangle_options;
GtkWidget *tool_options_gui;
GtkWidget *size_entry;
/* Activate crop tool */
gimp_tools_set_tool (gimp, "gimp-crop-tool", display);
/* Get tool options */
tool_info = gimp_get_tool_info (gimp, "gimp-crop-tool");
tool_options_gui = gimp_tools_get_tool_options_gui (tool_info->tool_options);
rectangle_options = GIMP_RECTANGLE_OPTIONS (tool_info->tool_options);
/* Find 'Width' or 'Height' GtkTextEntry in tool options */
size_entry = gimp_rectangle_options_get_width_entry (rectangle_options);
/* Set arbitrary non-0 value */
gimp_size_entry_set_value (GIMP_SIZE_ENTRY (size_entry),
0 /*field*/,
42.0 /*lower*/);
/* If we don't crash, everything s fine */
}
int main(int argc, char **argv)
{
Gimp *gimp = NULL;
@ -417,6 +475,7 @@ int main(int argc, char **argv)
/* Add tests */
ADD_TEST (crop_tool_can_crop);
ADD_TEST (crop_set_width_without_pending_rect);
/* Run the tests and return status */
result = g_test_run ();

View file

@ -656,6 +656,23 @@ gimp_rectangle_options_get_property (GObject *object,
}
}
/**
* gimp_rectangle_options_get_width_entry:
* @rectangle_options:
*
* Returns: GtkEntry used to enter desired width of rectangle. For
* testing purposes.
**/
GtkWidget *
gimp_rectangle_options_get_width_entry (GimpRectangleOptions *rectangle_options)
{
GimpRectangleOptionsPrivate *private;
private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (rectangle_options);
return private->width_entry;
}
/**
* gimp_rectangle_options_fixed_rule_changed:
* @combo_box:

View file

@ -165,4 +165,9 @@ void gimp_rectangle_options_get_property (GObject *object,
GParamSpec *pspec);
/* testing helper functions */
GtkWidget * gimp_rectangle_options_get_width_entry (GimpRectangleOptions *rectangle_options);
#endif /* __GIMP_RECTANGLE_OPTIONS_H__ */