2007-11-20 15:03:28 +00:00
|
|
|
/* Gtk+ testing utilities
|
2007-11-20 17:44:06 +00:00
|
|
|
* Copyright (C) 2007 Imendio AB
|
|
|
|
* Authors: Tim Janik
|
2007-11-20 15:03:28 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
/* --- test functions --- */
|
|
|
|
static void
|
|
|
|
test_button_clicks (void)
|
|
|
|
{
|
|
|
|
int a = 0, b = 0, c = 0;
|
|
|
|
GtkWidget *window = gtk_test_display_button_window ("Test Window",
|
|
|
|
"Test: gtk_test_widget_click",
|
|
|
|
"IgnoreMe1", &a,
|
|
|
|
"ClickMe", &b,
|
|
|
|
"IgnoreMe2", &c,
|
|
|
|
NULL);
|
|
|
|
GtkWidget *button = gtk_test_find_widget (window, "*Click*", GTK_TYPE_BUTTON);
|
|
|
|
gboolean simsuccess;
|
|
|
|
g_assert (button != NULL);
|
|
|
|
simsuccess = gtk_test_widget_click (button, 1, 0);
|
|
|
|
g_assert (simsuccess == TRUE);
|
2009-07-07 05:05:29 +00:00
|
|
|
while (gtk_events_pending ()) {
|
|
|
|
g_print ("iterate main loop\n");
|
2007-11-20 15:03:28 +00:00
|
|
|
gtk_main_iteration ();
|
2009-07-07 05:05:29 +00:00
|
|
|
}
|
|
|
|
g_assert (a == 0);
|
|
|
|
g_assert (b > 0);
|
|
|
|
g_assert (c == 0);
|
2007-11-20 15:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_button_keys (void)
|
|
|
|
{
|
|
|
|
int a = 0, b = 0, c = 0;
|
|
|
|
GtkWidget *window = gtk_test_display_button_window ("Test Window",
|
|
|
|
"Test: gtk_test_widget_send_key",
|
|
|
|
"IgnoreMe1", &a,
|
|
|
|
"ClickMe", &b,
|
|
|
|
"IgnoreMe2", &c,
|
|
|
|
NULL);
|
|
|
|
GtkWidget *button = gtk_test_find_widget (window, "*Click*", GTK_TYPE_BUTTON);
|
|
|
|
gboolean simsuccess;
|
|
|
|
g_assert (button != NULL);
|
|
|
|
gtk_widget_grab_focus (button);
|
2010-03-01 03:21:41 +00:00
|
|
|
g_assert (gtk_widget_has_focus (button));
|
2010-09-08 17:35:51 +00:00
|
|
|
simsuccess = gtk_test_widget_send_key (button, GDK_KEY_Return, 0);
|
2007-11-20 15:03:28 +00:00
|
|
|
g_assert (simsuccess == TRUE);
|
|
|
|
while (gtk_events_pending ())
|
|
|
|
gtk_main_iteration ();
|
2009-07-07 05:05:29 +00:00
|
|
|
g_assert (a == 0);
|
|
|
|
g_assert (b > 0);
|
|
|
|
g_assert (c == 0);
|
2007-11-20 15:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_slider_ranges (void)
|
|
|
|
{
|
2010-05-24 20:31:36 +00:00
|
|
|
GtkWidget *child;
|
2007-11-20 15:03:28 +00:00
|
|
|
GtkWidget *window = gtk_test_create_simple_window ("Test Window", "Test: gtk_test_warp_slider");
|
|
|
|
GtkWidget *hscale = gtk_hscale_new_with_range (-50, +50, 5);
|
2010-05-24 20:31:36 +00:00
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (window));
|
|
|
|
gtk_container_add (GTK_CONTAINER (child), hscale);
|
2007-11-20 15:03:28 +00:00
|
|
|
gtk_widget_show (hscale);
|
|
|
|
gtk_widget_show_now (window);
|
|
|
|
while (gtk_events_pending ())
|
|
|
|
gtk_main_iteration ();
|
|
|
|
gtk_test_slider_set_perc (hscale, 0.0);
|
|
|
|
while (gtk_events_pending ())
|
|
|
|
gtk_main_iteration ();
|
|
|
|
g_assert (gtk_test_slider_get_value (hscale) == -50);
|
|
|
|
gtk_test_slider_set_perc (hscale, 50.0);
|
|
|
|
while (gtk_events_pending ())
|
|
|
|
gtk_main_iteration ();
|
|
|
|
g_assert (fabs (gtk_test_slider_get_value (hscale)) < 0.0001);
|
|
|
|
gtk_test_slider_set_perc (hscale, 100.0);
|
|
|
|
while (gtk_events_pending ())
|
|
|
|
gtk_main_iteration ();
|
|
|
|
g_assert (gtk_test_slider_get_value (hscale) == +50.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_text_access (void)
|
|
|
|
{
|
2010-05-07 07:26:36 +00:00
|
|
|
const int N_WIDGETS = 3;
|
2007-11-20 15:03:28 +00:00
|
|
|
GtkWidget *widgets[N_WIDGETS];
|
|
|
|
int i = 0;
|
|
|
|
widgets[i++] = gtk_test_create_widget (GTK_TYPE_LABEL, NULL);
|
|
|
|
widgets[i++] = gtk_test_create_widget (GTK_TYPE_ENTRY, NULL);
|
|
|
|
widgets[i++] = gtk_test_create_widget (GTK_TYPE_TEXT_VIEW, NULL);
|
|
|
|
g_assert (i == N_WIDGETS);
|
|
|
|
for (i = 0; i < N_WIDGETS; i++)
|
|
|
|
gtk_test_text_set (widgets[i], "foobar");
|
|
|
|
for (i = 0; i < N_WIDGETS; i++)
|
|
|
|
{
|
|
|
|
gchar *text = gtk_test_text_get (widgets[i]);
|
|
|
|
g_assert (strcmp (text, "foobar") == 0);
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
for (i = 0; i < N_WIDGETS; i++)
|
|
|
|
gtk_test_text_set (widgets[i], "");
|
|
|
|
for (i = 0; i < N_WIDGETS; i++)
|
|
|
|
{
|
|
|
|
gchar *text = gtk_test_text_get (widgets[i]);
|
|
|
|
g_assert (strcmp (text, "") == 0);
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_xserver_sync (void)
|
|
|
|
{
|
|
|
|
GtkWidget *window = gtk_test_create_simple_window ("Test Window", "Test: test_xserver_sync");
|
|
|
|
GtkWidget *darea = gtk_drawing_area_new ();
|
2010-05-24 20:31:36 +00:00
|
|
|
GtkWidget *child;
|
2010-08-15 16:52:05 +00:00
|
|
|
GdkWindow *gdk_window;
|
2007-11-20 15:03:28 +00:00
|
|
|
GTimer *gtimer = g_timer_new();
|
|
|
|
gint sync_is_slower = 0, repeat = 5;
|
2010-05-24 20:31:36 +00:00
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (window));
|
2010-08-15 16:52:05 +00:00
|
|
|
//gdk_window = gtk_widget_get_window (darea);
|
|
|
|
|
2007-11-20 15:03:28 +00:00
|
|
|
gtk_widget_set_size_request (darea, 320, 200);
|
2010-05-24 20:31:36 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (child), darea);
|
2007-11-20 15:03:28 +00:00
|
|
|
gtk_widget_show (darea);
|
|
|
|
gtk_widget_show_now (window);
|
2010-08-15 16:52:05 +00:00
|
|
|
|
2007-11-20 15:03:28 +00:00
|
|
|
while (repeat--)
|
|
|
|
{
|
2010-07-14 23:08:03 +00:00
|
|
|
gint i, many = 200;
|
2007-11-20 15:03:28 +00:00
|
|
|
double nosync_time, sync_time;
|
2010-07-14 23:08:03 +00:00
|
|
|
cairo_t *cr;
|
|
|
|
|
2007-11-20 15:03:28 +00:00
|
|
|
while (gtk_events_pending ())
|
|
|
|
gtk_main_iteration ();
|
2010-08-15 16:52:05 +00:00
|
|
|
gdk_window = gtk_widget_get_window (darea);
|
|
|
|
cr = gdk_cairo_create (gdk_window);
|
2010-07-14 23:08:03 +00:00
|
|
|
cairo_set_source_rgba (cr, 0, 1, 0, 0.1);
|
2007-11-20 15:03:28 +00:00
|
|
|
/* run a number of consecutive drawing requests, just using drawing queue */
|
|
|
|
g_timer_start (gtimer);
|
|
|
|
for (i = 0; i < many; i++)
|
|
|
|
{
|
2010-07-14 23:08:03 +00:00
|
|
|
cairo_paint (cr);
|
2007-11-20 15:03:28 +00:00
|
|
|
}
|
|
|
|
g_timer_stop (gtimer);
|
|
|
|
nosync_time = g_timer_elapsed (gtimer, NULL);
|
|
|
|
gdk_flush();
|
|
|
|
while (gtk_events_pending ())
|
|
|
|
gtk_main_iteration ();
|
|
|
|
g_timer_start (gtimer);
|
|
|
|
/* run a number of consecutive drawing requests with intermediate drawing syncs */
|
|
|
|
for (i = 0; i < many; i++)
|
|
|
|
{
|
2010-07-14 23:08:03 +00:00
|
|
|
cairo_paint (cr);
|
2010-08-15 16:52:05 +00:00
|
|
|
gdk_test_render_sync (gdk_window);
|
2007-11-20 15:03:28 +00:00
|
|
|
}
|
|
|
|
g_timer_stop (gtimer);
|
|
|
|
sync_time = g_timer_elapsed (gtimer, NULL);
|
|
|
|
sync_is_slower += sync_time > nosync_time * 1.5;
|
|
|
|
}
|
|
|
|
g_timer_destroy (gtimer);
|
|
|
|
g_assert (sync_is_slower > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_spin_button_arrows (void)
|
|
|
|
{
|
2010-05-24 20:31:36 +00:00
|
|
|
GtkWidget *child;
|
2007-11-20 15:03:28 +00:00
|
|
|
GtkWidget *window = gtk_test_create_simple_window ("Test Window", "Test: test_spin_button_arrows");
|
|
|
|
GtkWidget *spinner = gtk_spin_button_new_with_range (0, 100, 5);
|
|
|
|
gboolean simsuccess;
|
|
|
|
double oldval, newval;
|
2010-05-24 20:31:36 +00:00
|
|
|
|
2010-10-12 16:53:44 +00:00
|
|
|
gtk_window_set_has_resize_grip (GTK_WINDOW (window), FALSE);
|
|
|
|
|
2010-05-24 20:31:36 +00:00
|
|
|
child = gtk_bin_get_child (GTK_BIN (window));
|
|
|
|
gtk_container_add (GTK_CONTAINER (child), spinner);
|
2007-11-20 15:03:28 +00:00
|
|
|
gtk_widget_show (spinner);
|
|
|
|
gtk_widget_show_now (window);
|
|
|
|
gtk_test_slider_set_perc (spinner, 0);
|
|
|
|
/* check initial spinner value */
|
|
|
|
oldval = gtk_test_slider_get_value (spinner);
|
|
|
|
g_assert (oldval == 0);
|
|
|
|
/* check simple increment */
|
|
|
|
simsuccess = gtk_test_spin_button_click (GTK_SPIN_BUTTON (spinner), 1, TRUE);
|
|
|
|
g_assert (simsuccess == TRUE);
|
|
|
|
while (gtk_events_pending ()) /* let spin button timeout/idle handlers update */
|
|
|
|
gtk_main_iteration ();
|
|
|
|
newval = gtk_test_slider_get_value (spinner);
|
|
|
|
g_assert (newval > oldval);
|
|
|
|
/* check maximum warp */
|
|
|
|
simsuccess = gtk_test_spin_button_click (GTK_SPIN_BUTTON (spinner), 3, TRUE);
|
|
|
|
g_assert (simsuccess == TRUE);
|
|
|
|
while (gtk_events_pending ()) /* let spin button timeout/idle handlers update */
|
|
|
|
gtk_main_iteration ();
|
|
|
|
oldval = gtk_test_slider_get_value (spinner);
|
|
|
|
g_assert (oldval == 100);
|
|
|
|
/* check simple decrement */
|
|
|
|
oldval = gtk_test_slider_get_value (spinner);
|
|
|
|
simsuccess = gtk_test_spin_button_click (GTK_SPIN_BUTTON (spinner), 1, FALSE);
|
|
|
|
g_assert (simsuccess == TRUE);
|
|
|
|
while (gtk_events_pending ()) /* let spin button timeout/idle handlers update */
|
|
|
|
gtk_main_iteration ();
|
|
|
|
newval = gtk_test_slider_get_value (spinner);
|
|
|
|
g_assert (newval < oldval);
|
|
|
|
/* check minimum warp */
|
|
|
|
simsuccess = gtk_test_spin_button_click (GTK_SPIN_BUTTON (spinner), 3, FALSE);
|
|
|
|
g_assert (simsuccess == TRUE);
|
|
|
|
while (gtk_events_pending ()) /* let spin button timeout/idle handlers update */
|
|
|
|
gtk_main_iteration ();
|
|
|
|
oldval = gtk_test_slider_get_value (spinner);
|
|
|
|
g_assert (oldval == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char *argv[])
|
|
|
|
{
|
|
|
|
gtk_test_init (&argc, &argv);
|
|
|
|
gtk_test_register_all_types();
|
call g_test_init() from gtk_test_init().
2007-11-22 15:39:40 Tim Janik <timj@imendio.com>
* gtk/gtktestutils.c: call g_test_init() from gtk_test_init().
* gtk/tests/testing.c: use g_test_add_func() to register tests and use
g_test_run() to run the tests to integrate with the testing framework.
* gtk/tests/Makefile.am: removed exemplary testing rules.
* Makefile.am, gtk/tests/Makefile.am, gtk/Makefile.am:
* gtk/xdgmime/Makefile.am, gtk/theme-bits/Makefile.am:
* tests/Makefile.am, docs/reference/gdk-pixbuf/Makefile.am:
* docs/reference/gdk/Makefile.am, docs/reference/gtk/Makefile.am:
* docs/reference/Makefile.am, docs/tools/Makefile.am:
* docs/tutorial/Makefile.am, docs/faq/Makefile.am, docs/Makefile.am:
* gdk-pixbuf/pixops/Makefile.am, gdk-pixbuf/Makefile.am:
* demos/gtk-demo/Makefile.am, demos/Makefile.am:
* modules/input/Makefile.am, modules/printbackends/file/Makefile.am:
* modules/printbackends/test/Makefile.am, modules/printbackends/Makefile.am:
* modules/printbackends/cups/Makefile.am, modules/printbackends/lpr/Makefile.am:
* modules/engines/ms-windows/Theme/gtk-2.0/Makefile.am:
* modules/engines/ms-windows/Theme/Makefile.am:
* modules/engines/ms-windows/Makefile.am:
* modules/engines/Makefile.am, modules/engines/pixbuf/Makefile.am:
* modules/Makefile.am, m4macros/Makefile.am, perf/Makefile.am:
* contrib/Makefile.am, contrib/gdk-pixbuf-xlib/Makefile.am:
* gdk/directfb/Makefile.am, gdk/linux-fb/Makefile.am:
* gdk/quartz/Makefile.am, gdk/win32/rc/Makefile.am:
* gdk/win32/Makefile.am, gdk/x11/Makefile.am, gdk/Makefile.am:
include $(top_srcdir)/Makefile.decl, adapted EXTRA_DIST assignments.
svn path=/trunk/; revision=19033
2007-11-22 14:38:26 +00:00
|
|
|
g_test_add_func ("/ui-tests/text-access", test_text_access);
|
|
|
|
g_test_add_func ("/ui-tests/button-clicks", test_button_clicks);
|
|
|
|
g_test_add_func ("/ui-tests/keys-events", test_button_keys);
|
|
|
|
g_test_add_func ("/ui-tests/slider-ranges", test_slider_ranges);
|
|
|
|
g_test_add_func ("/ui-tests/xserver-sync", test_xserver_sync);
|
|
|
|
g_test_add_func ("/ui-tests/spin-button-arrows", test_spin_button_arrows);
|
|
|
|
return g_test_run();
|
2007-11-20 15:03:28 +00:00
|
|
|
}
|