[rhythmbox: 1/3] property-model: emit 'row-deleted' signal after property deletion




commit 9f2822cffd8abe4de29ad8aa842fa2077d50d85f
Author: crvi <crvisqr gmail com>
Date:   Tue Jul 14 12:09:13 2020 +0530

    property-model: emit 'row-deleted' signal after property deletion

 rhythmdb/rhythmdb-property-model.c   |  6 +--
 tests/test-rhythmdb-property-model.c | 72 +++++++++++++++++++++++++++++++++++-
 tests/test-utils.c                   |  9 +++++
 tests/test-utils.h                   |  2 +
 4 files changed, 85 insertions(+), 4 deletions(-)
---
diff --git a/rhythmdb/rhythmdb-property-model.c b/rhythmdb/rhythmdb-property-model.c
index 40ddae468..129d07e4f 100644
--- a/rhythmdb/rhythmdb-property-model.c
+++ b/rhythmdb/rhythmdb-property-model.c
@@ -886,15 +886,15 @@ rhythmdb_property_model_delete_prop (RhythmDBPropertyModel *model,
 
        path = rhythmdb_property_model_get_path (GTK_TREE_MODEL (model), &iter);
        g_signal_emit (G_OBJECT (model), rhythmdb_property_model_signals[PRE_ROW_DELETION], 0);
-       gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
-       gtk_tree_path_free (path);
-
        g_sequence_remove (ptr);
        g_hash_table_remove (model->priv->reverse_map, propstr);
        prop->refcount = 0xdeadbeef;
        rb_refstring_unref (prop->string);
        rb_refstring_unref (prop->sort_string);
 
+       gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
+       gtk_tree_path_free (path);
+
        g_free (prop);
 }
 
diff --git a/tests/test-rhythmdb-property-model.c b/tests/test-rhythmdb-property-model.c
index ea4b2b383..05a80d36e 100644
--- a/tests/test-rhythmdb-property-model.c
+++ b/tests/test-rhythmdb-property-model.c
@@ -38,6 +38,9 @@
 #include "rb-file-helpers.h"
 #include "rb-util.h"
 
+static gulong pre_delete_sig_handler;
+static gulong post_delete_sig_handler;
+
 static int
 _get_property_count (RhythmDBPropertyModel *model, const char *artist)
 {
@@ -53,6 +56,65 @@ _get_property_count (RhythmDBPropertyModel *model, const char *artist)
        return count;
 }
 
+static void
+verify_pre_row_deletion (RhythmDBPropertyModel *propmodel)
+{
+       char *artist;
+       gint nrows;
+       GtkTreeIter iter;
+
+       nrows = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (propmodel), NULL);
+       ck_assert (nrows == 3);
+
+       /* skip 'All' */
+       ck_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (propmodel), &iter));
+
+       /* artist 1 */
+       ck_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (propmodel), &iter));
+       gtk_tree_model_get (GTK_TREE_MODEL (propmodel), &iter,
+                           RHYTHMDB_PROPERTY_MODEL_COLUMN_TITLE, &artist, -1);
+       ck_assert (g_strcmp0 (artist, "x") == 0);
+       g_free (artist);
+
+       /* artist 2 */
+       ck_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (propmodel), &iter));
+       gtk_tree_model_get (GTK_TREE_MODEL (propmodel), &iter,
+                           RHYTHMDB_PROPERTY_MODEL_COLUMN_TITLE, &artist, -1);
+       ck_assert (g_strcmp0 (artist, "y") == 0);
+       g_free (artist);
+
+       /* end of model */
+       ck_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (propmodel), &iter) == FALSE);
+
+       g_signal_handler_disconnect (G_OBJECT (propmodel), pre_delete_sig_handler);
+}
+
+static void
+verify_post_row_deletion (RhythmDBPropertyModel *propmodel)
+{
+       char *artist;
+       gint nrows;
+       GtkTreeIter iter;
+
+       nrows = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (propmodel), NULL);
+       ck_assert (nrows == 2);
+
+       /* skip 'All' */
+       ck_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (propmodel), &iter));
+
+       /* artist 1 */
+       ck_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (propmodel), &iter));
+       gtk_tree_model_get (GTK_TREE_MODEL (propmodel), &iter,
+                           RHYTHMDB_PROPERTY_MODEL_COLUMN_TITLE, &artist, -1);
+       ck_assert (g_strcmp0 (artist, "y") == 0);
+       g_free (artist);
+
+       /* end of model */
+       ck_assert (gtk_tree_model_iter_next (GTK_TREE_MODEL (propmodel), &iter) == FALSE);
+
+       g_signal_handler_disconnect (G_OBJECT (propmodel), post_delete_sig_handler);
+}
+
 /* tests property models attached to static query models */
 START_TEST (test_rhythmdb_property_model_static)
 {
@@ -98,7 +160,15 @@ START_TEST (test_rhythmdb_property_model_static)
        end_step ();
 
        /* change one */
-       set_waiting_signal (G_OBJECT (propmodel), "row-deleted");
+       pre_delete_sig_handler = set_waiting_signal_with_callback (G_OBJECT (propmodel),
+                                                                  "pre-row-deletion",
+                                                                  G_CALLBACK (verify_pre_row_deletion),
+                                                                  NULL);
+       post_delete_sig_handler = set_waiting_signal_with_callback (G_OBJECT (propmodel),
+                                                                   "row-deleted",
+                                                                   G_CALLBACK (verify_post_row_deletion),
+                                                                   NULL);
+
        set_entry_string (db, a, RHYTHMDB_PROP_ARTIST, "y");
        rhythmdb_commit (db);
        wait_for_signal ();
diff --git a/tests/test-utils.c b/tests/test-utils.c
index 92f626e49..808a03a78 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -99,6 +99,15 @@ mark_signal (void)
        }
 }
 
+gulong
+set_waiting_signal_with_callback (GObject *o, const char *name, GCallback callback, gpointer data)
+{
+       gulong custom_sig_handler;
+       custom_sig_handler = g_signal_connect (o, name, callback, data);
+       set_waiting_signal (o, name);
+       return custom_sig_handler;
+}
+
 void
 set_waiting_signal (GObject *o, const char *name)
 {
diff --git a/tests/test-utils.h b/tests/test-utils.h
index df3e635ac..a514b48f3 100644
--- a/tests/test-utils.h
+++ b/tests/test-utils.h
@@ -49,4 +49,6 @@ void set_entry_string (RhythmDB *db, RhythmDBEntry *entry, RhythmDBPropType prop
 void set_entry_ulong (RhythmDB *db, RhythmDBEntry *entry, RhythmDBPropType prop, gulong value);
 void set_entry_hidden (RhythmDB *db, RhythmDBEntry *entry, gboolean hidden);
 
+gulong set_waiting_signal_with_callback (GObject *o, const char *name, GCallback callback, gpointer data);
+
 #endif /* __TEST_UTILS_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]