tests: workarounds to keep treeview scrolling tests running

We can't safely examine allocations synchronously using
gtk_main_iteration(), as there might be not enough time for a new paint
clock tick to have expired and the allocation set on the widget.
Work this around adding g_usleep() calls before processing pending
mainloop events.
This commit is contained in:
Cosimo Cecchi 2013-02-18 19:14:13 -05:00
parent afc57cabf0
commit 4c130ac904

View File

@ -478,6 +478,17 @@ test_position (GtkTreeView *tree_view,
/* Testing scrolling to various positions with various alignments */ /* Testing scrolling to various positions with various alignments */
static void
ensure_layout (void)
{
/* HACK: sleep for more than one frame, to give the paint clock
* time to prepare the new layout */
g_usleep (100 * 1000);
while (gtk_events_pending ())
gtk_main_iteration ();
}
static void static void
scroll (ScrollFixture *fixture, scroll (ScrollFixture *fixture,
GtkTreePath *path, GtkTreePath *path,
@ -492,9 +503,7 @@ scroll (ScrollFixture *fixture,
gtk_widget_show_all (fixture->window); gtk_widget_show_all (fixture->window);
while (gtk_events_pending ()) ensure_layout ();
gtk_main_iteration ();
test_position (GTK_TREE_VIEW (fixture->tree_view), path, test_position (GTK_TREE_VIEW (fixture->tree_view), path,
use_align, row_align); use_align, row_align);
} }
@ -561,9 +570,7 @@ scroll_after_realize (ScrollFixture *fixture,
path, NULL, path, NULL,
use_align, row_align, 0.0); use_align, row_align, 0.0);
while (gtk_events_pending ()) ensure_layout ();
gtk_main_iteration ();
test_position (GTK_TREE_VIEW (fixture->tree_view), path, test_position (GTK_TREE_VIEW (fixture->tree_view), path,
use_align, row_align); use_align, row_align);
} }
@ -643,9 +650,7 @@ scroll_both_realize (ScrollFixture *fixture,
path, NULL, path, NULL,
use_align, row_align, 0.0); use_align, row_align, 0.0);
while (gtk_events_pending ()) ensure_layout ();
gtk_main_iteration ();
test_position (GTK_TREE_VIEW (fixture->tree_view), path, test_position (GTK_TREE_VIEW (fixture->tree_view), path,
use_align, row_align); use_align, row_align);
} }
@ -812,8 +817,7 @@ scroll_new_row (ScrollFixture *fixture,
column, column,
TRUE); TRUE);
while (gtk_events_pending ()) ensure_layout ();
gtk_main_iteration ();
/* Test position */ /* Test position */
test_position (GTK_TREE_VIEW (fixture->tree_view), scroll_path, test_position (GTK_TREE_VIEW (fixture->tree_view), scroll_path,
@ -865,8 +869,7 @@ scroll_new_row_tree (ScrollFixture *fixture,
scroll_path, NULL, FALSE, 0.0, 0.0); scroll_path, NULL, FALSE, 0.0, 0.0);
gtk_tree_path_free (scroll_path); gtk_tree_path_free (scroll_path);
while (gtk_events_pending ()) ensure_layout ();
gtk_main_iteration ();
/* Test position, the scroll bar must be at the end */ /* Test position, the scroll bar must be at the end */
g_assert (gtk_adjustment_get_value (vadjustment) == gtk_adjustment_get_upper (vadjustment) - gtk_adjustment_get_page_size (vadjustment)); g_assert (gtk_adjustment_get_value (vadjustment) == gtk_adjustment_get_upper (vadjustment) - gtk_adjustment_get_page_size (vadjustment));
@ -1013,6 +1016,9 @@ test_bug93584 (ScrollFixture *fixture,
row = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL); row = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL);
row -= 20; row -= 20;
while (gtk_events_pending ())
gtk_main_iteration ();
path = gtk_tree_path_new_from_indices (row, -1); path = gtk_tree_path_new_from_indices (row, -1);
scroll (fixture, path, TRUE, 0.5); scroll (fixture, path, TRUE, 0.5);
gtk_tree_path_free (path); gtk_tree_path_free (path);