Debian Codegraph @

tests/modules/si-audio-adapter.c

raw
1 /* WirePlumber
2 *
3 * Copyright © 2020 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 typedef struct {
12 WpBaseTestFixture base;
13 } TestFixture;
14
15 static void
16 on_plugin_loaded (WpCore * core, GAsyncResult * res, TestFixture *f)
17 {
18 gboolean loaded;
19 GError *error = NULL;
20
21 loaded = wp_core_load_component_finish (core, res, &error);
22 g_assert_no_error (error);
23 g_assert_true (loaded);
24
25 g_main_loop_quit (f->base.loop);
26 }
27
28 static void
29 test_si_audio_adapter_setup (TestFixture * f, gconstpointer user_data)
30 {
31 wp_base_test_fixture_setup (&f->base, 0);
32
33 /* load modules */
34 {
35 g_autoptr (WpTestServerLocker) lock =
36 wp_test_server_locker_new (&f->base.server);
37
38 g_assert_cmpint (pw_context_add_spa_lib (f->base.server.context,
39 "audiotestsrc", "audiotestsrc/libspa-audiotestsrc"), ==, 0);
40 if (!test_is_spa_lib_installed (&f->base, "audiotestsrc")) {
41 g_test_skip ("The pipewire audiotestsrc factory was not found");
42 return;
43 }
44 g_assert_nonnull (pw_context_load_module (f->base.server.context,
45 "libpipewire-module-spa-node-factory", NULL, NULL));
46 g_assert_nonnull (pw_context_load_module (f->base.server.context,
47 "libpipewire-module-adapter", NULL, NULL));
48 }
49 {
50 wp_core_load_component (f->base.core,
51 "libwireplumber-module-si-audio-adapter", "module", NULL, NULL, NULL,
52 (GAsyncReadyCallback) on_plugin_loaded, f);
53 g_main_loop_run (f->base.loop);
54 }
55 }
56
57 static void
58 test_si_audio_adapter_teardown (TestFixture * f, gconstpointer user_data)
59 {
60 wp_base_test_fixture_teardown (&f->base);
61 }
62
63 static void
64 test_si_audio_adapter_configure_activate (TestFixture * f,
65 gconstpointer user_data)
66 {
67 g_autoptr (WpNode) node = NULL;
68 g_autoptr (WpSessionItem) adapter = NULL;
69
70 /* skip test if audiotestsrc is not installed */
71 if (!test_is_spa_lib_installed (&f->base, "audiotestsrc")) {
72 g_test_skip ("The pipewire audiotestsrc factory was not found");
73 return;
74 }
75
76 /* create audiotestsrc adapter node */
77 node = wp_node_new_from_factory (f->base.core,
78 "adapter",
79 wp_properties_new (
80 "factory.name", "audiotestsrc",
81 "node.name", "audiotestsrc.adapter",
82 NULL));
83 g_assert_nonnull (node);
84 wp_object_activate (WP_OBJECT (node), WP_OBJECT_FEATURES_ALL,
85 NULL, (GAsyncReadyCallback) test_object_activate_finish_cb, f);
86 g_main_loop_run (f->base.loop);
87
88 /* create adapter */
89 adapter = wp_session_item_make (f->base.core, "si-audio-adapter");
90 g_assert_nonnull (adapter);
91 g_assert_true (WP_IS_SI_LINKABLE (adapter));
92
93 /* configure */
94 {
95 WpProperties *props = wp_properties_new_empty ();
96 wp_properties_setf (props, "item.node", "%p", node);
97 wp_properties_set (props, "media.class", "Audio/Source");
98 g_assert_true (wp_session_item_configure (adapter, props));
99 g_assert_true (wp_session_item_is_configured (adapter));
100 }
101
102 /* validate configuration */
103 {
104 const gchar *str = NULL;
105 g_autoptr (WpProperties) props = wp_session_item_get_properties (adapter);
106 g_assert_nonnull (props);
107 str = wp_properties_get (props, "item.factory.name");
108 g_assert_nonnull (str);
109 g_assert_cmpstr ("si-audio-adapter", ==, str);
110 }
111
112 /* activate */
113 wp_object_activate (WP_OBJECT (adapter), WP_SESSION_ITEM_FEATURE_ACTIVE,
114 NULL, (GAsyncReadyCallback) test_object_activate_finish_cb, f);
115 g_main_loop_run (f->base.loop);
116 g_assert_cmphex (wp_object_get_active_features (WP_OBJECT (adapter)), ==,
117 WP_SESSION_ITEM_FEATURE_ACTIVE);
118
119 /* deactivate - configuration should not be altered */
120 wp_object_deactivate (WP_OBJECT (adapter), WP_SESSION_ITEM_FEATURE_ACTIVE);
121 g_assert_cmphex (wp_object_get_active_features (WP_OBJECT (adapter)), ==, 0);
122 g_assert_true (wp_session_item_is_configured (adapter));
123
124 /* reset */
125 wp_session_item_reset (adapter);
126 g_assert_false (wp_session_item_is_configured (adapter));
127 }
128
129 gint
130 main (gint argc, gchar *argv[])
131 {
132 g_test_init (&argc, &argv, NULL);
133 wp_init (WP_INIT_ALL);
134
135 /* configure-activate */
136
137 g_test_add ("/modules/si-audio-adapter/configure-activate",
138 TestFixture, NULL,
139 test_si_audio_adapter_setup,
140 test_si_audio_adapter_configure_activate,
141 test_si_audio_adapter_teardown);
142
143 return g_test_run ();
144 }