[gupnp/wip/context-manager-tests: 2/3] ContextFilter: Emit notifications on real changes




commit 532e46739f8e160bdd9d38f21c46129d7e4d628e
Author: Jens Georg <mail jensge org>
Date:   Sat Jun 18 10:48:34 2022 +0200

    ContextFilter: Emit notifications on real changes
    
    So ContextManager can be sure it is only triggered if it has to act

 libgupnp/gupnp-context-filter.c | 19 +++++++++++++------
 tests/test-context-filter.c     | 25 +++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 6 deletions(-)
---
diff --git a/libgupnp/gupnp-context-filter.c b/libgupnp/gupnp-context-filter.c
index 821e615..660204c 100644
--- a/libgupnp/gupnp-context-filter.c
+++ b/libgupnp/gupnp-context-filter.c
@@ -24,7 +24,7 @@ typedef struct _GUPnPContextFilterPrivate GUPnPContextFilterPrivate;
  * Network context filter, used by [class@GUPnP.ContextManager]
  *
  * #GUPnPContextFilter handles network filtering. It provides API to manage a
- * list of entries that will be used to filter networks. The #GUPnPContextFilter
+ * list of entries that will be used to positive filter networks. The #GUPnPContextFilter
  * could be enabled or not. If it's enabled but the entries list is empty, it
  * behaves as if being disabled.
  *
@@ -99,14 +99,19 @@ gupnp_context_filter_set_property (GObject *object,
 
         switch (property_id) {
         case PROP_ENABLED:
-                priv->enabled = g_value_get_boolean (value);
+                gupnp_context_filter_set_enabled (list,
+                                                  g_value_get_boolean (value));
                 break;
         case PROP_ENTRIES: {
-                GList *entries = g_value_get_pointer (value);
                 g_hash_table_remove_all (priv->entries);
+                GPtrArray *array = g_ptr_array_new ();
+                GList *entries = g_value_get_pointer (value);
                 for (GList *it = entries; it != NULL; it = g_list_next (it)) {
-                        g_hash_table_add (priv->entries, g_strdup (it->data));
+                        g_ptr_array_add (array, it->data);
                 }
+                g_ptr_array_add (array, NULL);
+                gupnp_context_filter_add_entryv (list, (char **) array->pdata);
+                g_ptr_array_unref (array);
         } break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -183,7 +188,8 @@ gupnp_context_filter_class_init (GUPnPContextFilterClass *klass)
                                       "TRUE if the context filter is active.",
                                       FALSE,
                                       G_PARAM_CONSTRUCT | G_PARAM_READWRITE |
-                                              G_PARAM_STATIC_STRINGS));
+                                              G_PARAM_STATIC_STRINGS |
+                                              G_PARAM_EXPLICIT_NOTIFY));
 
         /**
          * GUPnPContextFilter:entries: (type GList(utf8))(attributes 
org.gtk.Property.get=gupnp_context_filter_get_entries)
@@ -200,7 +206,8 @@ gupnp_context_filter_class_init (GUPnPContextFilterClass *klass)
                         "Filter entries",
                         "GList of strings that compose the context filter.",
                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
-                                G_PARAM_STATIC_STRINGS));
+                                G_PARAM_STATIC_STRINGS |
+                                G_PARAM_EXPLICIT_NOTIFY));
 }
 
 /**
diff --git a/tests/test-context-filter.c b/tests/test-context-filter.c
index eaf5865..7b6f8e5 100644
--- a/tests/test-context-filter.c
+++ b/tests/test-context-filter.c
@@ -215,6 +215,31 @@ test_context_filter_enable_disable ()
         g_assert_false (gupnp_context_filter_get_enabled (filter));
         g_assert_cmpint (enabled_count, ==, 1);
 
+        enabled_count = 0;
+        gupnp_context_filter_set_enabled (filter, FALSE);
+        g_assert_false (gupnp_context_filter_get_enabled (filter));
+        g_assert_cmpint (enabled_count, ==, 0);
+
+        enabled_count = 0;
+        g_object_set (G_OBJECT (filter), "enabled", FALSE, NULL);
+        g_assert_false (gupnp_context_filter_get_enabled (filter));
+        g_assert_cmpint (enabled_count, ==, 0);
+
+        enabled_count = 0;
+        g_object_set (G_OBJECT (filter), "enabled", TRUE, NULL);
+        g_assert (gupnp_context_filter_get_enabled (filter));
+        g_assert_cmpint (enabled_count, ==, 1);
+
+        enabled_count = 0;
+        g_object_set (G_OBJECT (filter), "enabled", TRUE, NULL);
+        g_assert (gupnp_context_filter_get_enabled (filter));
+        g_assert_cmpint (enabled_count, ==, 0);
+
+        enabled_count = 0;
+        g_object_set (G_OBJECT (filter), "enabled", FALSE, NULL);
+        g_assert_false (gupnp_context_filter_get_enabled (filter));
+        g_assert_cmpint (enabled_count, ==, 1);
+
         g_object_unref (filter);
 }
 


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