testsuite: Add another test to the listitemmanager
authorBenjamin Otte <otte@redhat.com>
Sat, 10 Jun 2023 18:12:11 +0000 (20:12 +0200)
committerBenjamin Otte <otte@redhat.com>
Sat, 10 Jun 2023 18:25:20 +0000 (20:25 +0200)
Ensure the itemmanager doesn't lose any widgets by ensuring that the
tiles with widgets do account for all children of the list widget.

testsuite/gtk/listitemmanager.c

index 5b6da7c856b0e981cdd13cd84f24ee439b318bbc..0ad80b0aae1b90a797e87f3e133c42062cf4eff6 100644 (file)
@@ -85,14 +85,29 @@ print_list_item_manager_tiles (GtkListItemManager *items)
   g_string_free (string, TRUE);
 }
 
+static gsize
+widget_count_children (GtkWidget *widget)
+{
+  GtkWidget *child;
+  gsize n_children = 0;
+
+  for (child = gtk_widget_get_first_child (widget);
+       child;
+       child = gtk_widget_get_next_sibling (child))
+    n_children++;
+
+  return n_children;
+}
+
 static void
 check_list_item_manager (GtkListItemManager  *items,
+                         GtkWidget           *widget,
                          GtkListItemTracker **trackers,
                          gsize                n_trackers)
 {
   GListModel *model = G_LIST_MODEL (gtk_list_item_manager_get_model (items));
   GtkListTile *tile;
-  guint n_items = 0;
+  guint n_items, n_tile_widgets;
   guint i;
   gboolean has_sections;
   enum {
@@ -104,6 +119,9 @@ check_list_item_manager (GtkListItemManager  *items,
 
   has_sections = gtk_list_item_manager_get_has_sections (items);
 
+  n_items = 0;
+  n_tile_widgets = 0;
+
   for (tile = gtk_list_item_manager_get_first (items);
        tile != NULL;
        tile = gtk_rb_tree_node_get_next (tile))
@@ -176,10 +194,14 @@ check_list_item_manager (GtkListItemManager  *items,
             g_assert_not_reached ();
             break;
         }
+
+      if (tile->widget)
+        n_tile_widgets++;
     }
 
   g_assert_cmpint (section_state, ==, NO_SECTION);
   g_assert_cmpint (n_items, ==, g_list_model_get_n_items (model));
+  g_assert_cmpint (n_tile_widgets, ==, widget_count_children (widget));
 
   for (i = 0; i < n_trackers; i++)
     {
@@ -197,6 +219,7 @@ check_list_item_manager (GtkListItemManager  *items,
   gtk_list_item_manager_gc_tiles (items);
 
   n_items = 0;
+  n_tile_widgets = 0;
 
   for (tile = gtk_list_item_manager_get_first (items);
        tile != NULL;
@@ -259,10 +282,14 @@ check_list_item_manager (GtkListItemManager  *items,
             g_assert_not_reached ();
             break;
         }
+
+      if (tile->widget)
+        n_tile_widgets++;
     }
 
   g_assert_cmpint (section_state, ==, NO_SECTION);
   g_assert_cmpint (n_items, ==, g_list_model_get_n_items (model));
+  g_assert_cmpint (n_tile_widgets, ==, widget_count_children (widget));
 
   for (i = 0; i < n_trackers; i++)
     {
@@ -343,9 +370,9 @@ test_create_with_items (void)
   source = create_source_model (1, 50);
   selection = gtk_no_selection_new (G_LIST_MODEL (source));
   gtk_list_item_manager_set_model (items, GTK_SELECTION_MODEL (selection));
-  check_list_item_manager (items, NULL, 0);
+  check_list_item_manager (items, widget, NULL, 0);
   gtk_list_item_manager_set_model (items, GTK_SELECTION_MODEL (selection));
-  check_list_item_manager (items, NULL, 0);
+  check_list_item_manager (items, widget, NULL, 0);
 
   g_object_unref (selection);
   gtk_window_destroy (GTK_WINDOW (widget));
@@ -414,7 +441,7 @@ test_exhaustive (void)
         case 0:
           if (g_test_verbose ())
             g_test_message ("GC and checking");
-          check_list_item_manager (items, trackers, N_TRACKERS);
+          check_list_item_manager (items, widget, trackers, N_TRACKERS);
           break;
 
         case 1:
@@ -484,7 +511,7 @@ test_exhaustive (void)
         }
     }
 
-  check_list_item_manager (items, trackers, N_TRACKERS);
+  check_list_item_manager (items, widget, trackers, N_TRACKERS);
 
   for (i = 0; i < N_TRACKERS; i++)
     gtk_list_item_tracker_free (items, trackers[i]);