[gupnp/gupnp-1.4] ServiceProxy: Fix legacy async API, again.



commit 9d856b7196437ec1f5dc3f78bd88af1bc1cb674a
Author: Jens Georg <mail jensge org>
Date:   Thu Jan 13 18:50:20 2022 +0100

    ServiceProxy: Fix legacy async API, again.
    
    Fixes #67

 libgupnp/gupnp-service-proxy.c |   4 +-
 tests/test-bugs.c              | 136 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+), 1 deletion(-)
---
diff --git a/libgupnp/gupnp-service-proxy.c b/libgupnp/gupnp-service-proxy.c
index e40fd47..5dd1bfc 100644
--- a/libgupnp/gupnp-service-proxy.c
+++ b/libgupnp/gupnp-service-proxy.c
@@ -539,7 +539,9 @@ on_legacy_async_callback (GObject *source, GAsyncResult *res, gpointer user_data
             !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
                 if (error != NULL)
                         g_propagate_error (&action->error, error);
-                action->callback (action->proxy, action, action->user_data);
+                // action's proxy will be NULL now due to call_action_finish. So
+                // we use the one from our callback
+                action->callback (GUPNP_SERVICE_PROXY (source), action, action->user_data);
         }
 
         g_clear_error (&error);
diff --git a/tests/test-bugs.c b/tests/test-bugs.c
index 1ae48eb..a20f488 100644
--- a/tests/test-bugs.c
+++ b/tests/test-bugs.c
@@ -911,6 +911,141 @@ test_ggo_60_no_crash ()
         g_main_loop_unref (data.loop);
 }
 
+static void
+test_ggo_67_on_ping (GUPnPServiceProxy *proxy,
+                     GUPnPServiceProxyAction *action,
+                     gpointer user_data)
+{
+        TestServiceProxyData *data = (TestServiceProxyData *) user_data;
+
+        g_assert_nonnull (proxy);
+        g_assert_nonnull (action);
+        g_assert_nonnull (user_data);
+
+        g_main_loop_quit (data->loop);
+}
+
+static void
+test_ggo_67_on_ping_call (GUPnPService *service,
+                          GUPnPServiceAction *action,
+                          gpointer user_data)
+{
+        gupnp_service_action_return_success (action);
+}
+
+// Verbatim copy of 58, just with a different call-back
+static void
+test_ggo_67 ()
+{
+        GUPnPContext *context = NULL;
+        GError *error = NULL;
+        GUPnPControlPoint *cp = NULL;
+        GUPnPRootDevice *rd;
+        TestServiceProxyData data = { NULL, NULL };
+        GUPnPServiceInfo *info = NULL;
+
+        data.loop = g_main_loop_new (NULL, FALSE);
+
+        context = create_context (0, &error);
+        g_assert_no_error (error);
+        g_assert (context != NULL);
+
+        cp = gupnp_control_point_new (
+                context,
+                "urn:test-gupnp-org:service:TestService:1");
+
+        gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE);
+
+        g_signal_connect (G_OBJECT (cp),
+                          "service-proxy-available",
+                          G_CALLBACK (test_on_sp_available),
+                          &data);
+
+
+        rd = gupnp_root_device_new (context,
+                                    "TestDevice.xml",
+                                    DATA_PATH,
+                                    &error);
+        g_assert_no_error (error);
+        g_assert (rd != NULL);
+        gupnp_root_device_set_available (rd, TRUE);
+        info = gupnp_device_info_get_service (
+                GUPNP_DEVICE_INFO (rd),
+                "urn:test-gupnp-org:service:TestService:1");
+        g_signal_connect (G_OBJECT (info),
+                          "action-invoked::Ping",
+                          G_CALLBACK (test_ggo_67_on_ping_call),
+                          &data);
+
+        test_run_loop (data.loop);
+        g_assert (data.proxy != NULL);
+
+        G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+                GUPnPServiceProxyAction *action =
+                gupnp_service_proxy_begin_action (data.proxy,
+                                                  "Ping",
+                                                  test_ggo_67_on_ping,
+                                                  &data,
+                                                  NULL);
+
+        test_run_loop (data.loop);
+
+        gboolean success = gupnp_service_proxy_end_action (data.proxy,
+                                                           action,
+                                                           &error,
+                                                           NULL);
+
+        g_assert (success);
+        g_assert_no_error (error);
+
+        action = gupnp_service_proxy_begin_action (data.proxy,
+                                                   "Ping",
+                                                   test_ggo_67_on_ping,
+                                                   &data,
+                                                   NULL);
+
+        test_run_loop (data.loop);
+
+        GHashTable *result_hash = g_hash_table_new (g_str_hash, g_str_equal);
+
+        success = gupnp_service_proxy_end_action_hash (data.proxy,
+                                                       action,
+                                                       result_hash,
+                                                       &error);
+        g_hash_table_destroy (result_hash);
+
+        g_assert (success);
+        g_assert_no_error (error);
+
+        action = gupnp_service_proxy_begin_action (data.proxy,
+                                                   "Ping",
+                                                   test_ggo_67_on_ping,
+                                                   &data,
+                                                   NULL);
+
+        test_run_loop (data.loop);
+
+        GList *result_list = NULL;
+        success = gupnp_service_proxy_end_action_list (data.proxy,
+                                                       action,
+                                                       NULL,
+                                                       NULL,
+                                                       &result_list,
+                                                       &error);
+
+        g_assert (success);
+        g_assert_no_error (error);
+
+        G_GNUC_END_IGNORE_DEPRECATIONS
+
+                        g_object_unref (info);
+        g_object_unref (data.proxy);
+        g_object_unref (cp);
+        g_object_unref (rd);
+        g_object_unref (context);
+
+        g_main_loop_unref (data.loop);
+}
 int
 main (int argc, char *argv[]) {
     g_test_init (&argc, &argv, NULL);
@@ -924,6 +1059,7 @@ main (int argc, char *argv[]) {
     g_test_add_func ("/bugs/ggo/42", test_ggo_42);
     g_test_add_func ("/bugs/ggo/63", test_ggo_63);
     g_test_add_func ("/bugs/ggo/60/no-crash", test_ggo_60_no_crash);
+    g_test_add_func ("/bugs/ggo/67", test_ggo_67);
 
     return g_test_run ();
 }


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