mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-04-27 01:30:38 +02:00
tests: add config-policy unit test
This commit is contained in:
parent
664db8a200
commit
d5c3f7ee87
18 changed files with 1305 additions and 0 deletions
437
tests/modules/config-policy.c
Normal file
437
tests/modules/config-policy.c
Normal file
|
|
@ -0,0 +1,437 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2019 Collabora Ltd.
|
||||
* @author Julian Bouzas <julian.bouzas@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <pipewire/pipewire.h>
|
||||
|
||||
#include <wp/wp.h>
|
||||
|
||||
#include "config-policy/context.h"
|
||||
#include "../wp/test-server.h"
|
||||
|
||||
typedef struct {
|
||||
WpTestServer server;
|
||||
|
||||
GMutex mutex;
|
||||
GCond cond;
|
||||
gboolean created;
|
||||
|
||||
GThread *loop_thread;
|
||||
GMainContext *context;
|
||||
GMainLoop *loop;
|
||||
|
||||
WpCore *core;
|
||||
} TestConfigPolicyFixture;
|
||||
|
||||
static void *
|
||||
loop_thread_start (void *d)
|
||||
{
|
||||
TestConfigPolicyFixture *self = d;
|
||||
|
||||
/* Create the main loop using the default thread context */
|
||||
self->context = g_main_context_get_thread_default ();
|
||||
self->loop = g_main_loop_new (self->context, FALSE);
|
||||
|
||||
/* Notify the main thread that the main loop has been created */
|
||||
g_mutex_lock (&self->mutex);
|
||||
self->created = TRUE;
|
||||
g_cond_signal (&self->cond);
|
||||
g_mutex_unlock (&self->mutex);
|
||||
|
||||
/* Run the main loop */
|
||||
g_main_loop_run (self->loop);
|
||||
|
||||
/* Clean up */
|
||||
g_clear_pointer (&self->loop, g_main_loop_unref);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
config_policy_setup (TestConfigPolicyFixture *self, gconstpointer user_data)
|
||||
{
|
||||
/* Create the server */
|
||||
g_autoptr (WpProperties) props = NULL;
|
||||
wp_test_server_setup (&self->server);
|
||||
props = wp_properties_new (PW_KEY_REMOTE_NAME, self->server.name, NULL);
|
||||
|
||||
/* Data */
|
||||
g_mutex_init (&self->mutex);
|
||||
g_cond_init (&self->cond);
|
||||
self->created = FALSE;
|
||||
|
||||
/* Start the main loop in a thread */
|
||||
self->loop_thread = g_thread_new("loop-thread", &loop_thread_start, self);
|
||||
|
||||
/* Wait for the thread to create the main loop */
|
||||
g_mutex_lock (&self->mutex);
|
||||
while (!self->created)
|
||||
g_cond_wait (&self->cond, &self->mutex);
|
||||
g_mutex_unlock (&self->mutex);
|
||||
|
||||
/* Create the core using the thread context */
|
||||
self->core = wp_core_new (self->context, props);
|
||||
|
||||
/* Connect to the server */
|
||||
pw_remote_connect (wp_core_get_pw_remote (self->core));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
loop_thread_stop (gpointer data)
|
||||
{
|
||||
TestConfigPolicyFixture *self = data;
|
||||
g_main_loop_quit (self->loop);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
config_policy_teardown (TestConfigPolicyFixture *self, gconstpointer user_data)
|
||||
{
|
||||
/* Stop the main loop and wait until it is done */
|
||||
wp_core_idle_add (self->core, loop_thread_stop, self);
|
||||
g_thread_join (self->loop_thread);
|
||||
|
||||
/* Destroy the core */
|
||||
g_clear_object (&self->core);
|
||||
|
||||
g_mutex_clear (&self->mutex);
|
||||
g_cond_clear (&self->cond);
|
||||
self->created = FALSE;
|
||||
|
||||
/* Destroy the server */
|
||||
wp_test_server_teardown (&self->server);
|
||||
}
|
||||
|
||||
static void
|
||||
playback (TestConfigPolicyFixture *f, gconstpointer data)
|
||||
{
|
||||
g_autoptr (WpConfigPolicyContext) ctx = wp_config_policy_context_new (f->core,
|
||||
"config-policy/config-playback");
|
||||
g_autoptr (WpEndpointLink) link = NULL;
|
||||
g_autoptr (WpEndpoint) src = NULL;
|
||||
g_autoptr (WpEndpoint) sink = NULL;
|
||||
g_autoptr (WpEndpoint) ep1 = NULL;
|
||||
g_autoptr (WpEndpoint) ep2 = NULL;
|
||||
g_autoptr (WpEndpoint) ep3 = NULL;
|
||||
|
||||
/* Create the device endpoint */
|
||||
ep1 = wp_config_policy_context_add_endpoint (ctx, "ep1", "Fake/Sink",
|
||||
PW_DIRECTION_INPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep1);
|
||||
g_assert_null (link);
|
||||
g_assert_false (wp_endpoint_is_linked (ep1));
|
||||
|
||||
/* Create the first client endpoint */
|
||||
ep2 = wp_config_policy_context_add_endpoint (ctx, "ep2", "Stream/Output/Fake",
|
||||
PW_DIRECTION_OUTPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep2);
|
||||
g_assert_nonnull (link);
|
||||
g_assert_true (wp_endpoint_is_linked (ep2));
|
||||
g_assert_true (wp_endpoint_is_linked (ep1));
|
||||
src = wp_endpoint_link_get_source_endpoint (link);
|
||||
sink = wp_endpoint_link_get_sink_endpoint (link);
|
||||
g_assert_true (ep2 == src);
|
||||
g_assert_true (ep1 == sink);
|
||||
|
||||
/* Create the second client endpoint */
|
||||
ep3 = wp_config_policy_context_add_endpoint (ctx, "ep3", "Stream/Output/Fake",
|
||||
PW_DIRECTION_OUTPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep2);
|
||||
g_assert_nonnull (link);
|
||||
g_assert_true (wp_endpoint_is_linked (ep3));
|
||||
g_assert_true (wp_endpoint_is_linked (ep1));
|
||||
src = wp_endpoint_link_get_source_endpoint (link);
|
||||
sink = wp_endpoint_link_get_sink_endpoint (link);
|
||||
g_assert_true (ep3 == src);
|
||||
g_assert_true (ep1 == sink);
|
||||
|
||||
/* Make sure ep2 is unlinked after ep3 was linked */
|
||||
g_assert_false (wp_endpoint_is_linked (ep2));
|
||||
|
||||
/* Remove the client endpoints */
|
||||
wp_config_policy_context_remove_endpoint (ctx, ep2);
|
||||
wp_config_policy_context_remove_endpoint (ctx, ep3);
|
||||
}
|
||||
|
||||
static void
|
||||
capture (TestConfigPolicyFixture *f, gconstpointer data)
|
||||
{
|
||||
g_autoptr (WpConfigPolicyContext) ctx = wp_config_policy_context_new (f->core,
|
||||
"config-policy/config-capture");
|
||||
g_autoptr (WpEndpointLink) link = NULL;
|
||||
g_autoptr (WpEndpoint) src = NULL;
|
||||
g_autoptr (WpEndpoint) sink = NULL;
|
||||
g_autoptr (WpEndpoint) ep1 = NULL;
|
||||
g_autoptr (WpEndpoint) ep2 = NULL;
|
||||
|
||||
/* Create the device endpoint */
|
||||
ep1 = wp_config_policy_context_add_endpoint (ctx, "ep1", "Fake/Source",
|
||||
PW_DIRECTION_OUTPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep1);
|
||||
g_assert_null (link);
|
||||
g_assert_false (wp_endpoint_is_linked (ep1));
|
||||
|
||||
/* Create the client endpoint */
|
||||
ep2 = wp_config_policy_context_add_endpoint (ctx, "ep2", "Stream/Input/Fake",
|
||||
PW_DIRECTION_INPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep2);
|
||||
g_assert_nonnull (link);
|
||||
g_assert_true (wp_endpoint_is_linked (ep2));
|
||||
g_assert_true (wp_endpoint_is_linked (ep1));
|
||||
src = wp_endpoint_link_get_source_endpoint (link);
|
||||
sink = wp_endpoint_link_get_sink_endpoint (link);
|
||||
g_assert_true (ep1 == src);
|
||||
g_assert_true (ep2 == sink);
|
||||
|
||||
/* Remove the client endpoint */
|
||||
wp_config_policy_context_remove_endpoint (ctx, ep2);
|
||||
}
|
||||
|
||||
static void
|
||||
playback_capture (TestConfigPolicyFixture *f, gconstpointer data)
|
||||
{
|
||||
g_autoptr (WpConfigPolicyContext) ctx = wp_config_policy_context_new (f->core,
|
||||
"config-policy/config-playback-capture");
|
||||
g_autoptr (WpEndpointLink) link = NULL;
|
||||
g_autoptr (WpEndpoint) src = NULL;
|
||||
g_autoptr (WpEndpoint) sink = NULL;
|
||||
g_autoptr (WpEndpoint) ep1 = NULL;
|
||||
g_autoptr (WpEndpoint) ep2 = NULL;
|
||||
g_autoptr (WpEndpoint) ep3 = NULL;
|
||||
g_autoptr (WpEndpoint) ep4 = NULL;
|
||||
|
||||
/* Create the device endpoints */
|
||||
ep1 = wp_config_policy_context_add_endpoint (ctx, "ep1", "Fake/Sink",
|
||||
PW_DIRECTION_INPUT, NULL, NULL, 0, NULL);
|
||||
g_assert_nonnull (ep1);
|
||||
g_assert_null (link);
|
||||
g_assert_false (wp_endpoint_is_linked (ep1));
|
||||
ep2 = wp_config_policy_context_add_endpoint (ctx, "ep2", "Fake/Source",
|
||||
PW_DIRECTION_OUTPUT, NULL, NULL, 0, NULL);
|
||||
g_assert_nonnull (ep2);
|
||||
g_assert_null (link);
|
||||
g_assert_false (wp_endpoint_is_linked (ep2));
|
||||
|
||||
/* Create the playback client endpoint */
|
||||
ep3 = wp_config_policy_context_add_endpoint (ctx, "ep3", "Stream/Output/Fake",
|
||||
PW_DIRECTION_OUTPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep3);
|
||||
g_assert_nonnull (link);
|
||||
g_assert_true (wp_endpoint_is_linked (ep3));
|
||||
g_assert_true (wp_endpoint_is_linked (ep1));
|
||||
g_assert_false (wp_endpoint_is_linked (ep2));
|
||||
src = wp_endpoint_link_get_source_endpoint (link);
|
||||
sink = wp_endpoint_link_get_sink_endpoint (link);
|
||||
g_assert_true (ep3 == src);
|
||||
g_assert_true (ep1 == sink);
|
||||
|
||||
/* Create the capture client endpoint */
|
||||
ep4 = wp_config_policy_context_add_endpoint (ctx, "ep4", "Stream/Input/Fake",
|
||||
PW_DIRECTION_INPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep4);
|
||||
g_assert_nonnull (link);
|
||||
g_assert_true (wp_endpoint_is_linked (ep4));
|
||||
g_assert_true (wp_endpoint_is_linked (ep2));
|
||||
g_assert_true (wp_endpoint_is_linked (ep3));
|
||||
g_assert_true (wp_endpoint_is_linked (ep1));
|
||||
src = wp_endpoint_link_get_source_endpoint (link);
|
||||
sink = wp_endpoint_link_get_sink_endpoint (link);
|
||||
g_assert_true (ep2 == src);
|
||||
g_assert_true (ep4 == sink);
|
||||
|
||||
/* Remove the client endpoints */
|
||||
wp_config_policy_context_remove_endpoint (ctx, ep4);
|
||||
wp_config_policy_context_remove_endpoint (ctx, ep3);
|
||||
}
|
||||
|
||||
static void
|
||||
playback_priority (TestConfigPolicyFixture *f, gconstpointer data)
|
||||
{
|
||||
g_autoptr (WpConfigPolicyContext) ctx = wp_config_policy_context_new (f->core,
|
||||
"config-policy/config-playback-priority");
|
||||
g_autoptr (WpEndpointLink) link = NULL;
|
||||
g_autoptr (WpEndpoint) src = NULL;
|
||||
g_autoptr (WpEndpoint) sink = NULL;
|
||||
g_autoptr (WpEndpoint) dev = NULL;
|
||||
g_autoptr (WpEndpoint) ep1 = NULL;
|
||||
g_autoptr (WpEndpoint) ep2 = NULL;
|
||||
g_autoptr (WpEndpoint) ep3 = NULL;
|
||||
|
||||
/* Create the device endpoint with 4 streams */
|
||||
dev = wp_config_policy_context_add_endpoint (ctx, "dev", "Fake/Sink",
|
||||
PW_DIRECTION_INPUT, NULL, NULL, 4, NULL);
|
||||
g_assert_nonnull (dev);
|
||||
g_assert_null (link);
|
||||
g_assert_false (wp_endpoint_is_linked (dev));
|
||||
|
||||
/* Create the client endpoint for steam 2 (priority 50) and make sure it
|
||||
* is linked */
|
||||
ep2 = wp_config_policy_context_add_endpoint (ctx, "ep_for_stream_2",
|
||||
"Stream/Output/Fake", PW_DIRECTION_OUTPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep2);
|
||||
g_assert_nonnull (link);
|
||||
g_assert_true (wp_endpoint_is_linked (ep2));
|
||||
g_assert_true (wp_endpoint_is_linked (dev));
|
||||
src = wp_endpoint_link_get_source_endpoint (link);
|
||||
sink = wp_endpoint_link_get_sink_endpoint (link);
|
||||
g_assert_true (ep2 == src);
|
||||
g_assert_true (dev == sink);
|
||||
|
||||
/* Create the client endpoint for steam 1 (priority 25) and make sure it
|
||||
* is not linked */
|
||||
ep1 = wp_config_policy_context_add_endpoint (ctx, "ep_for_stream_1",
|
||||
"Stream/Output/Fake", PW_DIRECTION_OUTPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep1);
|
||||
g_assert_null (link);
|
||||
g_assert_false (wp_endpoint_is_linked (ep1));
|
||||
g_assert_true (wp_endpoint_is_linked (ep2));
|
||||
g_assert_true (wp_endpoint_is_linked (dev));
|
||||
|
||||
/* Create the client endpoint for steam 3 (priority 75) and make sure it
|
||||
* is linked */
|
||||
ep3 = wp_config_policy_context_add_endpoint (ctx, "ep_for_stream_3",
|
||||
"Stream/Output/Fake", PW_DIRECTION_OUTPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep3);
|
||||
g_assert_nonnull (link);
|
||||
g_assert_true (wp_endpoint_is_linked (ep3));
|
||||
g_assert_true (wp_endpoint_is_linked (dev));
|
||||
g_assert_false (wp_endpoint_is_linked (ep1));
|
||||
g_assert_false (wp_endpoint_is_linked (ep2));
|
||||
src = wp_endpoint_link_get_source_endpoint (link);
|
||||
sink = wp_endpoint_link_get_sink_endpoint (link);
|
||||
g_assert_true (ep3 == src);
|
||||
g_assert_true (dev == sink);
|
||||
|
||||
/* Remove the client endpoints */
|
||||
wp_config_policy_context_remove_endpoint (ctx, ep2);
|
||||
wp_config_policy_context_remove_endpoint (ctx, ep3);
|
||||
wp_config_policy_context_remove_endpoint (ctx, ep1);
|
||||
}
|
||||
|
||||
static void
|
||||
playback_keep (TestConfigPolicyFixture *f, gconstpointer data)
|
||||
{
|
||||
g_autoptr (WpConfigPolicyContext) ctx = wp_config_policy_context_new (f->core,
|
||||
"config-policy/config-playback-keep");
|
||||
g_autoptr (WpEndpointLink) link = NULL;
|
||||
g_autoptr (WpEndpoint) src = NULL;
|
||||
g_autoptr (WpEndpoint) sink = NULL;
|
||||
g_autoptr (WpEndpoint) ep1 = NULL;
|
||||
g_autoptr (WpEndpoint) ep2 = NULL;
|
||||
g_autoptr (WpEndpoint) ep3 = NULL;
|
||||
|
||||
/* Create the device endpoint */
|
||||
ep1 = wp_config_policy_context_add_endpoint (ctx, "ep1", "Fake/Sink",
|
||||
PW_DIRECTION_INPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep1);
|
||||
g_assert_null (link);
|
||||
g_assert_false (wp_endpoint_is_linked (ep1));
|
||||
|
||||
/* Create the first client endpoint */
|
||||
ep2 = wp_config_policy_context_add_endpoint (ctx, "ep2", "Stream/Output/Fake",
|
||||
PW_DIRECTION_OUTPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep2);
|
||||
g_assert_nonnull (link);
|
||||
g_assert_true (wp_endpoint_is_linked (ep2));
|
||||
g_assert_true (wp_endpoint_is_linked (ep1));
|
||||
src = wp_endpoint_link_get_source_endpoint (link);
|
||||
sink = wp_endpoint_link_get_sink_endpoint (link);
|
||||
g_assert_true (ep2 == src);
|
||||
g_assert_true (ep1 == sink);
|
||||
|
||||
/* Create the second client endpoint */
|
||||
ep3 = wp_config_policy_context_add_endpoint (ctx, "ep3", "Stream/Output/Fake",
|
||||
PW_DIRECTION_OUTPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep2);
|
||||
g_assert_nonnull (link);
|
||||
g_assert_true (wp_endpoint_is_linked (ep3));
|
||||
g_assert_true (wp_endpoint_is_linked (ep1));
|
||||
src = wp_endpoint_link_get_source_endpoint (link);
|
||||
sink = wp_endpoint_link_get_sink_endpoint (link);
|
||||
g_assert_true (ep3 == src);
|
||||
g_assert_true (ep1 == sink);
|
||||
|
||||
/* Make sure ep2 is still linked after ep3 was linked */
|
||||
g_assert_true (wp_endpoint_is_linked (ep2));
|
||||
|
||||
/* Remove the client endpoints */
|
||||
wp_config_policy_context_remove_endpoint (ctx, ep2);
|
||||
wp_config_policy_context_remove_endpoint (ctx, ep3);
|
||||
}
|
||||
|
||||
static void
|
||||
playback_role (TestConfigPolicyFixture *f, gconstpointer data)
|
||||
{
|
||||
g_autoptr (WpConfigPolicyContext) ctx = wp_config_policy_context_new (f->core,
|
||||
"config-policy/config-playback-role");
|
||||
g_autoptr (WpEndpointLink) link = NULL;
|
||||
g_autoptr (WpEndpoint) src = NULL;
|
||||
g_autoptr (WpEndpoint) sink = NULL;
|
||||
g_autoptr (WpEndpoint) ep1 = NULL;
|
||||
g_autoptr (WpEndpoint) ep2 = NULL;
|
||||
g_autoptr (WpEndpoint) ep3 = NULL;
|
||||
|
||||
/* Create the device with 2 roles: "0" with id 0, and "1" with id 1 */
|
||||
ep1 = wp_config_policy_context_add_endpoint (ctx, "ep1", "Fake/Sink",
|
||||
PW_DIRECTION_INPUT, NULL, NULL, 2, &link);
|
||||
g_assert_nonnull (ep1);
|
||||
g_assert_null (link);
|
||||
g_assert_false (wp_endpoint_is_linked (ep1));
|
||||
|
||||
/* Create the first client endpoint with role "0" and make sure it has
|
||||
* priority over the one defined in the configuration file which is "1" */
|
||||
ep2 = wp_config_policy_context_add_endpoint (ctx, "ep2", "Stream/Output/Fake",
|
||||
PW_DIRECTION_OUTPUT, NULL, "0", 0, &link);
|
||||
g_assert_nonnull (ep2);
|
||||
g_assert_nonnull (link);
|
||||
g_assert_true (wp_endpoint_is_linked (ep2));
|
||||
g_assert_true (wp_endpoint_is_linked (ep1));
|
||||
src = wp_endpoint_link_get_source_endpoint (link);
|
||||
sink = wp_endpoint_link_get_sink_endpoint (link);
|
||||
g_assert_true (ep2 == src);
|
||||
g_assert_true (ep1 == sink);
|
||||
g_assert_true (
|
||||
WP_STREAM_ID_NONE == wp_endpoint_link_get_source_stream (link));
|
||||
g_assert_true (0 == wp_endpoint_link_get_sink_stream (link));
|
||||
|
||||
/* Create the second client endpoint without role and make sure it uses
|
||||
* the one defined in the configuration file which is "1" */
|
||||
ep3 = wp_config_policy_context_add_endpoint (ctx, "ep3", "Stream/Output/Fake",
|
||||
PW_DIRECTION_OUTPUT, NULL, NULL, 0, &link);
|
||||
g_assert_nonnull (ep3);
|
||||
g_assert_nonnull (link);
|
||||
g_assert_true (wp_endpoint_is_linked (ep3));
|
||||
g_assert_true (wp_endpoint_is_linked (ep1));
|
||||
src = wp_endpoint_link_get_source_endpoint (link);
|
||||
sink = wp_endpoint_link_get_sink_endpoint (link);
|
||||
g_assert_true (ep3 == src);
|
||||
g_assert_true (ep1 == sink);
|
||||
g_assert_true (
|
||||
WP_STREAM_ID_NONE == wp_endpoint_link_get_source_stream (link));
|
||||
g_assert_true (1 == wp_endpoint_link_get_sink_stream (link));
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
pw_init (NULL, NULL);
|
||||
|
||||
g_test_add ("/modules/config-policy/playback", TestConfigPolicyFixture,
|
||||
NULL, config_policy_setup, playback, config_policy_teardown);
|
||||
g_test_add ("/modules/config-policy/capture", TestConfigPolicyFixture,
|
||||
NULL, config_policy_setup, capture, config_policy_teardown);
|
||||
g_test_add ("/modules/config-policy/playback-capture", TestConfigPolicyFixture,
|
||||
NULL, config_policy_setup, playback_capture, config_policy_teardown);
|
||||
g_test_add ("/modules/config-policy/playback-priority", TestConfigPolicyFixture,
|
||||
NULL, config_policy_setup, playback_priority, config_policy_teardown);
|
||||
g_test_add ("/modules/config-policy/playback-keep", TestConfigPolicyFixture,
|
||||
NULL, config_policy_setup, playback_keep, config_policy_teardown);
|
||||
g_test_add ("/modules/config-policy/playback-role", TestConfigPolicyFixture,
|
||||
NULL, config_policy_setup, playback_role, config_policy_teardown);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
[match-endpoint]
|
||||
direction = "input"
|
||||
media_class = "Stream/Input/Fake"
|
||||
|
||||
[target-endpoint]
|
||||
media_class = "Fake/Source"
|
||||
|
||||
[endpoint-link]
|
||||
keep = false
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
[match-endpoint]
|
||||
direction = "input"
|
||||
media_class = "Stream/Input/Fake"
|
||||
|
||||
[target-endpoint]
|
||||
media_class = "Fake/Source"
|
||||
|
||||
[endpoint-link]
|
||||
keep = false
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
[match-endpoint]
|
||||
direction = "output"
|
||||
media_class = "Stream/Output/Fake"
|
||||
|
||||
[target-endpoint]
|
||||
media_class = "Fake/Sink"
|
||||
|
||||
[endpoint-link]
|
||||
keep = false
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
[match-endpoint]
|
||||
direction = "output"
|
||||
media_class = "Stream/Output/Fake"
|
||||
|
||||
[target-endpoint]
|
||||
media_class = "Fake/Sink"
|
||||
|
||||
[endpoint-link]
|
||||
keep = true
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
[[streams]]
|
||||
name = "0"
|
||||
priority = 0
|
||||
|
||||
[[streams]]
|
||||
name = "1"
|
||||
priority = 25
|
||||
|
||||
[[streams]]
|
||||
name = "2"
|
||||
priority = 50
|
||||
|
||||
[[streams]]
|
||||
name = "3"
|
||||
priority = 75
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
[match-endpoint]
|
||||
direction = "output"
|
||||
name = "ep_for_stream_1"
|
||||
media_class = "Stream/Output/Fake"
|
||||
|
||||
[target-endpoint]
|
||||
media_class = "Fake/Sink"
|
||||
streams = "default.streams"
|
||||
stream = "1"
|
||||
|
||||
[endpoint-link]
|
||||
keep = false
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
[match-endpoint]
|
||||
direction = "output"
|
||||
name = "ep_for_stream_2"
|
||||
media_class = "Stream/Output/Fake"
|
||||
|
||||
[target-endpoint]
|
||||
media_class = "Fake/Sink"
|
||||
streams = "default.streams"
|
||||
stream = "2"
|
||||
|
||||
[endpoint-link]
|
||||
keep = false
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
[match-endpoint]
|
||||
direction = "output"
|
||||
name = "ep_for_stream_3"
|
||||
media_class = "Stream/Output/Fake"
|
||||
|
||||
[target-endpoint]
|
||||
media_class = "Fake/Sink"
|
||||
streams = "default.streams"
|
||||
stream = "3"
|
||||
|
||||
[endpoint-link]
|
||||
keep = false
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
[match-endpoint]
|
||||
direction = "output"
|
||||
media_class = "Stream/Output/Fake"
|
||||
|
||||
[target-endpoint]
|
||||
media_class = "Fake/Sink"
|
||||
stream = "1"
|
||||
|
||||
[endpoint-link]
|
||||
keep = false
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
[match-endpoint]
|
||||
direction = "output"
|
||||
media_class = "Stream/Output/Fake"
|
||||
|
||||
[target-endpoint]
|
||||
media_class = "Fake/Sink"
|
||||
|
||||
[endpoint-link]
|
||||
keep = false
|
||||
229
tests/modules/config-policy/context.c
Normal file
229
tests/modules/config-policy/context.c
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2019 Collabora Ltd.
|
||||
* @author Julian Bouzas <julian.bouzas@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <wp/wp.h>
|
||||
|
||||
#include "context.h"
|
||||
#include "endpoint-fake.h"
|
||||
#include "endpoint-link-fake.h"
|
||||
#include "../../../modules/module-config-policy/parser-endpoint-link.h"
|
||||
#include "../../../modules/module-config-policy/config-policy.h"
|
||||
|
||||
struct _WpConfigPolicyContext
|
||||
{
|
||||
GObject parent;
|
||||
|
||||
/* Props */
|
||||
GWeakRef core;
|
||||
char *config_path;
|
||||
|
||||
GMutex mutex;
|
||||
GCond cond;
|
||||
WpEndpoint *endpoint;
|
||||
WpEndpointLink *link;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_CORE,
|
||||
PROP_CONFIG_PATH,
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (WpConfigPolicyContext, wp_config_policy_context, G_TYPE_OBJECT);
|
||||
|
||||
static WpEndpoint *
|
||||
wait_for_endpoint (WpConfigPolicyContext *self, WpEndpointLink **link)
|
||||
{
|
||||
g_mutex_lock (&self->mutex);
|
||||
|
||||
/* Wait for endpoint to be set */
|
||||
while (!self->endpoint)
|
||||
g_cond_wait (&self->cond, &self->mutex);
|
||||
|
||||
/* Set endpoint to a local value and clear global value */
|
||||
WpEndpoint *endpoint = g_object_ref (self->endpoint);
|
||||
g_clear_object (&self->endpoint);
|
||||
|
||||
/* Set link to a local value and clear global value */
|
||||
if (link)
|
||||
*link = self->link ? g_object_ref (self->link) : NULL;
|
||||
g_clear_object (&self->link);
|
||||
|
||||
g_mutex_unlock (&self->mutex);
|
||||
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
static void
|
||||
on_done (WpConfigPolicy *cp, WpEndpoint *ep, WpEndpointLink *link,
|
||||
WpConfigPolicyContext *self)
|
||||
{
|
||||
if (!ep)
|
||||
return;
|
||||
|
||||
g_mutex_lock (&self->mutex);
|
||||
|
||||
self->endpoint = g_object_ref (ep);
|
||||
self->link = link ? g_object_ref (link) : NULL;
|
||||
g_cond_signal (&self->cond);
|
||||
|
||||
g_mutex_unlock (&self->mutex);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_config_policy_context_constructed (GObject *object)
|
||||
{
|
||||
WpConfigPolicyContext *self = WP_CONFIG_POLICY_CONTEXT (object);
|
||||
g_autoptr (WpCore) core = g_weak_ref_get (&self->core);
|
||||
g_return_if_fail (core);
|
||||
|
||||
/* Register the endpoint link fake factory */
|
||||
wp_factory_new (core, WP_ENDPOINT_LINK_FAKE_FACTORY_NAME,
|
||||
wp_endpoint_link_fake_factory);
|
||||
|
||||
/* Set the configuration path */
|
||||
g_autoptr (WpConfiguration) config = wp_configuration_get_instance (core);
|
||||
wp_configuration_add_path (config, self->config_path);
|
||||
|
||||
/* Register the config policy */
|
||||
g_autoptr (WpConfigPolicy) cp = wp_config_policy_new (config);
|
||||
wp_policy_register (WP_POLICY (cp), core);
|
||||
|
||||
/* Handle done and link-created signals */
|
||||
g_signal_connect (cp, "done", (GCallback) on_done, self);
|
||||
|
||||
G_OBJECT_CLASS (wp_config_policy_context_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_config_policy_context_set_property (GObject * object, guint property_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
WpConfigPolicyContext *self = WP_CONFIG_POLICY_CONTEXT (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_CORE:
|
||||
g_weak_ref_set (&self->core, g_value_get_object (value));
|
||||
break;
|
||||
case PROP_CONFIG_PATH:
|
||||
self->config_path = g_value_dup_string (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_config_policy_context_get_property (GObject * object, guint property_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
WpConfigPolicyContext *self = WP_CONFIG_POLICY_CONTEXT (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_CORE:
|
||||
g_value_take_object (value, g_weak_ref_get (&self->core));
|
||||
break;
|
||||
case PROP_CONFIG_PATH:
|
||||
g_value_set_string (value, self->config_path);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_config_policy_context_finalize (GObject * object)
|
||||
{
|
||||
WpConfigPolicyContext *self = WP_CONFIG_POLICY_CONTEXT (object);
|
||||
|
||||
g_mutex_clear (&self->mutex);
|
||||
g_cond_clear (&self->cond);
|
||||
|
||||
g_weak_ref_clear (&self->core);
|
||||
|
||||
G_OBJECT_CLASS (wp_config_policy_context_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_config_policy_context_init (WpConfigPolicyContext * self)
|
||||
{
|
||||
g_weak_ref_init (&self->core, NULL);
|
||||
|
||||
g_mutex_init (&self->mutex);
|
||||
g_cond_init (&self->cond);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_config_policy_context_class_init (WpConfigPolicyContextClass * klass)
|
||||
{
|
||||
GObjectClass *object_class = (GObjectClass *) klass;
|
||||
|
||||
object_class->constructed = wp_config_policy_context_constructed;
|
||||
object_class->finalize = wp_config_policy_context_finalize;
|
||||
object_class->set_property = wp_config_policy_context_set_property;
|
||||
object_class->get_property = wp_config_policy_context_get_property;
|
||||
|
||||
g_object_class_install_property (object_class, PROP_CORE,
|
||||
g_param_spec_object ("core", "core", "The wireplumber core", WP_TYPE_CORE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_CONFIG_PATH,
|
||||
g_param_spec_string ("config-path", "config-path",
|
||||
"The config-path of the context", NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
WpConfigPolicyContext *
|
||||
wp_config_policy_context_new (WpCore *core, const char *config_path)
|
||||
{
|
||||
return g_object_new (wp_config_policy_context_get_type (),
|
||||
"core", core,
|
||||
"config-path", config_path,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
on_endpoint_created (GObject *initable, GAsyncResult *res, gpointer d)
|
||||
{
|
||||
g_autoptr (WpEndpoint) ep = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
ep = wp_endpoint_new_finish (initable, res, &error);
|
||||
g_return_if_fail (!error);
|
||||
g_return_if_fail (ep);
|
||||
|
||||
/* Register the endpoint */
|
||||
wp_endpoint_register (ep);
|
||||
}
|
||||
|
||||
WpEndpoint *
|
||||
wp_config_policy_context_add_endpoint (WpConfigPolicyContext *self,
|
||||
const char *name, const char *media_class, guint direction,
|
||||
WpProperties *props, const char *role, guint streams, WpEndpointLink **link)
|
||||
{
|
||||
g_autoptr (WpCore) core = g_weak_ref_get (&self->core);
|
||||
g_return_val_if_fail (core, NULL);
|
||||
|
||||
wp_endpoint_fake_new_async (core, name, media_class, direction, props, role,
|
||||
streams, on_endpoint_created, self);
|
||||
|
||||
return wait_for_endpoint (self, link);
|
||||
}
|
||||
|
||||
void
|
||||
wp_config_policy_context_remove_endpoint (WpConfigPolicyContext *self,
|
||||
WpEndpoint *ep)
|
||||
{
|
||||
g_return_if_fail (ep);
|
||||
|
||||
wp_endpoint_unregister (ep);
|
||||
|
||||
wait_for_endpoint (self, NULL);
|
||||
}
|
||||
32
tests/modules/config-policy/context.h
Normal file
32
tests/modules/config-policy/context.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2019 Collabora Ltd.
|
||||
* @author Julian Bouzas <julian.bouzas@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef __WIREPLUMBER_CONFIG_POLICY_CONTEXT_H__
|
||||
#define __WIREPLUMBER_CONFIG_POLICY_CONTEXT_H__
|
||||
|
||||
#include <wp/wp.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
static const guint CONFIG_POLICY_CONTEXT_ID_NONE = G_MAXUINT;
|
||||
|
||||
G_DECLARE_FINAL_TYPE (WpConfigPolicyContext, wp_config_policy_context, WP,
|
||||
CONFIG_POLICY_CONTEXT, GObject);
|
||||
|
||||
WpConfigPolicyContext *wp_config_policy_context_new (WpCore *core,
|
||||
const char *config_path);
|
||||
WpEndpoint *wp_config_policy_context_add_endpoint (WpConfigPolicyContext *self,
|
||||
const char *name, const char *media_class, guint direction,
|
||||
WpProperties *props, const char *role, guint streams,
|
||||
WpEndpointLink **link);
|
||||
void wp_config_policy_context_remove_endpoint (WpConfigPolicyContext *self,
|
||||
WpEndpoint *ep);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
236
tests/modules/config-policy/endpoint-fake.c
Normal file
236
tests/modules/config-policy/endpoint-fake.c
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2019 Collabora Ltd.
|
||||
* @author Julian Bouzas <julian.bouzas@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <wp/wp.h>
|
||||
|
||||
#include "endpoint-fake.h"
|
||||
#include "endpoint-link-fake.h"
|
||||
|
||||
struct _WpEndpointFake
|
||||
{
|
||||
WpEndpoint parent;
|
||||
GTask *init_task;
|
||||
guint id;
|
||||
|
||||
/* Props */
|
||||
WpProperties *props;
|
||||
char *role;
|
||||
guint streams;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_PROPS,
|
||||
PROP_ROLE,
|
||||
PROP_STREAMS,
|
||||
};
|
||||
|
||||
static GAsyncInitableIface *wp_endpoint_fake_parent_interface = NULL;
|
||||
static void wp_endpoint_fake_async_initable_init (gpointer iface,
|
||||
gpointer iface_data);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (WpEndpointFake, wp_endpoint_fake, WP_TYPE_ENDPOINT,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE,
|
||||
wp_endpoint_fake_async_initable_init))
|
||||
|
||||
static WpProperties *
|
||||
wp_endpoint_fake_get_properties (WpEndpoint * ep)
|
||||
{
|
||||
WpEndpointFake *self = WP_ENDPOINT_FAKE (ep);
|
||||
return wp_properties_ref (self->props);
|
||||
}
|
||||
|
||||
static const char *
|
||||
wp_endpoint_fake_get_role (WpEndpoint * ep)
|
||||
{
|
||||
WpEndpointFake *self = WP_ENDPOINT_FAKE (ep);
|
||||
return self->role;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
wp_endpoint_fake_prepare_link (WpEndpoint * ep, guint32 stream_id,
|
||||
WpEndpointLink * link, GVariant ** properties, GError ** error)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static const char *
|
||||
wp_endpoint_fake_get_endpoint_link_factory (WpEndpoint * ep)
|
||||
{
|
||||
return WP_ENDPOINT_LINK_FAKE_FACTORY_NAME;
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_fake_constructed (GObject * object)
|
||||
{
|
||||
WpEndpointFake *self = WP_ENDPOINT_FAKE (object);
|
||||
GVariantDict d;
|
||||
|
||||
for (guint i = 0; i < self->streams; i++) {
|
||||
g_autofree gchar *name = g_strdup_printf ("%u", i);
|
||||
g_variant_dict_init (&d, NULL);
|
||||
g_variant_dict_insert (&d, "id", "u", i);
|
||||
g_variant_dict_insert (&d, "name", "s", name);
|
||||
wp_endpoint_register_stream (WP_ENDPOINT (self), g_variant_dict_end (&d));
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (wp_endpoint_fake_parent_class)->constructed (object);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_fake_set_property (GObject * object, guint property_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
WpEndpointFake *self = WP_ENDPOINT_FAKE (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_PROPS:
|
||||
g_clear_pointer (&self->props, wp_properties_unref);
|
||||
self->props = g_value_dup_boxed (value);
|
||||
if (!self->props)
|
||||
self->props = wp_properties_new_empty ();
|
||||
break;
|
||||
case PROP_ROLE:
|
||||
g_clear_pointer (&self->role, g_free);
|
||||
self->role = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_STREAMS:
|
||||
self->streams = g_value_get_uint (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_fake_get_property (GObject * object, guint property_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
WpEndpointFake *self = WP_ENDPOINT_FAKE (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_PROPS:
|
||||
g_value_take_boxed (value, self->props);
|
||||
break;
|
||||
case PROP_ROLE:
|
||||
g_value_set_string (value, self->role);
|
||||
break;
|
||||
case PROP_STREAMS:
|
||||
g_value_set_uint (value, self->streams);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_fake_finalize (GObject * object)
|
||||
{
|
||||
WpEndpointFake *self = WP_ENDPOINT_FAKE (object);
|
||||
g_clear_pointer (&self->props, wp_properties_unref);
|
||||
G_OBJECT_CLASS (wp_endpoint_fake_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_fake_finish_creation (WpCore *core, GAsyncResult *res,
|
||||
WpEndpointFake *self)
|
||||
{
|
||||
g_task_return_boolean (self->init_task, TRUE);
|
||||
g_clear_object (&self->init_task);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_fake_init_async (GAsyncInitable *initable, int io_priority,
|
||||
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data)
|
||||
{
|
||||
WpEndpointFake *self = WP_ENDPOINT_FAKE (initable);
|
||||
|
||||
self->init_task = g_task_new (initable, cancellable, callback, data);
|
||||
|
||||
wp_endpoint_fake_parent_interface->init_async (initable, io_priority,
|
||||
cancellable, callback, data);
|
||||
|
||||
g_autoptr (WpCore) core = wp_endpoint_get_core(WP_ENDPOINT(self));
|
||||
if (core)
|
||||
wp_core_sync (core, NULL,
|
||||
(GAsyncReadyCallback) wp_endpoint_fake_finish_creation, self);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_fake_async_initable_init (gpointer iface, gpointer iface_data)
|
||||
{
|
||||
GAsyncInitableIface *ai_iface = iface;
|
||||
wp_endpoint_fake_parent_interface = g_type_interface_peek_parent (iface);
|
||||
ai_iface->init_async = wp_endpoint_fake_init_async;
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_fake_init (WpEndpointFake * self)
|
||||
{
|
||||
static guint id = 0;
|
||||
self->id = id++;
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_fake_class_init (WpEndpointFakeClass * klass)
|
||||
{
|
||||
GObjectClass *object_class = (GObjectClass *) klass;
|
||||
WpEndpointClass *endpoint_class = (WpEndpointClass *) klass;
|
||||
|
||||
object_class->constructed = wp_endpoint_fake_constructed;
|
||||
object_class->finalize = wp_endpoint_fake_finalize;
|
||||
object_class->set_property = wp_endpoint_fake_set_property;
|
||||
object_class->get_property = wp_endpoint_fake_get_property;
|
||||
|
||||
endpoint_class->get_properties = wp_endpoint_fake_get_properties;
|
||||
endpoint_class->get_role = wp_endpoint_fake_get_role;
|
||||
endpoint_class->prepare_link = wp_endpoint_fake_prepare_link;
|
||||
endpoint_class->get_endpoint_link_factory =
|
||||
wp_endpoint_fake_get_endpoint_link_factory;
|
||||
|
||||
g_object_class_install_property (object_class, PROP_PROPS,
|
||||
g_param_spec_boxed ("properties", "properties",
|
||||
"The properties of the fake endpoint", WP_TYPE_PROPERTIES,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_ROLE,
|
||||
g_param_spec_string ("role", "role",
|
||||
"The role of the fake endpoint", NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (object_class, PROP_STREAMS,
|
||||
g_param_spec_uint ("streams", "streams",
|
||||
"The number of streams this endpoint has", 0, G_MAXUINT, 0,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
void
|
||||
wp_endpoint_fake_new_async (WpCore *core, const char *name,
|
||||
const char *media_class, guint direction,
|
||||
WpProperties *props, const char *role, guint streams,
|
||||
GAsyncReadyCallback ready, gpointer data)
|
||||
{
|
||||
g_async_initable_new_async (
|
||||
wp_endpoint_fake_get_type (), G_PRIORITY_DEFAULT, NULL, ready, data,
|
||||
"core", core,
|
||||
"name", name,
|
||||
"media-class", media_class,
|
||||
"direction", direction,
|
||||
"properties", props,
|
||||
"role", role,
|
||||
"streams", streams,
|
||||
NULL);
|
||||
}
|
||||
|
||||
guint
|
||||
wp_endpoint_fake_get_id (WpEndpointFake *self)
|
||||
{
|
||||
return self->id;
|
||||
}
|
||||
29
tests/modules/config-policy/endpoint-fake.h
Normal file
29
tests/modules/config-policy/endpoint-fake.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2019 Collabora Ltd.
|
||||
* @author Julian Bouzas <julian.bouzas@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef __WIREPLUMBER_ENDPOINT_FAKE_H__
|
||||
#define __WIREPLUMBER_ENDPOINT_FAKE_H__
|
||||
|
||||
#include <wp/wp.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
G_DECLARE_FINAL_TYPE (WpEndpointFake, wp_endpoint_fake, WP, ENDPOINT_FAKE,
|
||||
WpEndpoint)
|
||||
|
||||
void
|
||||
wp_endpoint_fake_new_async (WpCore *core, const char *name,
|
||||
const char *media_class, guint direction,
|
||||
WpProperties *props, const char *role, guint streams,
|
||||
GAsyncReadyCallback ready, gpointer data);
|
||||
|
||||
guint wp_endpoint_fake_get_id (WpEndpointFake *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
191
tests/modules/config-policy/endpoint-link-fake.c
Normal file
191
tests/modules/config-policy/endpoint-link-fake.c
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2019 Collabora Ltd.
|
||||
* @author Julian Bouzas <julian.bouzas@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <wp/wp.h>
|
||||
|
||||
#include "endpoint-fake.h"
|
||||
#include "endpoint-link-fake.h"
|
||||
|
||||
struct _WpEndpointLinkFake
|
||||
{
|
||||
WpEndpointLink parent;
|
||||
GTask *init_task;
|
||||
guint id;
|
||||
|
||||
/* Props */
|
||||
GWeakRef core;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_CORE
|
||||
};
|
||||
|
||||
static GAsyncInitableIface *wp_endpoint_link_fake_parent_interface = NULL;
|
||||
static void wp_endpoint_link_fake_async_initable_init (gpointer iface,
|
||||
gpointer iface_data);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (WpEndpointLinkFake, wp_endpoint_link_fake,
|
||||
WP_TYPE_ENDPOINT_LINK,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE,
|
||||
wp_endpoint_link_fake_async_initable_init))
|
||||
|
||||
static gboolean
|
||||
wp_endpoint_link_fake_create (WpEndpointLink * epl, GVariant * src_data,
|
||||
GVariant * sink_data, GError ** error)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_fake_destroy (WpEndpointLink * epl)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_fake_set_property (GObject * object, guint property_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
WpEndpointLinkFake *self = WP_ENDPOINT_LINK_FAKE (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_CORE:
|
||||
g_weak_ref_set (&self->core, g_value_get_object (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_fake_get_property (GObject * object, guint property_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
WpEndpointLinkFake *self = WP_ENDPOINT_LINK_FAKE (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_CORE:
|
||||
g_value_take_object (value, g_weak_ref_get (&self->core));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_fake_finalize (GObject * object)
|
||||
{
|
||||
WpEndpointLinkFake *self = WP_ENDPOINT_LINK_FAKE (object);
|
||||
g_clear_object (&self->init_task);
|
||||
G_OBJECT_CLASS (wp_endpoint_link_fake_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_fake_finish_creation (WpCore *core, GAsyncResult *res,
|
||||
WpEndpointLinkFake *self)
|
||||
{
|
||||
g_task_return_boolean (self->init_task, TRUE);
|
||||
g_clear_object (&self->init_task);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_fake_init_async (GAsyncInitable *initable, int io_priority,
|
||||
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data)
|
||||
{
|
||||
WpEndpointLinkFake *self = WP_ENDPOINT_LINK_FAKE (initable);
|
||||
|
||||
self->init_task = g_task_new (initable, cancellable, callback, data);
|
||||
|
||||
wp_endpoint_link_fake_parent_interface->init_async (initable,
|
||||
io_priority, cancellable, callback, data);
|
||||
|
||||
g_autoptr (WpCore) core = g_weak_ref_get (&self->core);
|
||||
if (core)
|
||||
wp_core_sync (core, NULL,
|
||||
(GAsyncReadyCallback) wp_endpoint_link_fake_finish_creation, self);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_fake_async_initable_init (gpointer iface,
|
||||
gpointer iface_data)
|
||||
{
|
||||
GAsyncInitableIface *ai_iface = iface;
|
||||
wp_endpoint_link_fake_parent_interface = g_type_interface_peek_parent (iface);
|
||||
ai_iface->init_async = wp_endpoint_link_fake_init_async;
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_fake_init (WpEndpointLinkFake * self)
|
||||
{
|
||||
static guint id = 0;
|
||||
self->id = id++;
|
||||
}
|
||||
|
||||
static void
|
||||
wp_endpoint_link_fake_class_init (WpEndpointLinkFakeClass * klass)
|
||||
{
|
||||
GObjectClass *object_class = (GObjectClass *) klass;
|
||||
WpEndpointLinkClass *link_class = (WpEndpointLinkClass *) klass;
|
||||
|
||||
object_class->finalize = wp_endpoint_link_fake_finalize;
|
||||
object_class->get_property = wp_endpoint_link_fake_get_property;
|
||||
object_class->set_property = wp_endpoint_link_fake_set_property;
|
||||
|
||||
link_class->create = wp_endpoint_link_fake_create;
|
||||
link_class->destroy = wp_endpoint_link_fake_destroy;
|
||||
|
||||
g_object_class_install_property (object_class, PROP_CORE,
|
||||
g_param_spec_object ("core", "core", "The wireplumber core",
|
||||
WP_TYPE_CORE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
||||
void
|
||||
wp_endpoint_link_fake_factory (WpFactory * factory, GType type,
|
||||
GVariant * properties, GAsyncReadyCallback ready, gpointer data)
|
||||
{
|
||||
g_autoptr (WpCore) core = NULL;
|
||||
guint64 src, sink;
|
||||
guint src_stream, sink_stream;
|
||||
gboolean keep;
|
||||
|
||||
/* Get the Core */
|
||||
core = wp_factory_get_core(factory);
|
||||
g_return_if_fail (core);
|
||||
|
||||
/* Get the properties */
|
||||
if (!g_variant_lookup (properties, "src", "t", &src))
|
||||
return;
|
||||
if (!g_variant_lookup (properties, "src-stream", "u", &src_stream))
|
||||
return;
|
||||
if (!g_variant_lookup (properties, "sink", "t", &sink))
|
||||
return;
|
||||
if (!g_variant_lookup (properties, "sink-stream", "u", &sink_stream))
|
||||
return;
|
||||
if (!g_variant_lookup (properties, "keep", "b", &keep))
|
||||
return;
|
||||
|
||||
/* Create the endpoint link */
|
||||
g_async_initable_new_async (
|
||||
wp_endpoint_link_fake_get_type (), G_PRIORITY_DEFAULT, NULL, ready, data,
|
||||
"src", (gpointer)src,
|
||||
"src-stream", src_stream,
|
||||
"sink", (gpointer)sink,
|
||||
"sink-stream", sink_stream,
|
||||
"keep", keep,
|
||||
"core", core,
|
||||
NULL);
|
||||
}
|
||||
|
||||
guint
|
||||
wp_endpoint_link_fake_get_id (WpEndpointLinkFake *self)
|
||||
{
|
||||
return self->id;
|
||||
}
|
||||
28
tests/modules/config-policy/endpoint-link-fake.h
Normal file
28
tests/modules/config-policy/endpoint-link-fake.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* WirePlumber
|
||||
*
|
||||
* Copyright © 2019 Collabora Ltd.
|
||||
* @author Julian Bouzas <julian.bouzas@collabora.com>
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef __WIREPLUMBER_ENDPOINT_LINK_FAKE_H__
|
||||
#define __WIREPLUMBER_ENDPOINT_LINK_FAKE_H__
|
||||
|
||||
#include <wp/wp.h>
|
||||
|
||||
#define WP_ENDPOINT_LINK_FAKE_FACTORY_NAME "endpoint-link-fake"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
G_DECLARE_FINAL_TYPE (WpEndpointLinkFake, wp_endpoint_link_fake, WP,
|
||||
ENDPOINT_LINK_FAKE, WpEndpointLink)
|
||||
|
||||
void wp_endpoint_link_fake_factory (WpFactory * factory, GType type,
|
||||
GVariant * properties, GAsyncReadyCallback ready, gpointer data);
|
||||
|
||||
guint wp_endpoint_link_fake_get_id (WpEndpointLinkFake *self);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
@ -14,3 +14,20 @@ test(
|
|||
dependencies: common_deps),
|
||||
env: common_env,
|
||||
)
|
||||
|
||||
test(
|
||||
'test-config-policy',
|
||||
executable('test-config-policy',
|
||||
[
|
||||
'config-policy.c',
|
||||
'config-policy/context.c',
|
||||
'config-policy/endpoint-fake.c',
|
||||
'config-policy/endpoint-link-fake.c',
|
||||
'../../modules/module-config-policy/config-policy.c',
|
||||
'../../modules/module-config-policy/parser-streams.c',
|
||||
'../../modules/module-config-policy/parser-endpoint-link.c'
|
||||
],
|
||||
dependencies: common_deps + [wptoml_dep]),
|
||||
env: common_env,
|
||||
workdir : meson.current_source_dir(),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue