[gimp] app/tests: Add gimp_test_utils_create_image_from_dalog()



commit 3728f6f7d7f127521f663db71fbad0a192c71d9b
Author: Martin Nordholts <martinn src gnome org>
Date:   Thu Jan 27 17:25:22 2011 +0100

    app/tests: Add gimp_test_utils_create_image_from_dalog()

 app/tests/gimp-app-test-utils.c |   59 +++++++++++++++++++++++++++++++++++++++
 app/tests/gimp-app-test-utils.h |    2 +
 app/tests/test-ui.c             |   47 ++----------------------------
 3 files changed, 65 insertions(+), 43 deletions(-)
---
diff --git a/app/tests/gimp-app-test-utils.c b/app/tests/gimp-app-test-utils.c
index d12d1d5..0c9003c 100644
--- a/app/tests/gimp-app-test-utils.c
+++ b/app/tests/gimp-app-test-utils.c
@@ -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;
+}
+
diff --git a/app/tests/gimp-app-test-utils.h b/app/tests/gimp-app-test-utils.h
index 4802e0d..322ef3d 100644
--- a/app/tests/gimp-app-test-utils.h
+++ b/app/tests/gimp-app-test-utils.h
@@ -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__ */
diff --git a/app/tests/test-ui.c b/app/tests/test-ui.c
index 8ad682c..49f4e1c 100644
--- a/app/tests/test-ui.c
+++ b/app/tests/test-ui.c
@@ -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;
-
-  /* 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);
+  Gimp      *gimp = GIMP (data);
+  GimpImage *image;
+  GimpLayer *layer;
 
-  /* 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),



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