1 /* Scrolling test suite for GtkTreeView
2 * Copyright (C) 2006 Kristian Rietveld <kris@gtk.org>
3 * Copyright (C) 2007 Imendio AB, Kristian Rietveld
4 * Copyright (C) 2009 Kristian Rietveld <kris@gtk.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 /* Original v1.0 -- December 26, 2006
23 * Conversion to GLib/GTK+ test framework during December, 2007
30 #define VIEW_WIDTH 320
31 #define VIEW_HEIGHT 240
34 #define BIG_N_ROWS N_ROWS * 100
38 * - Test that nothing happens if the row is fully visible.
39 * - The tests are dependent on the theme/font (size measurements,
41 * - Convert to proper GTK+ coding style.
42 * - Briefly test scrolling in tree stores as well.
46 /* Constructing models for testing */
48 create_model (gboolean constant)
55 store = gtk_list_store_new (1, G_TYPE_STRING);
57 for (i = 0; i < N_ROWS; i++) {
58 gtk_list_store_append (store, &iter);
59 if (constant || i % 2 == 0)
60 gtk_list_store_set (store, &iter, 0, "Foo", -1);
62 gtk_list_store_set (store, &iter, 0, "Sliff\nSloff\nBleh", -1);
65 return GTK_TREE_MODEL (store);
69 create_big_model (gboolean constant)
76 store = gtk_list_store_new (1, G_TYPE_STRING);
78 for (i = 0; i < BIG_N_ROWS; i++) {
79 gtk_list_store_append (store, &iter);
80 if (constant || i % 2 == 0)
81 gtk_list_store_set (store, &iter, 0, "Foo", -1);
83 gtk_list_store_set (store, &iter, 0, "Sliff\nSloff\nBleh", -1);
86 return GTK_TREE_MODEL (store);
101 scroll_fixture_setup (ScrollFixture *fixture,
103 gconstpointer test_data)
106 GtkCellRenderer *renderer;
107 GtkTreeViewColumn *column;
109 fixture->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
111 sw = gtk_scrolled_window_new (NULL, NULL);
112 gtk_container_add (GTK_CONTAINER (fixture->window), sw);
114 fixture->tree_view = gtk_tree_view_new_with_model (model);
115 g_object_unref (model);
116 gtk_widget_set_size_request (fixture->tree_view, VIEW_WIDTH, VIEW_HEIGHT);
118 renderer = gtk_cell_renderer_text_new ();
119 g_object_set (renderer, "editable", TRUE, NULL);
120 column = gtk_tree_view_column_new_with_attributes ("Title",
125 gtk_tree_view_append_column (GTK_TREE_VIEW (fixture->tree_view), column);
126 gtk_container_add (GTK_CONTAINER (sw), fixture->tree_view);
129 /* sets up a fixture with a model with constant row heights */
131 scroll_fixture_constant_setup (ScrollFixture *fixture,
132 gconstpointer test_data)
134 scroll_fixture_setup (fixture, create_model (TRUE), test_data);
137 /* sets up a fixture with a model with varying row heights */
139 scroll_fixture_mixed_setup (ScrollFixture *fixture,
140 gconstpointer test_data)
142 scroll_fixture_setup (fixture, create_model (FALSE), test_data);
145 /* sets up a fixture with a large model with constant row heights */
147 scroll_fixture_constant_big_setup (ScrollFixture *fixture,
148 gconstpointer test_data)
150 scroll_fixture_setup (fixture, create_big_model (TRUE), test_data);
153 /* sets up a fixture with a large model with varying row heights */
155 scroll_fixture_mixed_big_setup (ScrollFixture *fixture,
156 gconstpointer test_data)
158 scroll_fixture_setup (fixture, create_big_model (FALSE), test_data);
161 /* sets up a fixture with only a single row for the "single row scroll" test */
163 scroll_fixture_single_setup (ScrollFixture *fixture,
164 gconstpointer test_data)
167 GtkTreeIter iter, child;
169 store = gtk_tree_store_new (1, G_TYPE_STRING);
171 gtk_tree_store_append (store, &iter, NULL);
172 gtk_tree_store_set (store, &iter, 0, "Foo", -1);
174 gtk_tree_store_append (store, &child, &iter);
175 gtk_tree_store_set (store, &child, 0, "Two\nLines", -1);
177 /* The teardown will also destroy the model */
178 scroll_fixture_setup (fixture, GTK_TREE_MODEL (store), test_data);
181 /* sets up a fixture with a tree store */
183 scroll_fixture_tree_setup (ScrollFixture *fixture,
184 gconstpointer test_data)
187 GtkTreeIter iter, child;
190 store = gtk_tree_store_new (1, G_TYPE_STRING);
192 gtk_tree_store_append (store, &iter, NULL);
193 gtk_tree_store_set (store, &iter, 0, "Root node", -1);
195 for (i = 0; i < 5; i++) {
196 gtk_tree_store_append (store, &child, &iter);
197 gtk_tree_store_set (store, &child, 0, "Child node", -1);
200 for (i = 0; i < 5; i++) {
201 gtk_tree_store_append (store, &iter, NULL);
202 gtk_tree_store_set (store, &iter, 0, "Other node", -1);
205 /* The teardown will also destroy the model */
206 scroll_fixture_setup (fixture, GTK_TREE_MODEL (store), test_data);
210 scroll_fixture_teardown (ScrollFixture *fixture,
211 gconstpointer test_data)
213 gtk_widget_destroy (fixture->window);
217 * Position check and helpers.
227 get_row_start_for_index (GtkTreeView *tree_view, int index)
229 gint height1, height2;
234 path = gtk_tree_path_new_from_indices (0, -1);
235 gtk_tree_view_get_background_area (tree_view, path, NULL, &rect);
236 height1 = rect.height;
238 gtk_tree_path_next (path);
239 gtk_tree_view_get_background_area (tree_view, path, NULL, &rect);
240 height2 = rect.height;
241 gtk_tree_path_free (path);
243 row_start = (index / 2) * height1 + (index / 2) * height2;
245 row_start += height1;
251 get_pos_from_path (GtkTreeView *tree_view,
258 row_start = get_row_start_for_index (tree_view,
259 gtk_tree_path_get_indices (path)[0]);
261 if (row_start + row_height < vadj->page_size)
264 if (row_start >= vadj->upper - vadj->page_size)
271 test_position_with_align (GtkTreeView *tree_view,
278 gboolean passed = TRUE;
279 GtkAdjustment *vadj = gtk_tree_view_get_vadjustment (tree_view);
281 /* Switch on row-align: 0.0, 0.5, 1.0 */
282 switch ((int)(row_align * 2.)) {
284 if (pos == POS_TOP || pos == POS_CENTER) {
285 /* The row in question is the first row
287 * - rect.y should be zero
288 * - dy should be equal to the top
289 * y coordinate of the row.
293 if (vadj->value != row_start)
296 /* The row can be anywhere at the last
297 * page of the tree view.
298 * - dy is set to the start of the
301 if (vadj->value != vadj->upper - vadj->page_size)
309 && row_start < vadj->page_size / 2) {
310 /* For the first half of the top view we can't
311 * center the row in the view, instead we
312 * show the first page.
313 * - dy should be zero
315 if (vadj->value != 0)
317 } else if (pos == POS_BOTTOM
318 && row_start >= vadj->upper - vadj->page_size / 2) {
319 /* For the last half of the bottom view we
320 * can't center the row in the view, instead
321 * we show the last page.
322 * - dy should be the start of the
325 if (vadj->value != vadj->upper - vadj->page_size)
328 /* The row is located in the middle of
330 * - top y coordinate is equal to
331 * middle of the view minus
332 * half the height of the row.
333 * (ie. the row's center is at the
334 * center of the view).
336 if (row_y != (int)(vadj->page_size / 2 - row_height / 2))
343 if (pos == POS_TOP) {
344 /* The row can be anywhere on the
345 * first page of the tree view.
348 if (vadj->value != 0)
350 } else if (pos == POS_CENTER || pos == POS_BOTTOM) {
351 /* The row is the last row visible in the
353 * - rect.y is set to the top of the
355 * - row_start is greater than page_size
356 * (ie we are not on the first page).
357 * - dy is greater than zero
359 if (row_start < vadj->page_size
360 && row_start + row_height < vadj->page_size)
362 if (vadj->value <= 0)
364 if (row_y != vadj->page_size - row_height)
374 test_position_without_align (GtkTreeView *tree_view,
378 GtkAdjustment *vadj = gtk_tree_view_get_vadjustment (tree_view);
380 /* Without align the tree view does as less work as possible,
381 * so basically we only have to check whether the row
382 * is visible on the screen.
384 if (vadj->value <= row_start
385 && vadj->value + vadj->page_size >= row_start + row_height)
392 test_position (GtkTreeView *tree_view,
404 /* Get the location of the path we scrolled to */
405 gtk_tree_view_get_background_area (GTK_TREE_VIEW (tree_view),
408 row_start = get_row_start_for_index (GTK_TREE_VIEW (tree_view),
409 gtk_tree_path_get_indices (path)[0]);
412 pos = get_pos_from_path (GTK_TREE_VIEW (tree_view),
414 gtk_tree_view_get_vadjustment (GTK_TREE_VIEW (tree_view)));
416 /* This is only tested for during test_single() */
417 model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
418 if (gtk_tree_model_iter_n_children (model, NULL) == 1) {
419 GtkTreePath *tmppath;
421 /* Test nothing is dangling at the bottom; read
422 * description for test_single() for more information.
425 /* FIXME: hardcoded width */
426 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (tree_view), 0, GTK_WIDGET (tree_view)->allocation.height - 30, &tmppath, NULL, NULL, NULL)) {
427 g_assert_not_reached ();
428 gtk_tree_path_free (tmppath);
432 path_str = gtk_tree_path_to_string (path);
434 g_assert (test_position_with_align (tree_view, pos, rect.y,
435 row_start, rect.height, row_align));
437 g_assert (test_position_without_align (tree_view, row_start, rect.height));
448 /* Testing scrolling to various positions with various alignments */
451 scroll (ScrollFixture *fixture,
456 gtk_tree_view_set_cursor (GTK_TREE_VIEW (fixture->tree_view), path,
458 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (fixture->tree_view),
460 use_align, row_align, 0.0);
462 gtk_widget_show_all (fixture->window);
464 while (gtk_events_pending ())
465 gtk_main_iteration ();
467 test_position (GTK_TREE_VIEW (fixture->tree_view), path,
468 use_align, row_align, 0.0);
472 scroll_no_align (ScrollFixture *fixture,
473 gconstpointer test_data)
477 path = gtk_tree_path_new_from_string (test_data);
478 scroll (fixture, path, FALSE, 0.0);
479 gtk_tree_path_free (path);
483 scroll_align_0_0 (ScrollFixture *fixture,
484 gconstpointer test_data)
488 path = gtk_tree_path_new_from_string (test_data);
489 scroll (fixture, path, TRUE, 0.0);
490 gtk_tree_path_free (path);
494 scroll_align_0_5 (ScrollFixture *fixture,
495 gconstpointer test_data)
499 path = gtk_tree_path_new_from_string (test_data);
500 scroll (fixture, path, TRUE, 0.5);
501 gtk_tree_path_free (path);
505 scroll_align_1_0 (ScrollFixture *fixture,
506 gconstpointer test_data)
510 path = gtk_tree_path_new_from_string (test_data);
511 scroll (fixture, path, TRUE, 1.0);
512 gtk_tree_path_free (path);
517 scroll_after_realize (ScrollFixture *fixture,
522 gtk_widget_show_all (fixture->window);
524 while (gtk_events_pending ())
525 gtk_main_iteration ();
527 gtk_tree_view_set_cursor (GTK_TREE_VIEW (fixture->tree_view), path,
529 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (fixture->tree_view),
531 use_align, row_align, 0.0);
533 while (gtk_events_pending ())
534 gtk_main_iteration ();
536 test_position (GTK_TREE_VIEW (fixture->tree_view), path,
537 use_align, row_align, 0.0);
541 scroll_after_no_align (ScrollFixture *fixture,
542 gconstpointer test_data)
546 path = gtk_tree_path_new_from_string (test_data);
547 scroll_after_realize (fixture, path, FALSE, 0.0);
548 gtk_tree_path_free (path);
552 scroll_after_align_0_0 (ScrollFixture *fixture,
553 gconstpointer test_data)
557 path = gtk_tree_path_new_from_string (test_data);
558 scroll_after_realize (fixture, path, TRUE, 0.0);
559 gtk_tree_path_free (path);
563 scroll_after_align_0_5 (ScrollFixture *fixture,
564 gconstpointer test_data)
568 path = gtk_tree_path_new_from_string (test_data);
569 scroll_after_realize (fixture, path, TRUE, 0.5);
570 gtk_tree_path_free (path);
574 scroll_after_align_1_0 (ScrollFixture *fixture,
575 gconstpointer test_data)
579 path = gtk_tree_path_new_from_string (test_data);
580 scroll_after_realize (fixture, path, TRUE, 1.0);
581 gtk_tree_path_free (path);
586 scroll_both_realize (ScrollFixture *fixture,
593 gtk_widget_show_all (fixture->window);
596 end = gtk_tree_path_new_from_indices (999, -1);
598 gtk_tree_view_set_cursor (GTK_TREE_VIEW (fixture->tree_view), end,
600 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (fixture->tree_view),
602 use_align, row_align, 0.0);
603 gtk_tree_path_free (end);
605 while (gtk_events_pending ())
606 gtk_main_iteration ();
608 /* Scroll to final position */
609 gtk_tree_view_set_cursor (GTK_TREE_VIEW (fixture->tree_view), path,
611 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (fixture->tree_view),
613 use_align, row_align, 0.0);
615 while (gtk_events_pending ())
616 gtk_main_iteration ();
618 test_position (GTK_TREE_VIEW (fixture->tree_view), path,
619 use_align, row_align, 0.0);
623 scroll_both_no_align (ScrollFixture *fixture,
624 gconstpointer test_data)
628 path = gtk_tree_path_new_from_string (test_data);
629 scroll_both_realize (fixture, path, FALSE, 0.0);
630 gtk_tree_path_free (path);
634 scroll_both_align_0_0 (ScrollFixture *fixture,
635 gconstpointer test_data)
639 path = gtk_tree_path_new_from_string (test_data);
640 scroll_both_realize (fixture, path, TRUE, 0.0);
641 gtk_tree_path_free (path);
645 scroll_both_align_0_5 (ScrollFixture *fixture,
646 gconstpointer test_data)
650 path = gtk_tree_path_new_from_string (test_data);
651 scroll_both_realize (fixture, path, TRUE, 0.5);
652 gtk_tree_path_free (path);
656 scroll_both_align_1_0 (ScrollFixture *fixture,
657 gconstpointer test_data)
661 path = gtk_tree_path_new_from_string (test_data);
662 scroll_both_realize (fixture, path, TRUE, 1.0);
663 gtk_tree_path_free (path);
666 /* Testing scrolling to a newly created row */
668 create_new_row (GtkListStore *store,
675 gtk_list_store_prepend (store, iter);
679 /* Add a row in the middle of the visible area */
680 gtk_list_store_insert (store, iter, 4);
684 /* Add a row which is not completely visible */
685 gtk_list_store_insert (store, iter, 8);
689 /* Add a row in the middle */
690 gtk_list_store_insert (store, iter, 500);
695 gtk_list_store_append (store, iter);
699 gtk_list_store_set (store, iter, 0, "New...", -1);
703 scroll_new_row_editing_started (GtkCellRenderer *cell,
704 GtkCellEditable *editable,
708 GtkWidget **widget = user_data;
710 *widget = GTK_WIDGET (editable);
714 test_editable_position (GtkWidget *tree_view,
716 GtkTreePath *cursor_path)
721 gtk_tree_view_get_background_area (GTK_TREE_VIEW (tree_view),
722 cursor_path, NULL, &rect);
724 vadj = gtk_tree_view_get_vadjustment (GTK_TREE_VIEW (tree_view));
726 /* There are all in bin_window coordinates */
727 g_assert (editable->allocation.y == rect.y + ((rect.height - editable->allocation.height) / 2));
731 scroll_new_row (ScrollFixture *fixture,
732 gconstpointer test_data)
734 GtkTreeIter scroll_iter;
735 GtkTreePath *scroll_path;
738 GtkTreeViewColumn *column;
741 /* The aim of this test is creating a new row at several places,
742 * and immediately put the cursor on it. TreeView should correctly
743 * scroll to the row and show the editable widget.
748 g_test_bug ("81627");
750 gtk_widget_show_all (fixture->window);
752 while (gtk_events_pending ())
753 gtk_main_iteration ();
755 /* Create the new row and scroll to it */
756 model = gtk_tree_view_get_model (GTK_TREE_VIEW (fixture->tree_view));
757 create_new_row (GTK_LIST_STORE (model), GPOINTER_TO_INT (test_data),
760 /* Set up a signal handler to acquire the editable widget */
761 column = gtk_tree_view_get_column (GTK_TREE_VIEW (fixture->tree_view), 0);
762 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
764 g_signal_connect (G_OBJECT (renderers->data), "editing-started",
765 G_CALLBACK (scroll_new_row_editing_started),
768 /* Now set the cursor on the path and start editing */
769 scroll_path = gtk_tree_model_get_path (model, &scroll_iter);
770 gtk_tree_view_set_cursor (GTK_TREE_VIEW (fixture->tree_view),
775 while (gtk_events_pending ())
776 gtk_main_iteration ();
779 test_position (GTK_TREE_VIEW (fixture->tree_view), scroll_path,
781 test_editable_position (fixture->tree_view, editable, scroll_path);
783 gtk_tree_path_free (scroll_path);
787 scroll_new_row_tree (ScrollFixture *fixture,
788 gconstpointer test_data)
791 GtkAdjustment *vadjustment;
794 /* The goal of this test is to append new rows at the end of a tree
795 * store and immediately scroll to them. If there is a parent
796 * node with a couple of childs in the "area above" to explore,
797 * this used to lead to unexpected results due to a bug.
799 * This issue has been reported by Miroslav Rajcic on
800 * gtk-app-devel-list:
801 * http://mail.gnome.org/archives/gtk-app-devel-list/2008-December/msg00068.html
804 gtk_widget_show_all (fixture->window);
806 gtk_tree_view_expand_all (GTK_TREE_VIEW (fixture->tree_view));
808 while (gtk_events_pending ())
809 gtk_main_iteration ();
811 model = gtk_tree_view_get_model (GTK_TREE_VIEW (fixture->tree_view));
812 vadjustment = gtk_tree_view_get_vadjustment (GTK_TREE_VIEW (fixture->tree_view));
814 for (i = 0; i < 5; i++) {
815 GtkTreeIter scroll_iter;
816 GtkTreePath *scroll_path;
818 gtk_tree_store_append (GTK_TREE_STORE (model), &scroll_iter,
820 gtk_tree_store_set (GTK_TREE_STORE (model), &scroll_iter,
823 scroll_path = gtk_tree_model_get_path (model, &scroll_iter);
824 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (fixture->tree_view),
825 scroll_path, NULL, FALSE, 0.0, 0.0);
826 gtk_tree_path_free (scroll_path);
828 while (gtk_events_pending ())
829 gtk_main_iteration ();
831 /* Test position, the scroll bar must be at the end */
832 g_assert (vadjustment->value == vadjustment->upper - vadjustment->page_size);
836 /* Test for GNOME bugzilla bug 359231; tests "recovery when removing a bunch of
837 * rows at the bottom.
840 test_bug316689 (ScrollFixture *fixture,
841 gconstpointer test_data)
848 /* The aim of this test is to scroll to the bottom of a TreeView,
849 * remove at least one page_size of items and check if TreeView
850 * correctly corrects the scroll bar (else they will look "broken").
855 g_test_bug ("316689");
857 /* Scroll to some place close to the end */
858 path = gtk_tree_path_new_from_indices (N_ROWS - 4, -1);
859 scroll (fixture, path, FALSE, 0.0);
860 gtk_tree_path_free (path);
862 /* No need for a while events pending loop here, scroll() does this for us.
864 * We now remove a bunch of rows, wait for events to process and then
865 * check the adjustments to see if the TreeView gracefully recovered.
867 model = gtk_tree_view_get_model (GTK_TREE_VIEW (fixture->tree_view));
869 while (gtk_tree_model_iter_nth_child (model, &iter, NULL, N_ROWS - 15))
870 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
872 while (gtk_events_pending ())
873 gtk_main_iteration ();
875 vadj = gtk_tree_view_get_vadjustment (GTK_TREE_VIEW (fixture->tree_view));
877 g_assert (vadj->value + vadj->page_size <= vadj->upper);
878 g_assert (vadj->value == vadj->upper - vadj->page_size);
882 /* Test for GNOME bugzilla bug 359231 */
884 test_bug359231 (void)
887 int height1, height2;
889 GtkTreeIter iter, child;
892 ScrollFixture *fixture;
895 g_test_bug ("359231");
897 /* Create model (GtkTreeStore in this case) */
898 store = gtk_tree_store_new (1, G_TYPE_STRING);
900 gtk_tree_store_append (store, &iter, NULL);
901 gtk_tree_store_set (store, &iter, 0, "Foo", -1);
903 for (i = 0; i < 4; i++) {
904 gtk_tree_store_append (store, &child, &iter);
905 gtk_tree_store_set (store, &child, 0, "Two\nLines", -1);
908 fixture = g_new0 (ScrollFixture, 1);
909 scroll_fixture_setup (fixture, GTK_TREE_MODEL (store), NULL);
910 gtk_widget_show_all (fixture->window);
912 while (gtk_events_pending ())
913 gtk_main_iteration ();
915 /* Prepend some rows at the top, expand */
916 gtk_tree_store_prepend (store, &iter, NULL);
917 gtk_tree_store_set (store, &iter, 0, "Foo", -1);
919 gtk_tree_store_prepend (store, &child, &iter);
920 gtk_tree_store_set (store, &child, 0, "Two\nLines", -1);
922 gtk_tree_view_expand_all (GTK_TREE_VIEW (fixture->tree_view));
924 while (gtk_events_pending ())
925 gtk_main_iteration ();
927 /* Test if height of row 0:0 is correct */
928 path = gtk_tree_path_new_from_indices (0, -1);
929 gtk_tree_view_get_background_area (GTK_TREE_VIEW (fixture->tree_view),
931 height1 = rect.height;
933 gtk_tree_path_down (path);
934 gtk_tree_view_get_background_area (GTK_TREE_VIEW (fixture->tree_view),
936 height2 = rect.height;
937 gtk_tree_path_free (path);
939 g_assert (height2 > height1);
941 /* Clean up; the tear down also cleans up the model */
942 scroll_fixture_teardown (fixture, NULL);
945 /* Infrastructure for automatically adding tests */
954 test_type_string (int test_type)
958 return "before-realize";
961 return "after-realize";
971 align_string (gboolean use_align,
977 return g_strdup ("no-align");
979 ret = g_strdup_printf ("align-%1.1f", row_align);
984 add_test (const char *path,
989 void (* setup) (ScrollFixture *, gconstpointer),
990 void (* scroll_func) (ScrollFixture *, gconstpointer))
995 align = align_string (use_align, row_align);
997 test_path = g_strdup_printf ("/TreeView/scrolling/%s/%s-height/path-%s-%s",
998 test_type_string (test_type),
999 mixed ? "mixed" : "constant",
1003 g_test_add (test_path, ScrollFixture, path,
1004 setup, scroll_func, scroll_fixture_teardown);
1010 add_tests (gboolean mixed,
1014 void (*scroll_func) (ScrollFixture *, gconstpointer))
1016 void (* setup) (ScrollFixture *, gconstpointer);
1019 setup = scroll_fixture_mixed_setup;
1021 setup = scroll_fixture_constant_setup;
1023 add_test ("0", mixed, test_type, use_align, row_align, setup, scroll_func);
1024 add_test ("2", mixed, test_type, use_align, row_align, setup, scroll_func);
1025 add_test ("5", mixed, test_type, use_align, row_align, setup, scroll_func);
1026 /* We scroll to 8 to test a partial visible row. The 8 is
1027 * based on my font setting of "Vera Sans 11" and
1028 * the separators set to 0. (This should be made dynamic; FIXME).
1030 add_test ("8", mixed, test_type, use_align, row_align, setup, scroll_func);
1031 add_test ("10", mixed, test_type, use_align, row_align, setup, scroll_func);
1032 add_test ("250", mixed, test_type, use_align, row_align, setup, scroll_func);
1033 add_test ("500", mixed, test_type, use_align, row_align, setup, scroll_func);
1034 add_test ("750", mixed, test_type, use_align, row_align, setup, scroll_func);
1035 add_test ("990", mixed, test_type, use_align, row_align, setup, scroll_func);
1036 add_test ("991", mixed, test_type, use_align, row_align, setup, scroll_func);
1037 add_test ("995", mixed, test_type, use_align, row_align, setup, scroll_func);
1038 add_test ("997", mixed, test_type, use_align, row_align, setup, scroll_func);
1039 add_test ("999", mixed, test_type, use_align, row_align, setup, scroll_func);
1043 main (int argc, char **argv)
1045 gtk_test_init (&argc, &argv);
1047 /* Scrolls before realization */
1048 add_tests (FALSE, BEFORE, FALSE, 0.0, scroll_no_align);
1049 if (g_test_thorough ())
1050 add_tests (TRUE, BEFORE, FALSE, 0.0, scroll_no_align);
1052 add_tests (FALSE, BEFORE, TRUE, 0.0, scroll_align_0_0);
1053 if (g_test_thorough ())
1054 add_tests (TRUE, BEFORE, TRUE, 0.0, scroll_align_0_0);
1056 add_tests (FALSE, BEFORE, TRUE, 0.5, scroll_align_0_5);
1057 if (g_test_thorough ())
1058 add_tests (TRUE, BEFORE, TRUE, 0.5, scroll_align_0_5);
1060 add_tests (FALSE, BEFORE, TRUE, 1.0, scroll_align_1_0);
1061 if (g_test_thorough ())
1062 add_tests (TRUE, BEFORE, TRUE, 1.0, scroll_align_1_0);
1064 /* Scrolls after realization */
1065 add_tests (FALSE, AFTER, FALSE, 0.0, scroll_after_no_align);
1066 if (g_test_thorough ())
1067 add_tests (TRUE, AFTER, FALSE, 0.0, scroll_after_no_align);
1069 add_tests (FALSE, AFTER, TRUE, 0.0, scroll_after_align_0_0);
1070 if (g_test_thorough ())
1071 add_tests (TRUE, AFTER, TRUE, 0.0, scroll_after_align_0_0);
1073 add_tests (FALSE, AFTER, TRUE, 0.5, scroll_after_align_0_5);
1074 if (g_test_thorough ())
1075 add_tests (TRUE, AFTER, TRUE, 0.5, scroll_after_align_0_5);
1077 add_tests (FALSE, AFTER, TRUE, 1.0, scroll_after_align_1_0);
1078 if (g_test_thorough ())
1079 add_tests (TRUE, AFTER, TRUE, 1.0, scroll_after_align_1_0);
1081 /* Scroll to end before realization, to a real position after */
1082 if (g_test_thorough ()) {
1083 add_tests (FALSE, BOTH, FALSE, 0.0, scroll_both_no_align);
1084 add_tests (TRUE, BOTH, FALSE, 0.0, scroll_both_no_align);
1086 add_tests (FALSE, BOTH, TRUE, 0.0, scroll_both_align_0_0);
1087 add_tests (TRUE, BOTH, TRUE, 0.0, scroll_both_align_0_0);
1089 add_tests (FALSE, BOTH, TRUE, 0.5, scroll_both_align_0_5);
1090 add_tests (TRUE, BOTH, TRUE, 0.5, scroll_both_align_0_5);
1092 add_tests (FALSE, BOTH, TRUE, 1.0, scroll_both_align_1_0);
1093 add_tests (TRUE, BOTH, TRUE, 1.0, scroll_both_align_1_0);
1096 /* Test different alignments in view with single row */
1097 g_test_add ("/TreeView/scrolling/single-row/no-align",
1099 scroll_fixture_single_setup,
1101 scroll_fixture_teardown);
1102 g_test_add ("/TreeView/scrolling/single-row/align-0.0",
1104 scroll_fixture_single_setup,
1106 scroll_fixture_teardown);
1107 g_test_add ("/TreeView/scrolling/single-row/align-0.5",
1109 scroll_fixture_single_setup,
1111 scroll_fixture_teardown);
1112 g_test_add ("/TreeView/scrolling/single-row/align-1.0",
1114 scroll_fixture_single_setup,
1116 scroll_fixture_teardown);
1118 /* Test scrolling in a very large model; also very slow */
1119 if (g_test_slow ()) {
1120 g_test_add ("/TreeView/scrolling/large-model/constant-height/middle-no-align",
1121 ScrollFixture, "50000",
1122 scroll_fixture_constant_big_setup,
1124 scroll_fixture_teardown);
1125 g_test_add ("/TreeView/scrolling/large-model/constant-height/end-no-align",
1126 ScrollFixture, "99999",
1127 scroll_fixture_constant_big_setup,
1129 scroll_fixture_teardown);
1131 g_test_add ("/TreeView/scrolling/large-model/mixed-height/middle-no-align",
1132 ScrollFixture, "50000",
1133 scroll_fixture_mixed_big_setup,
1135 scroll_fixture_teardown);
1136 g_test_add ("/TreeView/scrolling/large-model/mixed-height/end-no-align",
1137 ScrollFixture, "99999",
1138 scroll_fixture_mixed_big_setup,
1140 scroll_fixture_teardown);
1143 /* Test scrolling to a newly created row */
1144 g_test_add ("/TreeView/scrolling/new-row/path-0", ScrollFixture,
1145 GINT_TO_POINTER (0),
1146 scroll_fixture_constant_setup,
1148 scroll_fixture_teardown);
1149 g_test_add ("/TreeView/scrolling/new-row/path-4", ScrollFixture,
1150 GINT_TO_POINTER (4),
1151 scroll_fixture_constant_setup,
1153 scroll_fixture_teardown);
1154 /* We scroll to 8 to test a partial visible row. The 8 is
1155 * based on my font setting of "Vera Sans 11" and
1156 * the separators set to 0. (This should be made dynamic; FIXME).
1158 g_test_add ("/TreeView/scrolling/new-row/path-8", ScrollFixture,
1159 GINT_TO_POINTER (8),
1160 scroll_fixture_constant_setup,
1162 scroll_fixture_teardown);
1163 g_test_add ("/TreeView/scrolling/new-row/path-500", ScrollFixture,
1164 GINT_TO_POINTER (500),
1165 scroll_fixture_constant_setup,
1167 scroll_fixture_teardown);
1168 g_test_add ("/TreeView/scrolling/new-row/path-999", ScrollFixture,
1169 GINT_TO_POINTER (999),
1170 scroll_fixture_constant_setup,
1172 scroll_fixture_teardown);
1174 g_test_add ("/TreeView/scrolling/new-row/tree", ScrollFixture,
1176 scroll_fixture_tree_setup,
1177 scroll_new_row_tree,
1178 scroll_fixture_teardown);
1181 g_test_add ("/TreeView/scrolling/specific/bug-316689",
1182 ScrollFixture, NULL,
1183 scroll_fixture_constant_setup, test_bug316689,
1184 scroll_fixture_teardown);
1185 g_test_add_func ("/TreeView/scrolling/specific/bug-359231",
1188 return g_test_run ();