| 1 |
/* WirePlumber |
| 2 |
* |
| 3 |
* Copyright © 2021 Collabora Ltd. |
| 4 |
* @author George Kiagiadakis <[email protected]> |
| 5 |
* |
| 6 |
* SPDX-License-Identifier: MIT |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "../common/base-test-fixture.h" |
| 10 |
|
| 11 |
struct _TestSiDummy |
| 12 |
{ |
| 13 |
WpSessionItem parent; |
| 14 |
}; |
| 15 |
|
| 16 |
G_DECLARE_FINAL_TYPE (TestSiDummy, si_dummy, TEST, SI_DUMMY, WpSessionItem) |
| 17 |
G_DEFINE_TYPE (TestSiDummy, si_dummy, WP_TYPE_SESSION_ITEM) |
| 18 |
|
| 19 |
static void |
| 20 |
si_dummy_init (TestSiDummy * self) |
| 21 |
{ |
| 22 |
} |
| 23 |
|
| 24 |
static gboolean |
| 25 |
si_dummy_configure (WpSessionItem * item, WpProperties * props) |
| 26 |
{ |
| 27 |
TestSiDummy *self = TEST_SI_DUMMY (item); |
| 28 |
wp_session_item_set_properties (WP_SESSION_ITEM (self), props); |
| 29 |
return TRUE; |
| 30 |
} |
| 31 |
|
| 32 |
static void |
| 33 |
si_dummy_class_init (TestSiDummyClass * klass) |
| 34 |
{ |
| 35 |
WpSessionItemClass *si_class = (WpSessionItemClass *) klass; |
| 36 |
si_class->configure = si_dummy_configure; |
| 37 |
} |
| 38 |
|
| 39 |
typedef struct { |
| 40 |
WpBaseTestFixture base; |
| 41 |
WpObjectManager *om; |
| 42 |
} TestFixture; |
| 43 |
|
| 44 |
static void |
| 45 |
test_om_setup (TestFixture *self, gconstpointer user_data) |
| 46 |
{ |
| 47 |
wp_base_test_fixture_setup (&self->base, WP_BASE_TEST_FLAG_CLIENT_CORE); |
| 48 |
} |
| 49 |
|
| 50 |
static void |
| 51 |
test_om_teardown (TestFixture *self, gconstpointer user_data) |
| 52 |
{ |
| 53 |
wp_base_test_fixture_teardown (&self->base); |
| 54 |
} |
| 55 |
|
| 56 |
static void |
| 57 |
test_om_interest_on_pw_props (TestFixture *f, gconstpointer user_data) |
| 58 |
{ |
| 59 |
g_autoptr (WpNode) node = NULL; |
| 60 |
g_autoptr (WpObjectManager) om = NULL; |
| 61 |
|
| 62 |
/* load modules on the server side */ |
| 63 |
{ |
| 64 |
g_autoptr (WpTestServerLocker) lock = |
| 65 |
wp_test_server_locker_new (&f->base.server); |
| 66 |
|
| 67 |
g_assert_cmpint (pw_context_add_spa_lib (f->base.server.context, |
| 68 |
"audiotestsrc", "audiotestsrc/libspa-audiotestsrc"), ==, 0); |
| 69 |
if (!test_is_spa_lib_installed (&f->base, "audiotestsrc")) { |
| 70 |
g_test_skip ("The pipewire audiotestsrc factory was not found"); |
| 71 |
return; |
| 72 |
} |
| 73 |
g_assert_nonnull (pw_context_load_module (f->base.server.context, |
| 74 |
"libpipewire-module-adapter", NULL, NULL)); |
| 75 |
} |
| 76 |
|
| 77 |
/* export node on the client core */ |
| 78 |
node = wp_node_new_from_factory (f->base.client_core, |
| 79 |
"adapter", |
| 80 |
wp_properties_new ( |
| 81 |
"factory.name", "audiotestsrc", |
| 82 |
"node.name", "Test Source", |
| 83 |
"test.answer", "42", |
| 84 |
NULL)); |
| 85 |
g_assert_nonnull (node); |
| 86 |
|
| 87 |
wp_object_activate (WP_OBJECT (node), WP_OBJECT_FEATURES_ALL, |
| 88 |
NULL, (GAsyncReadyCallback) test_object_activate_finish_cb, f); |
| 89 |
g_main_loop_run (f->base.loop); |
| 90 |
|
| 91 |
/* ensure the base core is in sync */ |
| 92 |
wp_core_sync (f->base.core, NULL, (GAsyncReadyCallback) test_core_done_cb, f); |
| 93 |
g_main_loop_run (f->base.loop); |
| 94 |
|
| 95 |
/* request that node from the base core */ |
| 96 |
om = wp_object_manager_new (); |
| 97 |
wp_object_manager_add_interest (om, WP_TYPE_NODE, |
| 98 |
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "node.name", "=s", "Test Source", |
| 99 |
WP_CONSTRAINT_TYPE_PW_PROPERTY, "test.answer", "=s", "42", |
| 100 |
NULL); |
| 101 |
test_ensure_object_manager_is_installed (om, f->base.core, f->base.loop); |
| 102 |
|
| 103 |
g_assert_cmpuint (wp_object_manager_get_n_objects (om), ==, 1); |
| 104 |
g_clear_object (&om); |
| 105 |
|
| 106 |
/* request "test.answer" to be absent... this will not match */ |
| 107 |
om = wp_object_manager_new (); |
| 108 |
wp_object_manager_add_interest (om, WP_TYPE_NODE, |
| 109 |
WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "node.name", "=s", "Test Source", |
| 110 |
WP_CONSTRAINT_TYPE_PW_PROPERTY, "test.answer", "-", |
| 111 |
NULL); |
| 112 |
test_ensure_object_manager_is_installed (om, f->base.core, f->base.loop); |
| 113 |
|
| 114 |
g_assert_cmpuint (wp_object_manager_get_n_objects (om), ==, 0); |
| 115 |
} |
| 116 |
|
| 117 |
static void |
| 118 |
test_om_iterate_remove (TestFixture *f, gconstpointer user_data) |
| 119 |
{ |
| 120 |
g_autoptr (WpObjectManager) om = NULL; |
| 121 |
WpSessionItem *si = NULL; |
| 122 |
|
| 123 |
si = g_object_new (si_dummy_get_type (), "core", f->base.core, NULL); |
| 124 |
g_assert_true (wp_session_item_configure (si, |
| 125 |
wp_properties_new ("property1", "4321", NULL))); |
| 126 |
wp_session_item_register (si); |
| 127 |
|
| 128 |
si = g_object_new (si_dummy_get_type (), "core", f->base.core, NULL); |
| 129 |
g_assert_true (wp_session_item_configure (si, |
| 130 |
wp_properties_new ("property1", "2345", NULL))); |
| 131 |
wp_session_item_register (si); |
| 132 |
|
| 133 |
si = g_object_new (si_dummy_get_type (), "core", f->base.core, NULL); |
| 134 |
g_assert_true (wp_session_item_configure (si, |
| 135 |
wp_properties_new ("property1", "1234", NULL))); |
| 136 |
wp_session_item_register (si); |
| 137 |
|
| 138 |
si = g_object_new (si_dummy_get_type (), "core", f->base.core, NULL); |
| 139 |
g_assert_true (wp_session_item_configure (si, |
| 140 |
wp_properties_new ("property1", "1234", NULL))); |
| 141 |
wp_session_item_register (si); |
| 142 |
|
| 143 |
om = wp_object_manager_new (); |
| 144 |
wp_object_manager_add_interest (om, si_dummy_get_type (), NULL); |
| 145 |
test_ensure_object_manager_is_installed (om, f->base.core, f->base.loop); |
| 146 |
|
| 147 |
{ |
| 148 |
g_autoptr (WpIterator) it = wp_object_manager_new_iterator (om); |
| 149 |
g_auto (GValue) value = G_VALUE_INIT; |
| 150 |
while (wp_iterator_next (it, &value)) { |
| 151 |
si = g_value_get_object (&value); |
| 152 |
g_assert_true (WP_IS_SESSION_ITEM (si)); |
| 153 |
if (!g_strcmp0 (wp_session_item_get_property (si, "property1"), "1234")) { |
| 154 |
wp_session_item_remove (si); |
| 155 |
} |
| 156 |
g_value_unset (&value); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
g_assert_cmpint (wp_object_manager_get_n_objects (om), ==, 2); |
| 161 |
g_assert_null (wp_object_manager_lookup (om, si_dummy_get_type (), |
| 162 |
WP_CONSTRAINT_TYPE_PW_PROPERTY, "property1", "=s", "1234", NULL)); |
| 163 |
} |
| 164 |
|
| 165 |
gint |
| 166 |
main (gint argc, gchar *argv[]) |
| 167 |
{ |
| 168 |
g_test_init (&argc, &argv, NULL); |
| 169 |
wp_init (WP_INIT_ALL); |
| 170 |
|
| 171 |
g_test_add ("/wp/om/interest-on-pw-props", TestFixture, NULL, |
| 172 |
test_om_setup, test_om_interest_on_pw_props, test_om_teardown); |
| 173 |
g_test_add ("/wp/om/iterate_remove", TestFixture, NULL, |
| 174 |
test_om_setup, test_om_iterate_remove, test_om_teardown); |
| 175 |
|
| 176 |
return g_test_run (); |
| 177 |
} |