| 1 |
/* WirePlumber |
| 2 |
* |
| 3 |
* Copyright © 2021 Collabora Ltd. |
| 4 |
* @author Ashok Sidipotu <[email protected]> |
| 5 |
* |
| 6 |
* SPDX-License-Identifier: MIT |
| 7 |
*/ |
| 8 |
#include "../common/base-test-fixture.h" |
| 9 |
|
| 10 |
typedef struct { |
| 11 |
WpBaseTestFixture base; |
| 12 |
WpObjectManager *om; |
| 13 |
} TestFixture; |
| 14 |
|
| 15 |
static void |
| 16 |
test_factory_setup (TestFixture *self, gconstpointer user_data) |
| 17 |
{ |
| 18 |
wp_base_test_fixture_setup (&self->base, 0); |
| 19 |
self->om = wp_object_manager_new (); |
| 20 |
} |
| 21 |
|
| 22 |
static void |
| 23 |
test_factory_teardown (TestFixture *self, gconstpointer user_data) |
| 24 |
{ |
| 25 |
g_clear_object (&self->om); |
| 26 |
wp_base_test_fixture_teardown (&self->base); |
| 27 |
} |
| 28 |
|
| 29 |
static void |
| 30 |
test_factory_enumeration_object_added (WpObjectManager *om, |
| 31 |
WpFactory *factory, TestFixture *fixture) |
| 32 |
{ |
| 33 |
g_autoptr (WpProperties) properties = |
| 34 |
wp_global_proxy_get_global_properties(WP_GLOBAL_PROXY(factory)); |
| 35 |
const gchar* name = wp_properties_get (properties, PW_KEY_FACTORY_NAME); |
| 36 |
g_assert_nonnull(name); |
| 37 |
g_debug("factory name=%s", name); |
| 38 |
|
| 39 |
/* among all the pw factory objects look for client-node-factory object */ |
| 40 |
if (!g_strcmp0(name, "client-node")) |
| 41 |
g_main_loop_quit(fixture->base.loop); |
| 42 |
} |
| 43 |
|
| 44 |
static void |
| 45 |
test_factory_enumeration (TestFixture *self, gconstpointer user_data) |
| 46 |
{ |
| 47 |
g_signal_connect (self->om, "object_added", |
| 48 |
(GCallback) test_factory_enumeration_object_added, self); |
| 49 |
|
| 50 |
wp_object_manager_add_interest(self->om, WP_TYPE_FACTORY, NULL); |
| 51 |
wp_core_install_object_manager(self->base.core, self->om); |
| 52 |
g_main_loop_run(self->base.loop); |
| 53 |
} |
| 54 |
|
| 55 |
gint |
| 56 |
main (gint argc, gchar *argv[]) |
| 57 |
{ |
| 58 |
g_test_init (&argc, &argv, NULL); |
| 59 |
wp_init (WP_INIT_ALL); |
| 60 |
|
| 61 |
g_test_add ("/wp/factory/enumeration", TestFixture, NULL, |
| 62 |
test_factory_setup, test_factory_enumeration, test_factory_teardown); |
| 63 |
|
| 64 |
return g_test_run (); |
| 65 |
} |