]> Pileus Git - ~andy/gtk/blobdiff - gtk/tests/gtktreemodelrefcount.c
treeview: fix a critical warning
[~andy/gtk] / gtk / tests / gtktreemodelrefcount.c
index 9c91a587da6b663ff6972c3e0b2a6ab8f04cf85d..7f29f994e15f7242ed6db3f0b5052e9c139c7518 100644 (file)
@@ -12,9 +12,7 @@
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
@@ -60,6 +58,28 @@ G_DEFINE_TYPE_WITH_CODE (GtkTreeModelRefCount, gtk_tree_model_ref_count, GTK_TYP
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
                                                 gtk_tree_model_ref_count_tree_model_init))
 
+static void
+row_removed (GtkTreeModelRefCount *ref_model,
+             GtkTreePath *path)
+{
+  GHashTableIter iter;
+  GtkTreeIter tree_iter;
+
+  if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ref_model), &tree_iter))
+    {
+      g_hash_table_remove_all (ref_model->priv->node_hash);
+      return;
+    }
+
+  g_hash_table_iter_init (&iter, ref_model->priv->node_hash);
+
+  while (g_hash_table_iter_next (&iter, &tree_iter.user_data, NULL))
+    {
+      if (!gtk_tree_store_iter_is_valid (GTK_TREE_STORE (ref_model), &tree_iter))
+        g_hash_table_iter_remove (&iter);
+    }
+}
+
 static void
 gtk_tree_model_ref_count_init (GtkTreeModelRefCount *ref_model)
 {
@@ -71,6 +91,8 @@ gtk_tree_model_ref_count_init (GtkTreeModelRefCount *ref_model)
                                                       g_direct_equal,
                                                       NULL,
                                                       (GDestroyNotify)node_info_free);
+
+  g_signal_connect (ref_model, "row-deleted", G_CALLBACK (row_removed), NULL);
 }
 
 static void
@@ -239,7 +261,12 @@ check_iter (GtkTreeModelRefCount *ref_model,
     }
 
   if (may_assert)
-    g_assert_cmpint (expected_ref_count, ==, info->ref_count);
+    {
+      if (expected_ref_count == 0)
+        g_assert_cmpint (expected_ref_count, ==, info->ref_count);
+      else
+        g_assert_cmpint (expected_ref_count, <=, info->ref_count);
+    }
 
   return expected_ref_count == info->ref_count;
 }