app/tests: Add gimp_test_utils_create_image_from_dalog()

This commit is contained in:
Martin Nordholts 2011-01-27 17:25:22 +01:00
parent 6ea36f3383
commit 3728f6f7d7
3 changed files with 65 additions and 43 deletions

View File

@ -27,11 +27,14 @@
#include "display/gimpimagewindow.h"
#include "widgets/gimpuimanager.h"
#include "widgets/gimpdialogfactory.h"
#include "core/gimp.h"
#include "core/gimpimage.h"
#include "core/gimplayer.h"
#include "tests.h"
#include "gimp-app-test-utils.h"
@ -197,3 +200,59 @@ gimp_test_utils_get_ui_manager (Gimp *gimp)
return ui_manager;
}
/**
* gimp_test_utils_create_image_from_dalog:
* @gimp:
*
* Creates a new image using the "New image" dialog, and then returns
* the #GimpImage created.
*
* Returns: The created #GimpImage.
**/
GimpImage *
gimp_test_utils_create_image_from_dalog (Gimp *gimp)
{
GimpImage *image = NULL;
GtkWidget *new_image_dialog = NULL;
guint n_initial_images = g_list_length (gimp_get_image_iter (gimp));
guint n_images = -1;
gint tries_left = 100;
GimpUIManager *ui_manager = gimp_test_utils_get_ui_manager (gimp);
/* Bring up the new image dialog */
gimp_ui_manager_activate_action (ui_manager,
"image",
"image-new");
gimp_test_run_mainloop_until_idle ();
/* Get the GtkWindow of the dialog */
new_image_dialog =
gimp_dialog_factory_dialog_raise (gimp_dialog_factory_get_singleton (),
gdk_screen_get_default (),
"gimp-image-new-dialog",
-1 /*view_size*/);
/* Press the focused widget, it should be the Ok button. It will
* take a while for the image to be created to loop for a while
*/
gtk_widget_activate (gtk_window_get_focus (GTK_WINDOW (new_image_dialog)));
do
{
g_usleep (20 * 1000);
gimp_test_run_mainloop_until_idle ();
n_images = g_list_length (gimp_get_image_iter (gimp));
}
while (tries_left-- &&
n_images != n_initial_images + 1);
/* Make sure there now is one image more than initially */
g_assert_cmpint (n_images,
==,
n_initial_images + 1);
image = GIMP_IMAGE (gimp_get_image_iter (gimp)->data);
return image;
}

View File

@ -28,6 +28,8 @@ void gimp_test_utils_create_image (Gimp *gimp,
void gimp_test_utils_synthesize_key_event (GtkWidget *widget,
guint keyval);
GimpUIManager * gimp_test_utils_get_ui_manager (Gimp *gimp);
GimpImage * gimp_test_utils_create_image_from_dalog
(Gimp *gimp);
#endif /* __GIMP_RECTANGLE_SELECT_TOOL_H__ */

View File

@ -229,52 +229,13 @@ static void
create_new_image_via_dialog (GimpTestFixture *fixture,
gconstpointer data)
{
Gimp *gimp = GIMP (data);
GimpDisplay *display = GIMP_DISPLAY (gimp_get_empty_display (gimp));
GimpDisplayShell *shell = gimp_display_get_shell (display);
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (shell));
GimpImageWindow *image_window = GIMP_IMAGE_WINDOW (toplevel);
GimpUIManager *ui_manager = gimp_image_window_get_ui_manager (image_window);
GtkWidget *new_image_dialog = NULL;
guint n_initial_images = g_list_length (gimp_get_image_iter (gimp));
guint n_images = -1;
gint tries_left = 100;
GimpImage *image;
GimpLayer *layer;
Gimp *gimp = GIMP (data);
GimpImage *image;
GimpLayer *layer;
/* Bring up the new image dialog */
gimp_ui_manager_activate_action (ui_manager,
"image",
"image-new");
gimp_test_run_mainloop_until_idle ();
/* Get the GtkWindow of the dialog */
new_image_dialog =
gimp_dialog_factory_dialog_raise (gimp_dialog_factory_get_singleton (),
gtk_widget_get_screen (GTK_WIDGET (shell)),
"gimp-image-new-dialog",
-1 /*view_size*/);
/* Press the focused widget, it should be the Ok button. It will
* take a while for the image to be created to loop for a while
*/
gtk_widget_activate (gtk_window_get_focus (GTK_WINDOW (new_image_dialog)));
do
{
g_usleep (20 * 1000);
gimp_test_run_mainloop_until_idle ();
n_images = g_list_length (gimp_get_image_iter (gimp));
}
while (tries_left-- &&
n_images != n_initial_images + 1);
/* Make sure there now is one image more than initially */
g_assert_cmpint (n_images,
==,
n_initial_images + 1);
image = gimp_test_utils_create_image_from_dalog (gimp);
/* Add a layer to the image to make it more useful in later tests */
image = GIMP_IMAGE (gimp_get_image_iter (gimp)->data);
layer = gimp_layer_new (image,
gimp_image_get_width (image),
gimp_image_get_height (image),