From 1f17efb81c55f9b24cc002dd9a1d76a6e4613fe4 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 27 Apr 2013 13:34:18 -0400 Subject: [PATCH] Add some tests for GtkWindow These tests may have some assumptions on reasonable window manager behaviour. For now, we just test that the default size of the window ends up as the allocated size of the content. This test currently fails with client-side decorations, because we are not properly discriminating between overall window size and content size. --- gtk/tests/Makefile.am | 4 ++++ gtk/tests/window.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 gtk/tests/window.c diff --git a/gtk/tests/Makefile.am b/gtk/tests/Makefile.am index 0bbd4f5197..7bcd7c32bd 100644 --- a/gtk/tests/Makefile.am +++ b/gtk/tests/Makefile.am @@ -176,6 +176,10 @@ TEST_PROGS += objects-finalize objects_finalize_SOURCES = objects-finalize.c objects_finalize_LDADD = $(progs_ldadd) +TEST_PROGS += window +window_SOURCES = window.c +window_LDADD = $(progs_ldadd) + EXTRA_DIST += \ file-chooser-test-dir/empty \ file-chooser-test-dir/text.txt diff --git a/gtk/tests/window.c b/gtk/tests/window.c new file mode 100644 index 0000000000..1aecdfc790 --- /dev/null +++ b/gtk/tests/window.c @@ -0,0 +1,50 @@ +#include + +static gboolean +stop_main (gpointer data) +{ + gtk_main_quit (); + + return G_SOURCE_REMOVE; +} + +static void +test_default_size (void) +{ + GtkWidget *window; + GtkWidget *box; + gint w, h; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + 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); + + 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); + + gtk_widget_show_all (window); + + g_timeout_add (1000, stop_main, NULL); + gtk_main (); + + g_assert (gtk_widget_get_allocated_width (window) == 300); + g_assert (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); +} + +int +main (int argc, char *argv[]) +{ + gtk_test_init (&argc, &argv); + + g_test_add_func ("/window/default-size", test_default_size); + + return g_test_run (); +}