gridview: Add tests for tile split

These tests are reusing the section model plumbing
of the listitemmanager tests, and just check that
splitting tiles according to a certain number of
columns works
This commit is contained in:
Matthias Clasen
2023-05-20 20:48:04 -04:00
parent 73696a8521
commit 0b156637a5

View File

@@ -20,6 +20,7 @@
#include <gtk/gtk.h>
#include "gtk/gtklistitemmanagerprivate.h"
#include "gtk/gtklistbaseprivate.h"
#include "gtk/gtkgridviewprivate.h"
static GListModel *
create_source_model (guint min_size, guint max_size)
@@ -374,7 +375,43 @@ print_changes_cb (GListModel *model,
}
static void
test_exhaustive (void)
check_column_tile_invariants (GtkListItemManager *items,
unsigned int n_columns)
{
GtkListTile *tile;
for (tile = gtk_list_item_manager_get_first (items);
tile != NULL;
tile = gtk_rb_tree_node_get_next (tile))
{
g_assert (tile->type != GTK_LIST_TILE_REMOVED);
if (tile->n_items > 1)
{
unsigned int pos, col;
pos = gtk_list_tile_get_position (items, tile);
col = gtk_grid_view_get_column_for_position (items, n_columns, pos);
if (gtk_grid_view_is_multirow_tile (items, n_columns, tile))
g_assert_true (col == 0);
else
g_assert_true (col + tile->n_items - 1 <= n_columns);
}
}
}
static void
check_grid_view (GtkListItemManager *items)
{
for (unsigned int n_columns = 1; n_columns < 10; n_columns++)
{
gtk_list_item_manager_gc_tiles (items);
gtk_grid_view_split_tiles_by_columns (items, n_columns);
check_column_tile_invariants (items, n_columns);
}
}
static void
test_exhaustive (gboolean grid)
{
GtkListItemTracker *trackers[N_TRACKERS];
GListStore *store;
@@ -484,7 +521,10 @@ test_exhaustive (void)
}
}
check_list_item_manager (items, trackers, N_TRACKERS);
if (grid)
check_grid_view (items);
else
check_list_item_manager (items, trackers, N_TRACKERS);
for (i = 0; i < N_TRACKERS; i++)
gtk_list_item_tracker_free (items, trackers[i]);
@@ -492,6 +532,18 @@ test_exhaustive (void)
gtk_window_destroy (GTK_WINDOW (widget));
}
static void
test_exhaustive_list (void)
{
test_exhaustive (FALSE);
}
static void
test_exhaustive_grid (void)
{
test_exhaustive (TRUE);
}
int
main (int argc, char *argv[])
{
@@ -499,7 +551,8 @@ main (int argc, char *argv[])
g_test_add_func ("/listitemmanager/create", test_create);
g_test_add_func ("/listitemmanager/create_with_items", test_create_with_items);
g_test_add_func ("/listitemmanager/exhaustive", test_exhaustive);
g_test_add_func ("/listitemmanager/exhaustive", test_exhaustive_list);
g_test_add_func ("/gridview/split", test_exhaustive_grid);
return g_test_run ();
}