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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
/* WirePlumber
*
* Copyright © 2019 Collabora Ltd.
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#include "../common/base-test-fixture.h"
typedef struct {
WpBaseTestFixture base;
/* the object manager that listens for proxies */
WpObjectManager *om;
} TestFixture;
static void
test_proxy_setup (TestFixture *self, gconstpointer user_data)
{
wp_base_test_fixture_setup (&self->base, 0);
self->om = wp_object_manager_new ();
}
static void
test_proxy_teardown (TestFixture *self, gconstpointer user_data)
{
g_clear_object (&self->om);
wp_base_test_fixture_teardown (&self->base);
}
static void
test_proxy_basic_activated (WpObject *proxy, GAsyncResult *res,
TestFixture *fixture)
{
g_autoptr (GError) error = NULL;
g_assert_true (wp_object_activate_finish (proxy, res, &error));
g_assert_no_error (error);
g_assert_true (wp_object_get_active_features (proxy) & WP_PROXY_FEATURE_BOUND);
g_assert_nonnull (wp_proxy_get_pw_proxy (WP_PROXY (proxy)));
g_main_loop_quit (fixture->base.loop);
}
static void
test_proxy_basic_object_added (WpObjectManager *om, WpGlobalProxy *proxy,
TestFixture *fixture)
{
g_assert_nonnull (proxy);
{
g_autoptr (WpCore) pcore = NULL;
g_autoptr (WpCore) omcore = NULL;
g_object_get (proxy, "core", &pcore, NULL);
g_object_get (om, "core", &omcore, NULL);
g_assert_nonnull (pcore);
g_assert_nonnull (omcore);
g_assert_true (pcore == omcore);
}
g_assert_cmphex (wp_global_proxy_get_permissions (proxy), ==, PW_PERM_ALL);
g_assert_true (WP_IS_CLIENT (proxy));
g_assert_cmphex (wp_object_get_active_features (WP_OBJECT (proxy)), ==, 0);
g_assert_null (wp_proxy_get_pw_proxy (WP_PROXY (proxy)));
{
g_autoptr (WpProperties) props =
wp_global_proxy_get_global_properties (proxy);
g_assert_nonnull (props);
g_assert_cmpstr (wp_properties_get (props, PW_KEY_PROTOCOL), ==,
"protocol-native");
}
wp_object_activate (WP_OBJECT (proxy), WP_PROXY_FEATURE_BOUND, NULL,
(GAsyncReadyCallback) test_proxy_basic_activated, fixture);
}
static void
test_proxy_basic (TestFixture *fixture, gconstpointer data)
{
/* our test server should advertise exactly one
* client: our core; use this to test WpProxy */
g_signal_connect (fixture->om, "object-added",
(GCallback) test_proxy_basic_object_added, fixture);
wp_object_manager_add_interest (fixture->om, WP_TYPE_CLIENT, NULL);
wp_core_install_object_manager (fixture->base.core, fixture->om);
g_main_loop_run (fixture->base.loop);
}
static void
test_node_enum_params_done (WpPipewireObject *node, GAsyncResult *res,
TestFixture *f)
{
g_autoptr (WpIterator) params = NULL;
g_autoptr (GError) error = NULL;
g_auto (GValue) item = G_VALUE_INIT;
guint n_params = 0;
params = wp_pipewire_object_enum_params_finish (node, res, &error);
g_assert_no_error (error);
g_assert_nonnull (params);
for (; wp_iterator_next (params, &item); g_value_unset (&item)) {
WpSpaPod *pod = NULL;
g_assert_cmpuint (G_VALUE_TYPE (&item), ==, WP_TYPE_SPA_POD);
pod = g_value_get_boxed (&item);
g_assert_nonnull (pod);
g_assert_true (wp_spa_pod_is_object (pod));
g_assert_cmpuint (wp_spa_type_from_name ("Spa:Pod:Object:Param:PropInfo"),
==, wp_spa_pod_get_spa_type (pod));
n_params++;
}
g_assert_cmpint (n_params, >, 0);
g_main_loop_quit (f->base.loop);
}
static void
test_node (TestFixture *f, gconstpointer data)
{
g_autoptr (WpPipewireObject) proxy = NULL;
const struct pw_node_info *info;
/* 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,
"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-adapter", NULL, NULL));
}
proxy = WP_PIPEWIRE_OBJECT (wp_node_new_from_factory (f->base.core,
"adapter",
wp_properties_new (
"factory.name", "audiotestsrc",
"node.name", "audiotestsrc.adapter",
NULL)));
g_assert_nonnull (proxy);
wp_object_activate (WP_OBJECT (proxy), WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL,
NULL, (GAsyncReadyCallback) test_object_activate_finish_cb, f);
g_main_loop_run (f->base.loop);
/* basic tests */
g_assert_cmphex (wp_object_get_active_features (WP_OBJECT (proxy)), ==,
WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL);
g_assert_nonnull (wp_proxy_get_pw_proxy (WP_PROXY (proxy)));
g_assert_true (WP_IS_NODE (proxy));
/* info */
{
info = wp_pipewire_object_get_native_info (proxy);
g_assert_nonnull (info);
g_assert_cmpint (wp_proxy_get_bound_id (WP_PROXY (proxy)), ==, info->id);
}
/* properties */
{
const gchar *id = wp_pipewire_object_get_property (proxy, PW_KEY_OBJECT_ID);
g_assert_nonnull (id);
g_assert_cmpint (info->id, ==, atoi(id));
}
{
const char *id;
g_autoptr (WpProperties) props = NULL;
props = wp_pipewire_object_get_properties (proxy);
g_assert_nonnull (props);
g_assert_true (wp_properties_peek_dict (props) == info->props);
id = wp_properties_get (props, PW_KEY_OBJECT_ID);
g_assert_nonnull (id);
g_assert_cmpint (info->id, ==, atoi(id));
}
/* param info */
{
const gchar *flags_str;
g_autoptr (GVariant) param_info = wp_pipewire_object_get_param_info (proxy);
g_assert_nonnull (param_info);
g_assert_true (g_variant_is_of_type (param_info, G_VARIANT_TYPE ("a{ss}")));
g_assert_cmpuint (g_variant_n_children (param_info), ==, info->n_params);
g_assert_true (g_variant_lookup (param_info, "PropInfo", "&s", &flags_str));
g_assert_cmpstr (flags_str, ==, "r");
g_assert_true (g_variant_lookup (param_info, "Props", "&s", &flags_str));
g_assert_cmpstr (flags_str, ==, "rw");
}
/* enum params */
wp_pipewire_object_enum_params (proxy, "PropInfo", NULL, NULL,
(GAsyncReadyCallback) test_node_enum_params_done, f);
g_main_loop_run (f->base.loop);
}
static void
activate_error_cb (WpObject * object, GAsyncResult * res,
WpBaseTestFixture * f)
{
g_autoptr (GError) error = NULL;
gboolean augment_ret = wp_object_activate_finish (object, res, &error);
g_assert_error (error, WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_OPERATION_FAILED);
g_assert_false (augment_ret);
g_main_loop_quit (f->loop);
}
static void
test_link_error (TestFixture *f, gconstpointer data)
{
g_autoptr (WpPipewireObject) proxy = NULL;
/* load audiotestsrc on the server side */
{
g_autoptr (WpTestServerLocker) lock =
wp_test_server_locker_new (&f->base.server);
g_assert_nonnull (pw_context_load_module (f->base.server.context,
"libpipewire-module-link-factory", NULL, NULL));
}
proxy = WP_PIPEWIRE_OBJECT (wp_link_new_from_factory (f->base.core,
"link-factory",
wp_properties_new (
"link.output.node", "invalid",
"link.input.node", "invalid",
NULL)));
g_assert_nonnull (proxy);
wp_object_activate (WP_OBJECT (proxy), WP_OBJECT_FEATURES_ALL,
NULL, (GAsyncReadyCallback) activate_error_cb, f);
g_main_loop_run (f->base.loop);
}
static void
enum_params_error_cb (WpPipewireObject * object, GAsyncResult * res,
WpBaseTestFixture * f)
{
g_autoptr (GError) error = NULL;
g_autoptr (WpIterator) it =
wp_pipewire_object_enum_params_finish (object, res, &error);
g_assert_error (error, WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_OPERATION_FAILED);
g_assert_null (it);
g_main_loop_quit (f->loop);
}
static void
test_enum_params_error (TestFixture *f, gconstpointer data)
{
g_autoptr (WpNode) node = 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,
"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-adapter", NULL, NULL));
}
node = wp_node_new_from_factory (f->base.core,
"adapter",
wp_properties_new (
"factory.name", "audiotestsrc",
"node.name", "audiotestsrc",
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);
/* EnumRoute doesn't exist on audiotestsrc, obviously */
wp_pipewire_object_enum_params (WP_PIPEWIRE_OBJECT (node), "EnumRoute", NULL,
NULL, (GAsyncReadyCallback) enum_params_error_cb, f);
g_main_loop_run (f->base.loop);
}
gint
main (gint argc, gchar *argv[])
{
g_test_init (&argc, &argv, NULL);
wp_init (WP_INIT_ALL);
g_test_add ("/wp/proxy/basic", TestFixture, NULL,
test_proxy_setup, test_proxy_basic, test_proxy_teardown);
g_test_add ("/wp/proxy/node", TestFixture, NULL,
test_proxy_setup, test_node, test_proxy_teardown);
g_test_add ("/wp/proxy/link_error", TestFixture, NULL,
test_proxy_setup, test_link_error, test_proxy_teardown);
g_test_add ("/wp/proxy/enum_params_error", TestFixture, NULL,
test_proxy_setup, test_enum_params_error, test_proxy_teardown);
return g_test_run ();
}
|