summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2022-04-02 11:16:49 +0200
committerJens Georg <mail@jensge.org>2022-04-02 11:16:49 +0200
commit174e80e5440a9e591d0d53ed5093659c6d945103 (patch)
tree278f06d2fea8e5aaa4e45ea8dec582904e385ece /tests
parentef9fe1ae0e9cee75bc7938d6a1c95333513c8f59 (diff)
downloadgupnp-174e80e5440a9e591d0d53ed5093659c6d945103.tar.gz
test: Add sync call soap error test
Diffstat (limited to 'tests')
-rw-r--r--tests/test-service-proxy.c49
1 files changed, 43 insertions, 6 deletions
diff --git a/tests/test-service-proxy.c b/tests/test-service-proxy.c
index 267f2c8..240c154 100644
--- a/tests/test-service-proxy.c
+++ b/tests/test-service-proxy.c
@@ -413,6 +413,7 @@ typedef struct {
GMainContext *outer_context;
const char *address;
GCancellable *cancellable;
+ GError expected_error;
} ThreadData;
typedef struct {
@@ -471,10 +472,10 @@ thread_func (gpointer data)
gupnp_service_proxy_call_action (gpd.p, action, d->cancellable, &error);
gupnp_service_proxy_action_unref (action);
- if (d->cancellable == NULL)
- g_assert_no_error (error);
- else
- g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
+ if (d->expected_error.domain != 0)
+ g_error_matches (error,
+ d->expected_error.domain,
+ d->expected_error.code);
g_object_unref (gpd.p);
g_object_unref (cp);
@@ -505,6 +506,7 @@ test_sync_call (ProxyTestFixture *tf, gconstpointer user_data)
d.outer_context = g_main_context_get_thread_default ();
d.outer_loop = tf->loop;
d.cancellable = NULL;
+ d.expected_error.domain = 0;
GThread *t = g_thread_new ("Sync call test", thread_func, &d);
test_run_loop (tf->loop, g_test_get_path());
@@ -538,6 +540,8 @@ test_cancel_sync_call (ProxyTestFixture *tf, gconstpointer user_data)
d.outer_context = g_main_context_get_thread_default ();
d.outer_loop = tf->loop;
d.cancellable = g_cancellable_new ();
+ d.expected_error.domain = G_IO_ERROR;
+ d.expected_error.code = G_IO_ERROR_CANCELLED;
GThread *t = g_thread_new ("Sync call cancel test", thread_func, &d);
test_run_loop (tf->loop, g_test_get_path());
@@ -575,6 +579,8 @@ on_test_soap_error (GObject *source, GAsyncResult *res, gpointer user_data)
GUPNP_CONTROL_ERROR,
GUPNP_CONTROL_ERROR_OUT_OF_SYNC);
+ g_clear_error (&error);
+
ProxyTestFixture *tf = (ProxyTestFixture *) user_data;
g_main_loop_quit (tf->loop);
}
@@ -604,6 +610,30 @@ test_finish_soap_error (ProxyTestFixture *tf, gconstpointer user_data)
g_main_loop_run (tf->loop);
}
+void
+test_finish_soap_error_sync (ProxyTestFixture *tf, gconstpointer user_data)
+{
+ g_signal_connect (tf->service,
+ "action-invoked::Ping",
+ G_CALLBACK (on_test_async_call_ping_error),
+ tf);
+ ThreadData d;
+ d.address = (const char *) user_data;
+ d.outer_context = g_main_context_get_thread_default ();
+ d.outer_loop = tf->loop;
+ d.cancellable = NULL;
+ d.expected_error.domain = GUPNP_CONTROL_ERROR;
+ d.expected_error.code = GUPNP_CONTROL_ERROR_OUT_OF_SYNC;
+
+ GThread *t = g_thread_new ("Sync call test", thread_func, &d);
+ test_run_loop (tf->loop, g_test_get_path ());
+ g_thread_join (t);
+
+ // Spin the loop for a bit...
+ g_timeout_add (500, (GSourceFunc) delayed_loop_quitter, tf->loop);
+ g_main_loop_run (tf->loop);
+}
+
int
main (int argc, char *argv[])
{
@@ -637,6 +667,13 @@ main (int argc, char *argv[])
test_async_call_destroy_with_pending,
test_fixture_teardown);
+ g_test_add ("/service-proxy/async/soap-error-in-finish",
+ ProxyTestFixture,
+ "127.0.0.1",
+ test_fixture_setup,
+ test_finish_soap_error,
+ test_fixture_teardown);
+
g_test_add ("/service-proxy/sync/call",
ProxyTestFixture,
"127.0.0.1",
@@ -651,11 +688,11 @@ main (int argc, char *argv[])
test_cancel_sync_call,
test_fixture_teardown);
- g_test_add ("/service-proxy/async/soap-error-in-finish",
+ g_test_add ("/service-proxy/sync/soap-error-in-finish",
ProxyTestFixture,
"127.0.0.1",
test_fixture_setup,
- test_finish_soap_error,
+ test_finish_soap_error_sync,
test_fixture_teardown);
return g_test_run ();