2019-11-25 16:16:32 +02: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"
|
|
|
|
|
#include <pipewire/extensions/session-manager/keys.h>
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
typedef struct {
|
2020-04-22 18:29:40 +03:00
|
|
|
WpBaseTestFixture base;
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
WpObjectManager *export_om;
|
|
|
|
|
WpObjectManager *proxy_om;
|
|
|
|
|
|
2020-02-11 16:43:10 +02:00
|
|
|
WpImplSession *impl_session;
|
2019-11-25 16:16:32 +02:00
|
|
|
WpProxy *proxy_session;
|
|
|
|
|
|
|
|
|
|
gint n_events;
|
|
|
|
|
|
|
|
|
|
} TestSessionFixture;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_session_setup (TestSessionFixture *self, gconstpointer user_data)
|
|
|
|
|
{
|
2020-04-22 18:29:40 +03:00
|
|
|
wp_base_test_fixture_setup (&self->base, WP_BASE_TEST_FLAG_CLIENT_CORE);
|
2019-11-25 16:16:32 +02:00
|
|
|
self->export_om = wp_object_manager_new ();
|
|
|
|
|
self->proxy_om = wp_object_manager_new ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_session_teardown (TestSessionFixture *self, gconstpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
g_clear_object (&self->proxy_om);
|
|
|
|
|
g_clear_object (&self->export_om);
|
2020-04-22 18:29:40 +03:00
|
|
|
wp_base_test_fixture_teardown (&self->base);
|
2019-11-25 16:16:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_session_basic_exported_object_added (WpObjectManager *om,
|
|
|
|
|
WpSession *session, TestSessionFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_debug ("exported object added");
|
|
|
|
|
|
2020-02-11 16:43:10 +02:00
|
|
|
g_assert_true (WP_IS_IMPL_SESSION (session));
|
2019-11-25 16:16:32 +02:00
|
|
|
|
2020-02-11 16:43:10 +02:00
|
|
|
g_assert_null (fixture->impl_session);
|
|
|
|
|
fixture->impl_session = WP_IMPL_SESSION (session);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
if (++fixture->n_events == 3)
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_quit (fixture->base.loop);
|
2019-11-25 16:16:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_session_basic_exported_object_removed (WpObjectManager *om,
|
|
|
|
|
WpSession *session, TestSessionFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_debug ("exported object removed");
|
|
|
|
|
|
2020-02-11 16:43:10 +02:00
|
|
|
g_assert_true (WP_IS_IMPL_SESSION (session));
|
2019-11-25 16:16:32 +02:00
|
|
|
|
2020-02-11 16:43:10 +02:00
|
|
|
g_assert_nonnull (fixture->impl_session);
|
|
|
|
|
fixture->impl_session = NULL;
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
if (++fixture->n_events == 2)
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_quit (fixture->base.loop);
|
2019-11-25 16:16:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_session_basic_proxy_object_added (WpObjectManager *om,
|
|
|
|
|
WpSession *session, TestSessionFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_debug ("proxy object added");
|
|
|
|
|
|
|
|
|
|
g_assert_true (WP_IS_SESSION (session));
|
|
|
|
|
|
|
|
|
|
g_assert_null (fixture->proxy_session);
|
|
|
|
|
fixture->proxy_session = WP_PROXY (session);
|
|
|
|
|
|
|
|
|
|
if (++fixture->n_events == 3)
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_quit (fixture->base.loop);
|
2019-11-25 16:16:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_session_basic_proxy_object_removed (WpObjectManager *om,
|
|
|
|
|
WpSession *session, TestSessionFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_debug ("proxy object removed");
|
|
|
|
|
|
|
|
|
|
g_assert_true (WP_IS_SESSION (session));
|
|
|
|
|
|
|
|
|
|
g_assert_nonnull (fixture->proxy_session);
|
|
|
|
|
fixture->proxy_session = NULL;
|
|
|
|
|
|
|
|
|
|
if (++fixture->n_events == 2)
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_quit (fixture->base.loop);
|
2019-11-25 16:16:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-02-11 16:43:10 +02:00
|
|
|
test_session_basic_export_done (WpProxy * session, GAsyncResult * res,
|
2019-11-25 16:16:32 +02:00
|
|
|
TestSessionFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_autoptr (GError) error = NULL;
|
|
|
|
|
|
|
|
|
|
g_debug ("export done");
|
|
|
|
|
|
2020-02-11 16:43:10 +02:00
|
|
|
g_assert_true (wp_proxy_augment_finish (session, res, &error));
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
2020-02-11 16:43:10 +02:00
|
|
|
g_assert_true (WP_IS_IMPL_SESSION (session));
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
if (++fixture->n_events == 3)
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_quit (fixture->base.loop);
|
2019-11-25 16:16:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_session_basic_default_endpoint_changed (WpSession * session,
|
2020-04-16 13:29:48 -04:00
|
|
|
const char *type_name, guint32 id, TestSessionFixture *fixture)
|
2019-11-25 16:16:32 +02:00
|
|
|
{
|
2020-04-16 13:29:48 -04:00
|
|
|
g_debug ("endpoint changed: %s (%s, %u)", G_OBJECT_TYPE_NAME (session),
|
|
|
|
|
type_name, id);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
g_assert_true (WP_IS_SESSION (session));
|
|
|
|
|
|
|
|
|
|
if (++fixture->n_events == 2)
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_quit (fixture->base.loop);
|
2019-11-25 16:16:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_session_basic_notify_properties (WpSession * session, GParamSpec * param,
|
|
|
|
|
TestSessionFixture *fixture)
|
|
|
|
|
{
|
|
|
|
|
g_debug ("properties changed: %s", G_OBJECT_TYPE_NAME (session));
|
|
|
|
|
|
|
|
|
|
g_assert_true (WP_IS_SESSION (session));
|
|
|
|
|
|
|
|
|
|
if (++fixture->n_events == 2)
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_quit (fixture->base.loop);
|
2019-11-25 16:16:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_session_basic (TestSessionFixture *fixture, gconstpointer data)
|
|
|
|
|
{
|
2020-02-11 16:43:10 +02:00
|
|
|
g_autoptr (WpImplSession) session = NULL;
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
/* set up the export side */
|
|
|
|
|
g_signal_connect (fixture->export_om, "object-added",
|
|
|
|
|
(GCallback) test_session_basic_exported_object_added, fixture);
|
|
|
|
|
g_signal_connect (fixture->export_om, "object-removed",
|
|
|
|
|
(GCallback) test_session_basic_exported_object_removed, fixture);
|
2020-02-13 19:56:41 +02:00
|
|
|
wp_object_manager_add_interest (fixture->export_om,
|
|
|
|
|
WP_TYPE_IMPL_SESSION, NULL,
|
2020-04-01 13:38:39 +03:00
|
|
|
WP_SESSION_FEATURES_STANDARD);
|
2020-04-22 18:29:40 +03:00
|
|
|
wp_core_install_object_manager (fixture->base.core, fixture->export_om);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
/* set up the proxy side */
|
|
|
|
|
g_signal_connect (fixture->proxy_om, "object-added",
|
|
|
|
|
(GCallback) test_session_basic_proxy_object_added, fixture);
|
|
|
|
|
g_signal_connect (fixture->proxy_om, "object-removed",
|
|
|
|
|
(GCallback) test_session_basic_proxy_object_removed, fixture);
|
2020-02-13 19:56:41 +02:00
|
|
|
wp_object_manager_add_interest (fixture->proxy_om,
|
2020-02-12 14:15:51 +02:00
|
|
|
WP_TYPE_SESSION, NULL,
|
2020-04-01 13:38:39 +03:00
|
|
|
WP_SESSION_FEATURES_STANDARD);
|
2020-04-22 18:29:40 +03:00
|
|
|
wp_core_install_object_manager (fixture->base.client_core, fixture->proxy_om);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
/* create session */
|
2020-04-22 18:29:40 +03:00
|
|
|
session = wp_impl_session_new (fixture->base.core);
|
2020-02-11 16:43:10 +02:00
|
|
|
wp_impl_session_set_property (session, "test.property", "test-value");
|
2019-11-25 16:16:32 +02:00
|
|
|
wp_session_set_default_endpoint (WP_SESSION (session),
|
2020-04-16 13:29:48 -04:00
|
|
|
"wp-session-default-endpoint-audio-sink", 5);
|
2019-11-25 16:16:32 +02:00
|
|
|
wp_session_set_default_endpoint (WP_SESSION (session),
|
2020-04-16 13:29:48 -04:00
|
|
|
"wp-session-default-endpoint-video-source", 9);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
/* verify properties are set before export */
|
|
|
|
|
{
|
|
|
|
|
g_autoptr (WpProperties) props =
|
2020-02-11 16:43:10 +02:00
|
|
|
wp_proxy_get_properties (WP_PROXY (session));
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
|
|
|
|
|
"test-value");
|
|
|
|
|
}
|
|
|
|
|
g_assert_cmpuint (wp_session_get_default_endpoint (WP_SESSION (session),
|
2020-04-16 13:29:48 -04:00
|
|
|
"wp-session-default-endpoint-audio-sink"), ==, 5);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpuint (wp_session_get_default_endpoint (WP_SESSION (session),
|
2020-04-16 13:29:48 -04:00
|
|
|
"wp-session-default-endpoint-video-source"), ==, 9);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
/* do export */
|
2020-02-11 16:43:10 +02:00
|
|
|
wp_proxy_augment (WP_PROXY (session), WP_PROXY_FEATURE_BOUND, NULL,
|
2019-11-25 16:16:32 +02:00
|
|
|
(GAsyncReadyCallback) test_session_basic_export_done, fixture);
|
|
|
|
|
|
|
|
|
|
/* run until objects are created and features are cached */
|
|
|
|
|
fixture->n_events = 0;
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_run (fixture->base.loop);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpint (fixture->n_events, ==, 3);
|
2020-02-11 16:43:10 +02:00
|
|
|
g_assert_nonnull (fixture->impl_session);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_nonnull (fixture->proxy_session);
|
2020-02-11 16:43:10 +02:00
|
|
|
g_assert_true (fixture->impl_session == session);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
/* test round 1: verify the values on the proxy */
|
|
|
|
|
|
|
|
|
|
g_assert_cmphex (wp_proxy_get_features (fixture->proxy_session), ==,
|
|
|
|
|
WP_PROXY_FEATURE_PW_PROXY |
|
|
|
|
|
WP_PROXY_FEATURE_INFO |
|
2020-01-23 18:50:01 +02:00
|
|
|
WP_PROXY_FEATURE_BOUND |
|
2020-04-16 15:18:53 -04:00
|
|
|
WP_PROXY_FEATURE_CONTROLS |
|
|
|
|
|
WP_SESSION_FEATURE_ENDPOINTS);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
2020-01-23 18:50:01 +02:00
|
|
|
g_assert_cmpuint (wp_proxy_get_bound_id (fixture->proxy_session), ==,
|
2020-02-11 16:43:10 +02:00
|
|
|
wp_proxy_get_bound_id (WP_PROXY (session)));
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
g_autoptr (WpProperties) props =
|
2020-01-22 10:34:56 +02:00
|
|
|
wp_proxy_get_properties (fixture->proxy_session);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
|
|
|
|
|
"test-value");
|
|
|
|
|
}
|
|
|
|
|
g_assert_cmpuint (wp_session_get_default_endpoint (
|
|
|
|
|
WP_SESSION (fixture->proxy_session),
|
2020-04-16 13:29:48 -04:00
|
|
|
"wp-session-default-endpoint-audio-sink"), ==, 5);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpuint (wp_session_get_default_endpoint (
|
|
|
|
|
WP_SESSION (fixture->proxy_session),
|
2020-04-16 13:29:48 -04:00
|
|
|
"wp-session-default-endpoint-video-source"), ==, 9);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
/* setup change signals */
|
|
|
|
|
g_signal_connect (fixture->proxy_session, "default-endpoint-changed",
|
|
|
|
|
(GCallback) test_session_basic_default_endpoint_changed, fixture);
|
|
|
|
|
g_signal_connect (session, "default-endpoint-changed",
|
|
|
|
|
(GCallback) test_session_basic_default_endpoint_changed, fixture);
|
|
|
|
|
g_signal_connect (fixture->proxy_session, "notify::properties",
|
|
|
|
|
(GCallback) test_session_basic_notify_properties, fixture);
|
|
|
|
|
g_signal_connect (session, "notify::properties",
|
|
|
|
|
(GCallback) test_session_basic_notify_properties, fixture);
|
|
|
|
|
|
|
|
|
|
/* change default endpoint on the proxy */
|
|
|
|
|
wp_session_set_default_endpoint (WP_SESSION (fixture->proxy_session),
|
2020-04-16 13:29:48 -04:00
|
|
|
"wp-session-default-endpoint-audio-sink", 73);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
/* run until the change is on both sides */
|
|
|
|
|
fixture->n_events = 0;
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_run (fixture->base.loop);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpint (fixture->n_events, ==, 2);
|
|
|
|
|
|
|
|
|
|
/* test round 2: verify the value change on both sides */
|
|
|
|
|
|
|
|
|
|
g_assert_cmpuint (wp_session_get_default_endpoint (
|
|
|
|
|
WP_SESSION (fixture->proxy_session),
|
2020-04-16 13:29:48 -04:00
|
|
|
"wp-session-default-endpoint-audio-sink"), ==, 73);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpuint (wp_session_get_default_endpoint (
|
|
|
|
|
WP_SESSION (fixture->proxy_session),
|
2020-04-16 13:29:48 -04:00
|
|
|
"wp-session-default-endpoint-video-source"), ==, 9);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
g_assert_cmpuint (wp_session_get_default_endpoint (
|
2020-04-16 13:29:48 -04:00
|
|
|
WP_SESSION (session), "wp-session-default-endpoint-audio-sink"), ==, 73);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpuint (wp_session_get_default_endpoint (
|
2020-04-16 13:29:48 -04:00
|
|
|
WP_SESSION (session), "wp-session-default-endpoint-video-source"), ==, 9);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
/* change default endpoint on the exported */
|
|
|
|
|
fixture->n_events = 0;
|
|
|
|
|
wp_session_set_default_endpoint (WP_SESSION (session),
|
2020-04-16 13:29:48 -04:00
|
|
|
"wp-session-default-endpoint-audio-source", 44);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
/* run until the change is on both sides */
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_run (fixture->base.loop);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpint (fixture->n_events, ==, 2);
|
|
|
|
|
|
|
|
|
|
/* test round 3: verify the value change on both sides */
|
|
|
|
|
|
|
|
|
|
g_assert_cmpuint (wp_session_get_default_endpoint (
|
2020-04-16 13:29:48 -04:00
|
|
|
WP_SESSION (session), "wp-session-default-endpoint-audio-source"), ==, 44);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpuint (wp_session_get_default_endpoint (
|
|
|
|
|
WP_SESSION (fixture->proxy_session),
|
2020-04-16 13:29:48 -04:00
|
|
|
"wp-session-default-endpoint-audio-source"), ==, 44);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
/* change a property on the exported */
|
|
|
|
|
fixture->n_events = 0;
|
2020-02-11 16:43:10 +02:00
|
|
|
wp_impl_session_set_property (session, "test.property", "changed-value");
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
/* run until the change is on both sides */
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_run (fixture->base.loop);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpint (fixture->n_events, ==, 2);
|
|
|
|
|
|
|
|
|
|
/* test round 4: verify the property change on both sides */
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
g_autoptr (WpProperties) props =
|
2020-02-11 16:43:10 +02:00
|
|
|
wp_proxy_get_properties (WP_PROXY (session));
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
|
|
|
|
|
"changed-value");
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
g_autoptr (WpProperties) props =
|
2020-01-22 10:34:56 +02:00
|
|
|
wp_proxy_get_properties (fixture->proxy_session);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpstr (wp_properties_get (props, "test.property"), ==,
|
|
|
|
|
"changed-value");
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 16:43:10 +02:00
|
|
|
/* destroy impl session */
|
2019-11-25 16:16:32 +02:00
|
|
|
fixture->n_events = 0;
|
2020-02-11 16:43:10 +02:00
|
|
|
g_clear_object (&session);
|
2019-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
/* run until objects are destroyed */
|
2020-04-22 18:29:40 +03:00
|
|
|
g_main_loop_run (fixture->base.loop);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_cmpint (fixture->n_events, ==, 2);
|
2020-02-11 16:43:10 +02:00
|
|
|
g_assert_null (fixture->impl_session);
|
2019-11-25 16:16:32 +02:00
|
|
|
g_assert_null (fixture->proxy_session);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-11-25 16:16:32 +02:00
|
|
|
|
|
|
|
|
g_test_add ("/wp/session/basic", TestSessionFixture, NULL,
|
|
|
|
|
test_session_setup, test_session_basic, test_session_teardown);
|
|
|
|
|
|
|
|
|
|
return g_test_run ();
|
|
|
|
|
}
|