[gtk+] Some window size test tweaks
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Some window size test tweaks
- Date: Sat, 4 May 2013 20:15:45 +0000 (UTC)
commit 96e0d9db72c4f8291bc58167fa77b2919fad217a
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Apr 28 17:50:01 2013 -0400
Some window size test tweaks
Draw a checkerboard pattern, and add an interactive mode that
waits for events before moving on. This makes it easier to see
when a size is wrong.
gtk/tests/window.c | 83 +++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 70 insertions(+), 13 deletions(-)
---
diff --git a/gtk/tests/window.c b/gtk/tests/window.c
index b249471..9aa631c 100644
--- a/gtk/tests/window.c
+++ b/gtk/tests/window.c
@@ -1,5 +1,7 @@
#include <gtk/gtk.h>
+static gboolean interactive = FALSE;
+
static gboolean
stop_main (gpointer data)
{
@@ -8,6 +10,36 @@ stop_main (gpointer data)
return G_SOURCE_REMOVE;
}
+static gboolean
+on_draw (GtkWidget *widget, cairo_t *cr)
+{
+ gint i, j;
+
+ for (i = 0; 20 * i < gtk_widget_get_allocated_width (widget); i++)
+ {
+ for (j = 0; 20 * j < gtk_widget_get_allocated_height (widget); j++)
+ {
+ if ((i + j) % 2 == 1)
+ cairo_set_source_rgb (cr, 1., 1., 1.);
+ else
+ cairo_set_source_rgb (cr, 0., 0., 0.);
+
+ cairo_rectangle (cr, 20. * i, 20. *j, 20., 20.);
+ cairo_fill (cr);
+ }
+ }
+
+ return FALSE;
+}
+
+static gboolean
+on_keypress (GtkWidget *widget)
+{
+ gtk_main_quit ();
+
+ return TRUE;
+}
+
static void
test_default_size (void)
{
@@ -16,33 +48,42 @@ test_default_size (void)
gint w, h;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ g_signal_connect (window, "draw", G_CALLBACK (on_draw), NULL);
+ if (interactive)
+ g_signal_connect (window, "key-press-event", G_CALLBACK (on_keypress), NULL);
+
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (window), box);
gtk_window_get_default_size (GTK_WINDOW (window), &w, &h);
- g_assert (w == -1 && h == -1);
+ g_assert_cmpint (w, ==, -1);
+ g_assert_cmpint (h, ==, -1);
gtk_window_set_default_size (GTK_WINDOW (window), 300, 300);
gtk_window_get_default_size (GTK_WINDOW (window), &w, &h);
- g_assert (w == 300 && h == 300);
+ g_assert_cmpint (w, ==, 300);
+ g_assert_cmpint (h, ==, 300);
gtk_window_get_size (GTK_WINDOW (window), &w, &h);
- g_assert (w == 300 && h == 300);
+ g_assert_cmpint (w, ==, 300);
+ g_assert_cmpint (h, ==, 300);
gtk_widget_show_all (window);
- g_timeout_add (1000, stop_main, NULL);
+ if (!interactive)
+ g_timeout_add (200, stop_main, NULL);
gtk_main ();
gtk_window_get_size (GTK_WINDOW (window), &w, &h);
- g_assert (w == 300 && h == 300);
+ g_assert_cmpint (w, ==, 300);
+ g_assert_cmpint (h, ==, 300);
- g_assert (gtk_widget_get_allocated_width (window) == 300);
- g_assert (gtk_widget_get_allocated_height (window) == 300);
+ g_assert_cmpint (gtk_widget_get_allocated_width (window), ==, 300);
+ g_assert_cmpint (gtk_widget_get_allocated_height (window), ==, 300);
- g_assert (gtk_widget_get_allocated_width (box) == 300);
- g_assert (gtk_widget_get_allocated_height (box) == 300);
+ g_assert_cmpint (gtk_widget_get_allocated_width (box), ==, 300);
+ g_assert_cmpint (gtk_widget_get_allocated_height (box), ==, 300);
gtk_widget_destroy (window);
}
@@ -55,6 +96,10 @@ test_resize (void)
gint w, h;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ g_signal_connect (window, "draw", G_CALLBACK (on_draw), NULL);
+ if (interactive)
+ g_signal_connect (window, "key-press-event", G_CALLBACK (on_keypress), NULL);
+
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (window), box);
@@ -62,19 +107,23 @@ test_resize (void)
gtk_widget_show_all (window);
- g_timeout_add (1000, stop_main, NULL);
+ if (!interactive)
+ g_timeout_add (200, stop_main, NULL);
gtk_main ();
gtk_window_get_size (GTK_WINDOW (window), &w, &h);
- g_assert (w == 400 && h == 200);
+ g_assert_cmpint (w, ==, 400);
+ g_assert_cmpint (h, ==, 200);
gtk_window_resize (GTK_WINDOW (window), 200, 400);
- g_timeout_add (1000, stop_main, NULL);
+ if (!interactive)
+ g_timeout_add (200, stop_main, NULL);
gtk_main ();
gtk_window_get_size (GTK_WINDOW (window), &w, &h);
- g_assert (w == 200 && h == 400);
+ g_assert_cmpint (w, ==, 200);
+ g_assert_cmpint (h, ==, 400);
gtk_widget_destroy (window);
}
@@ -82,8 +131,16 @@ test_resize (void)
int
main (int argc, char *argv[])
{
+ gint i;
+
gtk_test_init (&argc, &argv);
+ for (i = 0; i < argc; i++)
+ {
+ if (g_strcmp0 (argv[i], "--interactive") == 0)
+ interactive = TRUE;
+ }
+
g_test_add_func ("/window/default-size", test_default_size);
g_test_add_func ("/window/resize", test_resize);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]