2019-08-25 12:45:24 +03:00
|
|
|
/* WirePlumber
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2019 Collabora Ltd.
|
|
|
|
|
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*/
|
|
|
|
|
|
2020-04-22 18:29:40 +03:00
|
|
|
#include "../common/base-test-fixture.h"
|
2019-08-25 12:45:24 +03:00
|
|
|
|
|
|
|
|
typedef struct {
|
2020-04-22 18:29:40 +03:00
|
|
|
WpBaseTestFixture base;
|
2019-08-25 12:45:24 +03:00
|
|
|
|
2019-11-13 15:44:23 +02:00
|
|
|
/* the object manager that listens for proxies */
|
|
|
|
|
WpObjectManager *om;
|
|
|
|
|
|
2019-08-25 12:45:24 +03:00
|
|
|
} TestProxyFixture;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_proxy_setup (TestProxyFixture *self, gconstpointer user_data)
|
|
|
|
|
{
|
2020-04-22 18:29:40 +03:00
|
|
|
wp_base_test_fixture_setup (&self->base, 0);
|
2019-11-13 15:44:23 +02:00
|
|
|
self->om = wp_object_manager_new ();
|
2019-08-25 12:45:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_proxy_teardown (TestProxyFixture *self, gconstpointer user_data)
|
|
|
|
|
{
|
2019-11-13 15:44:23 +02:00
|
|
|
g_clear_object (&self->om);
|
2020-04-22 18:29:40 +03:00
|
|
|
wp_base_test_fixture_teardown (&self->base);
|
2019-08-25 12:45:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_proxy_basic_augmented (WpProxy *proxy, GAsyncResult *res,
|
|
|
|
|
TestProxyFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_autoptr (GError) error = NULL;
|
|
|
|
|
g_assert_true (wp_proxy_augment_finish (proxy, res, &error));
|
2019-08-27 17:37:06 +03:00
|
|
|
g_assert_no_error (error);
|
2019-08-25 12:45:24 +03:00
|
|
|
|
|
|
|
|
g_assert_true (wp_proxy_get_features (proxy) & WP_PROXY_FEATURE_PW_PROXY);
|
|
|
|
|
g_assert_nonnull (wp_proxy_get_pw_proxy (proxy));
|
|
|
|
|
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_quit (fixture->base.loop);
|
2019-08-25 12:45:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-11-13 15:44:23 +02:00
|
|
|
test_proxy_basic_object_added (WpObjectManager *om, WpProxy *proxy,
|
2019-08-25 12:45:24 +03:00
|
|
|
TestProxyFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_assert_nonnull (proxy);
|
|
|
|
|
{
|
2019-11-13 15:44:23 +02:00
|
|
|
g_autoptr (WpCore) pcore = NULL;
|
|
|
|
|
g_autoptr (WpCore) omcore = NULL;
|
|
|
|
|
g_object_get (proxy, "core", &pcore, NULL);
|
|
|
|
|
g_object_get (om, "core", &omcore, NULL);
|
2019-09-07 17:55:46 +03:00
|
|
|
g_assert_nonnull (pcore);
|
2019-11-13 15:44:23 +02:00
|
|
|
g_assert_nonnull (omcore);
|
|
|
|
|
g_assert_true (pcore == omcore);
|
2019-08-25 12:45:24 +03:00
|
|
|
}
|
|
|
|
|
g_assert_cmphex (wp_proxy_get_global_permissions (proxy), ==, PW_PERM_RWX);
|
2020-01-22 18:54:45 +02:00
|
|
|
g_assert_true (WP_IS_CLIENT (proxy));
|
2019-08-25 12:45:24 +03:00
|
|
|
|
|
|
|
|
g_assert_cmphex (wp_proxy_get_features (proxy), ==, 0);
|
|
|
|
|
g_assert_null (wp_proxy_get_pw_proxy (proxy));
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
g_autoptr (WpProperties) props = wp_proxy_get_global_properties (proxy);
|
|
|
|
|
g_assert_nonnull (props);
|
|
|
|
|
g_assert_cmpstr (wp_properties_get (props, PW_KEY_PROTOCOL), ==,
|
|
|
|
|
"protocol-native");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wp_proxy_augment (proxy, WP_PROXY_FEATURE_PW_PROXY, NULL,
|
|
|
|
|
(GAsyncReadyCallback) test_proxy_basic_augmented, fixture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_proxy_basic (TestProxyFixture *fixture, gconstpointer data)
|
|
|
|
|
{
|
|
|
|
|
/* our test server should advertise exactly one
|
|
|
|
|
* client: our WpRemote; use this to test WpProxy */
|
2019-11-13 15:44:23 +02:00
|
|
|
g_signal_connect (fixture->om, "object-added",
|
|
|
|
|
(GCallback) test_proxy_basic_object_added, fixture);
|
|
|
|
|
|
2020-02-13 19:56:41 +02:00
|
|
|
wp_object_manager_add_interest (fixture->om, WP_TYPE_CLIENT, NULL, 0);
|
2020-04-22 18:29:40 +03:00
|
|
|
wp_core_install_object_manager (fixture->base.core, fixture->om);
|
2019-08-25 12:45:24 +03:00
|
|
|
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_run (fixture->base.loop);
|
2019-08-25 12:45:24 +03:00
|
|
|
}
|
|
|
|
|
|
2019-08-27 17:38:33 +03:00
|
|
|
typedef struct {
|
|
|
|
|
TestProxyFixture *fixture;
|
|
|
|
|
guint n_params;
|
2020-01-22 18:54:45 +02:00
|
|
|
} TestNodeParamData;
|
2019-08-27 17:38:33 +03:00
|
|
|
|
|
|
|
|
static void
|
2020-01-22 18:54:45 +02:00
|
|
|
test_node_param (WpNode *node, int seq, guint id, guint index,
|
|
|
|
|
guint next, struct spa_pod *param, TestNodeParamData *data)
|
2019-08-27 17:38:33 +03:00
|
|
|
{
|
|
|
|
|
data->n_params++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-01-22 18:54:45 +02:00
|
|
|
test_node_enum_params_done (WpProxy *node, GAsyncResult *res,
|
|
|
|
|
TestNodeParamData *data)
|
2019-08-27 17:38:33 +03:00
|
|
|
{
|
|
|
|
|
g_autoptr (GPtrArray) params = NULL;
|
|
|
|
|
g_autoptr (GError) error = NULL;
|
|
|
|
|
guint i;
|
|
|
|
|
|
2020-01-22 10:34:56 +02:00
|
|
|
params = wp_proxy_enum_params_collect_finish (node, res, &error);
|
2019-08-27 17:38:33 +03:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
g_assert_nonnull (params);
|
|
|
|
|
|
|
|
|
|
/* the param signal must have also been fired for all params */
|
|
|
|
|
g_assert_cmpint (params->len, ==, data->n_params);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < params->len; i++) {
|
2020-04-16 13:29:48 -04:00
|
|
|
WpSpaPod *pod = g_ptr_array_index (params, i);
|
|
|
|
|
g_assert_cmpstr ("PropInfo", ==, wp_spa_pod_get_object_type_name (pod));
|
2019-08-27 17:38:33 +03:00
|
|
|
}
|
|
|
|
|
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_quit (data->fixture->base.loop);
|
2019-08-27 17:38:33 +03:00
|
|
|
g_free (data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-01-22 18:54:45 +02:00
|
|
|
test_node_object_added (WpObjectManager *om, WpProxy *proxy,
|
2019-08-27 17:38:33 +03:00
|
|
|
TestProxyFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
const struct pw_node_info *info;
|
2020-01-22 18:54:45 +02:00
|
|
|
TestNodeParamData *param_data;
|
2019-08-27 17:38:33 +03:00
|
|
|
|
|
|
|
|
g_assert_nonnull (proxy);
|
2020-01-30 17:41:25 +02:00
|
|
|
g_assert_cmphex (wp_proxy_get_features (proxy), ==, WP_PROXY_FEATURES_STANDARD);
|
2019-08-27 17:38:33 +03:00
|
|
|
g_assert_nonnull (wp_proxy_get_pw_proxy (proxy));
|
|
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
g_assert_true (WP_IS_NODE (proxy));
|
2020-01-22 10:34:56 +02:00
|
|
|
info = wp_proxy_get_info (proxy);
|
2019-08-27 17:38:33 +03:00
|
|
|
g_assert_nonnull (info);
|
2020-01-23 18:50:01 +02:00
|
|
|
g_assert_cmpint (wp_proxy_get_bound_id (proxy), ==, info->id);
|
2019-08-27 17:38:33 +03:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const char *id;
|
2020-01-22 10:34:56 +02:00
|
|
|
g_autoptr (WpProperties) props = wp_proxy_get_properties (proxy);
|
2019-08-27 17:38:33 +03:00
|
|
|
|
|
|
|
|
g_assert_nonnull (props);
|
|
|
|
|
g_assert_true (wp_properties_peek_dict (props) == info->props);
|
2019-10-10 12:30:45 +03:00
|
|
|
id = wp_properties_get (props, PW_KEY_OBJECT_ID);
|
2019-08-27 17:38:33 +03:00
|
|
|
g_assert_nonnull (id);
|
|
|
|
|
g_assert_cmpint (info->id, ==, atoi(id));
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
param_data = g_new0 (TestNodeParamData, 1);
|
2019-08-27 17:38:33 +03:00
|
|
|
param_data->fixture = fixture;
|
|
|
|
|
|
2020-01-22 18:54:45 +02:00
|
|
|
g_signal_connect (proxy, "param", (GCallback) test_node_param,
|
2019-08-27 17:38:33 +03:00
|
|
|
param_data);
|
2020-04-16 13:29:48 -04:00
|
|
|
g_autoptr (WpSpaPod) filter = wp_spa_pod_new_none ();
|
2020-01-22 10:34:56 +02:00
|
|
|
wp_proxy_enum_params_collect (proxy, SPA_PARAM_PropInfo, 0, -1,
|
2020-04-16 13:29:48 -04:00
|
|
|
filter, NULL, (GAsyncReadyCallback) test_node_enum_params_done,
|
2019-08-27 17:38:33 +03:00
|
|
|
param_data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-01-22 18:54:45 +02:00
|
|
|
test_node (TestProxyFixture *fixture, gconstpointer data)
|
2019-08-27 17:38:33 +03:00
|
|
|
{
|
|
|
|
|
/* load audiotestsrc on the server side */
|
2020-04-22 18:29:40 +03:00
|
|
|
pw_thread_loop_lock (fixture->base.server.thread_loop);
|
|
|
|
|
pw_context_add_spa_lib (fixture->base.server.context, "audiotestsrc",
|
2019-08-27 17:38:33 +03:00
|
|
|
"audiotestsrc/libspa-audiotestsrc");
|
2020-04-22 18:29:40 +03:00
|
|
|
if (!pw_context_load_module (fixture->base.server.context,
|
2020-01-09 12:39:45 -05:00
|
|
|
"libpipewire-module-spa-node", "audiotestsrc", NULL)) {
|
2020-04-22 18:29:40 +03:00
|
|
|
pw_thread_loop_unlock (fixture->base.server.thread_loop);
|
2019-08-27 17:38:33 +03:00
|
|
|
g_test_skip ("audiotestsrc SPA plugin is not installed");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-04-22 18:29:40 +03:00
|
|
|
pw_thread_loop_unlock (fixture->base.server.thread_loop);
|
2019-08-27 17:38:33 +03:00
|
|
|
|
|
|
|
|
/* we should be able to see this exported audiotestsrc node on the client */
|
2019-11-13 15:44:23 +02:00
|
|
|
g_signal_connect (fixture->om, "object-added",
|
2020-01-22 18:54:45 +02:00
|
|
|
(GCallback) test_node_object_added, fixture);
|
2019-08-27 17:38:33 +03:00
|
|
|
|
2019-11-13 15:44:23 +02:00
|
|
|
/* declare interest and set default features to be ready
|
|
|
|
|
when the signal is fired */
|
2020-02-13 19:56:41 +02:00
|
|
|
wp_object_manager_add_interest (fixture->om,
|
2020-02-12 14:15:51 +02:00
|
|
|
WP_TYPE_NODE, NULL, WP_PROXY_FEATURES_STANDARD);
|
2020-04-22 18:29:40 +03:00
|
|
|
wp_core_install_object_manager (fixture->base.core, fixture->om);
|
2019-08-27 17:38:33 +03:00
|
|
|
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_run (fixture->base.loop);
|
2019-08-27 17:38:33 +03:00
|
|
|
}
|
|
|
|
|
|
2019-08-25 12:45:24 +03:00
|
|
|
gint
|
|
|
|
|
main (gint argc, gchar *argv[])
|
|
|
|
|
{
|
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
|
pw_init (NULL, NULL);
|
2020-04-14 18:31:17 +03:00
|
|
|
g_log_set_writer_func (wp_log_writer_default, NULL, NULL);
|
2019-08-25 12:45:24 +03:00
|
|
|
|
|
|
|
|
g_test_add ("/wp/proxy/basic", TestProxyFixture, NULL,
|
|
|
|
|
test_proxy_setup, test_proxy_basic, test_proxy_teardown);
|
2019-08-27 17:38:33 +03:00
|
|
|
g_test_add ("/wp/proxy/node", TestProxyFixture, NULL,
|
2020-01-22 18:54:45 +02:00
|
|
|
test_proxy_setup, test_node, test_proxy_teardown);
|
2019-08-25 12:45:24 +03:00
|
|
|
|
|
|
|
|
return g_test_run ();
|
|
|
|
|
}
|