wireplumber/tests/wp/object-manager.c
George Kiagiadakis 1ca67abc66 object-manager: support declaring interest on all properties of globals
Until now, object manager could only match pw global properties on
pw global objects, because this is the only available properties set
at the time the registry creates the global.

With this change, the object manager will now bind the proxy
if the type and the pw global properties have matched and will wait
until the proxy is available with all of its properties and tries
the check again.
2021-06-07 17:47:42 +03:00

95 lines
2.8 KiB
C

/* WirePlumber
*
* Copyright © 2021 Collabora Ltd.
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#include "../common/base-test-fixture.h"
typedef struct {
WpBaseTestFixture base;
WpObjectManager *om;
} TestFixture;
static void
test_om_setup (TestFixture *self, gconstpointer user_data)
{
wp_base_test_fixture_setup (&self->base, WP_BASE_TEST_FLAG_CLIENT_CORE);
}
static void
test_om_teardown (TestFixture *self, gconstpointer user_data)
{
wp_base_test_fixture_teardown (&self->base);
}
static void
test_om_interest_on_pw_props (TestFixture *f, gconstpointer user_data)
{
g_autoptr (WpNode) node = NULL;
g_autoptr (WpObjectManager) om = NULL;
/* load audiotestsrc on the server side */
{
g_autoptr (WpTestServerLocker) lock =
wp_test_server_locker_new (&f->base.server);
g_assert_cmpint (pw_context_add_spa_lib (f->base.server.context,
"fake*", "test/libspa-test"), ==, 0);
g_assert_nonnull (pw_context_load_module (f->base.server.context,
"libpipewire-module-spa-node-factory", NULL, NULL));
}
/* export node on the client core */
node = wp_node_new_from_factory (f->base.client_core,
"spa-node-factory",
wp_properties_new (
"factory.name", "fakesink",
"node.name", "Fakesink",
"test.answer", "42",
NULL));
g_assert_nonnull (node);
wp_object_activate (WP_OBJECT (node), WP_OBJECT_FEATURES_ALL,
NULL, (GAsyncReadyCallback) test_object_activate_finish_cb, f);
g_main_loop_run (f->base.loop);
/* ensure the base core is in sync */
wp_core_sync (f->base.core, NULL, (GAsyncReadyCallback) test_core_done_cb, f);
g_main_loop_run (f->base.loop);
/* request that node from the base core */
om = wp_object_manager_new ();
wp_object_manager_add_interest (om, WP_TYPE_NODE,
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "node.name", "=s", "Fakesink",
WP_CONSTRAINT_TYPE_PW_PROPERTY, "test.answer", "=s", "42",
NULL);
test_ensure_object_manager_is_installed (om, f->base.core, f->base.loop);
g_assert_cmpuint (wp_object_manager_get_n_objects (om), ==, 1);
g_clear_object (&om);
/* request "test.answer" to be absent... this will not match */
om = wp_object_manager_new ();
wp_object_manager_add_interest (om, WP_TYPE_NODE,
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "node.name", "=s", "Fakesink",
WP_CONSTRAINT_TYPE_PW_PROPERTY, "test.answer", "-",
NULL);
test_ensure_object_manager_is_installed (om, f->base.core, f->base.loop);
g_assert_cmpuint (wp_object_manager_get_n_objects (om), ==, 0);
}
gint
main (gint argc, gchar *argv[])
{
g_test_init (&argc, &argv, NULL);
wp_init (WP_INIT_ALL);
g_test_add ("/wp/om/interest-on-pw-props", TestFixture, NULL,
test_om_setup, test_om_interest_on_pw_props, test_om_teardown);
return g_test_run ();
}