1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
/* WirePlumber
*
* Copyright © 2020 Collabora Ltd.
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#include "../common/base-test-fixture.h"
typedef struct {
WpBaseTestFixture base;
} TestFixture;
typedef struct {
const gchar *factory;
const gchar *name;
const gchar *media_class;
const gchar *expected_media_class;
WpDirection expected_direction;
} TestData;
static void
on_plugin_loaded (WpCore * core, GAsyncResult * res, TestFixture *f)
{
gboolean loaded;
GError *error = NULL;
loaded = wp_core_load_component_finish (core, res, &error);
g_assert_no_error (error);
g_assert_true (loaded);
g_main_loop_quit (f->base.loop);
}
static void
test_si_node_setup (TestFixture * f, gconstpointer user_data)
{
wp_base_test_fixture_setup (&f->base, 0);
/* load modules */
{
g_autoptr (WpTestServerLocker) lock =
wp_test_server_locker_new (&f->base.server);
g_assert_cmpint (pw_context_add_spa_lib (f->base.server.context,
"audiotestsrc", "audiotestsrc/libspa-audiotestsrc"), ==, 0);
if (!test_is_spa_lib_installed (&f->base, "audiotestsrc")) {
g_test_skip ("The pipewire audiotestsrc factory was not found");
return;
}
g_assert_nonnull (pw_context_load_module (f->base.server.context,
"libpipewire-module-spa-node-factory", NULL, NULL));
}
{
wp_core_load_component (f->base.core,
"libwireplumber-module-si-node", "module", NULL, NULL, NULL,
(GAsyncReadyCallback) on_plugin_loaded, f);
g_main_loop_run (f->base.loop);
}
}
static void
test_si_node_teardown (TestFixture * f, gconstpointer user_data)
{
wp_base_test_fixture_teardown (&f->base);
}
static void
test_si_node_configure_activate (TestFixture * f, gconstpointer user_data)
{
const TestData *data = user_data;
g_autoptr (WpNode) node = NULL;
g_autoptr (WpSessionItem) item = NULL;
/* skip test if spa factory is not installed */
if (!test_is_spa_lib_installed (&f->base, data->factory)) {
g_autofree gchar *msg = NULL;
msg = g_strdup_printf ("The pipewire %s factory was not found",
data->factory);
g_test_skip (msg);
return;
}
/* create item */
item = wp_session_item_make (f->base.core, "si-node");
g_assert_nonnull (item);
g_assert_true (WP_IS_SI_LINKABLE (item));
node = wp_node_new_from_factory (f->base.core,
"spa-node-factory",
wp_properties_new (
"factory.name", data->factory,
"node.name", data->name,
NULL));
g_assert_nonnull (node);
wp_object_activate (WP_OBJECT (node), WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL,
NULL, (GAsyncReadyCallback) test_object_activate_finish_cb, f);
g_main_loop_run (f->base.loop);
/* configure */
{
WpProperties *props = wp_properties_new_empty ();
wp_properties_setf (props, "item.node", "%p", node);
wp_properties_set (props, "media.class", data->media_class);
g_assert_true (wp_session_item_configure (item, props));
g_assert_true (wp_session_item_is_configured (item));
}
{
const gchar *str = NULL;
g_autoptr (WpProperties) props = wp_session_item_get_properties (item);
g_assert_nonnull (props);
str = wp_properties_get (props, "media.class");
g_assert_nonnull (str);
g_assert_cmpstr (data->expected_media_class, ==, str);
str = wp_properties_get (props, "item.factory.name");
g_assert_nonnull (str);
g_assert_cmpstr ("si-node", ==, str);
}
/* activate */
wp_object_activate (WP_OBJECT (item), WP_SESSION_ITEM_FEATURE_ACTIVE,
NULL, (GAsyncReadyCallback) test_object_activate_finish_cb, f);
g_main_loop_run (f->base.loop);
g_assert_cmphex (wp_object_get_active_features (WP_OBJECT (item)), ==,
WP_SESSION_ITEM_FEATURE_ACTIVE);
g_assert_cmphex (wp_object_get_active_features (WP_OBJECT (node)), ==,
WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL | WP_NODE_FEATURE_PORTS);
if (data->expected_direction == WP_DIRECTION_INPUT)
g_assert_cmpuint (wp_node_get_n_input_ports (node, NULL), ==, 1);
else
g_assert_cmpuint (wp_node_get_n_output_ports (node, NULL), ==, 1);
g_assert_cmpuint (wp_node_get_n_ports (node), ==, 1);
{
guint32 node_id, port_id, channel;
g_autoptr (GVariant) v =
wp_si_linkable_get_ports (WP_SI_LINKABLE (item),
(data->expected_direction == WP_DIRECTION_INPUT) ? "input" : "output");
g_assert_true (g_variant_is_of_type (v, G_VARIANT_TYPE ("a(uuu)")));
g_assert_cmpint (g_variant_n_children (v), ==, 1);
g_variant_get_child (v, 0, "(uuu)", &node_id, &port_id, &channel);
g_assert_cmpuint (node_id, ==, wp_proxy_get_bound_id (WP_PROXY (node)));
g_assert_cmpuint (channel, ==, 0);
{
g_autoptr (WpIterator) it = wp_node_new_ports_iterator (node);
g_auto (GValue) val = G_VALUE_INIT;
WpProxy *port;
g_assert_true (wp_iterator_next (it, &val));
port = g_value_get_object (&val);
g_assert_nonnull (port);
g_assert_cmpuint (port_id, ==, wp_proxy_get_bound_id (port));
}
}
/* deactivate - configuration should not be altered */
wp_object_deactivate (WP_OBJECT (item), WP_SESSION_ITEM_FEATURE_ACTIVE);
g_assert_cmphex (wp_object_get_active_features (WP_OBJECT (item)), ==, 0);
g_assert_true (wp_session_item_is_configured (item));
g_assert_cmphex (wp_object_get_active_features (WP_OBJECT (node)), ==,
WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL | WP_NODE_FEATURE_PORTS);
{
const gchar *str = NULL;
g_autoptr (WpProperties) props = wp_session_item_get_properties (item);
g_assert_nonnull (props);
str = wp_properties_get (props, "media.class");
g_assert_nonnull (str);
g_assert_cmpstr (data->expected_media_class, ==, str);
str = wp_properties_get (props, "item.factory.name");
g_assert_nonnull (str);
g_assert_cmpstr ("si-node", ==, str);
}
/* reset - configuration resets */
wp_session_item_reset (item);
g_assert_false (wp_session_item_is_configured (item));
{
g_autoptr (WpProperties) props =
wp_session_item_get_properties (item);
g_assert_null (props);
}
}
gint
main (gint argc, gchar *argv[])
{
g_test_init (&argc, &argv, NULL);
wp_init (WP_INIT_ALL);
/* data */
const TestData nullsink_data = {
"support.null-audio-sink", "nullsink0", "Fake/Sink", "Fake/Sink", WP_DIRECTION_INPUT
};
const TestData audiotestsrc_data = {
"audiotestsrc", "audiotestsrc0", "Audio/Source", "Audio/Source", WP_DIRECTION_OUTPUT
};
/* configure-activate */
g_test_add ("/modules/si-node/configure-activate/nullsink",
TestFixture, &nullsink_data,
test_si_node_setup,
test_si_node_configure_activate,
test_si_node_teardown);
g_test_add ("/modules/si-node/configure-activate/audiotestsrc",
TestFixture, &audiotestsrc_data,
test_si_node_setup,
test_si_node_configure_activate,
test_si_node_teardown);
return g_test_run ();
}
|