[gupnp/gupnp-1.4] tests: Add test for ggo#58



commit 75001fa9552089b21ec94e05d4423692fbfd48bb
Author: Jens Georg <mail jensge org>
Date:   Mon Dec 6 18:31:17 2021 +0100

    tests: Add test for ggo#58
    
    https://gitlab.gnome.org/GNOME/gupnp/-/issues/58

 tests/data/TestService.xml |   3 +
 tests/test-bugs.c          | 138 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 141 insertions(+)
---
diff --git a/tests/data/TestService.xml b/tests/data/TestService.xml
index 8f02269..21848e1 100644
--- a/tests/data/TestService.xml
+++ b/tests/data/TestService.xml
@@ -42,6 +42,9 @@
     </stateVariable>
   </serviceStateTable>
   <actionList>
+    <action>
+      <name>Ping</name>
+    </action>
     <action>
       <name>Browse</name>
       <argumentList>
diff --git a/tests/test-bugs.c b/tests/test-bugs.c
index 9d118c7..42ec5da 100644
--- a/tests/test-bugs.c
+++ b/tests/test-bugs.c
@@ -523,6 +523,143 @@ test_ggo_24 (void)
                 validate_host_header ("[fe80::01%eth0]", "fe80::acab", 4711));
 }
 
+/*
+ * Test that the legacy async _end_action calls still work
+ *
+ * https://gitlab.gnome.org/GNOME/gupnp/-/issues/58
+ */
+
+static void
+test_ggo_58_on_ping (GUPnPServiceProxy *proxy,
+                     GUPnPServiceProxyAction *action,
+                     gpointer user_data)
+{
+        TestServiceProxyData *data = (TestServiceProxyData *) user_data;
+
+        g_main_loop_quit (data->loop);
+}
+
+static void
+test_ggo_58_on_ping_call (GUPnPService *service,
+                          GUPnPServiceAction *action,
+                          gpointer user_data)
+{
+        gupnp_service_action_return (action);
+}
+
+static void
+test_ggo_58 ()
+{
+        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_58_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_58_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_58_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_58_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);
@@ -532,6 +669,7 @@ main (int argc, char *argv[]) {
     g_test_add_func ("/bugs/bgo/722696", test_bgo_722696);
     g_test_add_func ("/bugs/bgo/743233", test_bgo_743233);
     g_test_add_func ("/bugs/ggo/24", test_ggo_24);
+    g_test_add_func ("/bugs/ggo/58", test_ggo_58);
 
     return g_test_run ();
 }


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