tests: use WpConf for the settings unit tests

Also moves the settings.conf file into settings/wireplumber.conf
This commit is contained in:
Julian Bouzas 2023-01-10 09:38:27 -05:00
parent 360e0b3eaf
commit d43b55d01e
6 changed files with 37 additions and 220 deletions

View file

@ -244,7 +244,7 @@ static void
base_tests_setup (ScriptRunnerFixture *f, gconstpointer data)
{
f->base.conf_file =
g_strdup_printf ("%s/settings.conf", g_getenv ("G_TEST_SRCDIR"));
g_strdup_printf ("%s/settings/wireplumber.conf", g_getenv ("G_TEST_SRCDIR"));
wp_base_test_fixture_setup (&f->base, WP_BASE_TEST_FLAG_CLIENT_CORE);

View file

@ -25,8 +25,8 @@ typedef struct {
static void
test_conf_file_setup (TestSettingsFixture *self, gconstpointer user_data)
{
self->base.conf_file =
g_strdup_printf ("%s/settings.conf", g_getenv ("G_TEST_SRCDIR"));
self->base.conf_file = g_strdup_printf ("%s/settings/wireplumber.conf",
g_getenv ("G_TEST_SRCDIR"));
wp_base_test_fixture_setup (&self->base, WP_BASE_TEST_FLAG_CLIENT_CORE);
}
@ -38,40 +38,20 @@ test_conf_file_teardown (TestSettingsFixture *self, gconstpointer user_data)
wp_base_test_fixture_teardown (&self->base);
}
static int
dummy(void *data, const char *location, const char *section,
const char *str, size_t len)
{
return 1;
}
static void
test_conf_file (TestSettingsFixture *self, gconstpointer data)
{
struct pw_context *pw_ctx = wp_core_get_pw_context (self->base.core);
/* test if the "settings" section is present in the JSON config file */
g_assert_true (pw_context_conf_section_for_each(pw_ctx,
"wireplumber.settings", dummy, NULL));
}
struct data {
int count;
WpProperties *settings;
};
static int
do_parse_settings (void *data, const char *location,
const char *section, const char *str, size_t len)
static WpProperties *
do_parse_settings (WpSpaJson *json)
{
struct data *d = data;
g_autoptr (WpSpaJson) json = wp_spa_json_new_from_stringn (str, len);
g_autoptr (WpProperties) settings = wp_properties_new_empty ();
g_autoptr (WpIterator) iter = wp_spa_json_new_iterator (json);
g_auto (GValue) item = G_VALUE_INIT;
if (!wp_spa_json_is_object (json)) {
return -EINVAL;
}
if (!wp_spa_json_is_object (json))
return NULL;
while (wp_iterator_next (iter, &item)) {
WpSpaJson *j = g_value_get_boxed (&item);
@ -85,15 +65,11 @@ do_parse_settings (void *data, const char *location,
value = wp_spa_json_to_string (j);
g_value_unset (&item);
if (name && value) {
wp_properties_set (d->settings, name, value);
d->count++;
}
if (name && value)
wp_properties_set (settings, name, value);
}
g_debug ("parsed %d settings & rules from conf file\n", d->count);
return 0;
return g_steal_pointer (&settings);
}
static void
@ -102,17 +78,14 @@ test_parsing_setup (TestSettingsFixture *self, gconstpointer user_data)
test_conf_file_setup (self, user_data);
{
struct pw_context *pw_ctx = wp_core_get_pw_context (self->base.core);
g_autoptr (WpProperties) settings = wp_properties_new_empty();
struct data data = { .settings = settings };
g_autoptr (WpConf) conf = wp_conf_get_instance (self->base.core);
g_assert_nonnull (conf);
g_autoptr (WpSpaJson) json = wp_conf_get_section (conf,
"wireplumber.settings", NULL);
g_assert_nonnull (json);
g_assert_false (pw_context_conf_section_for_each(pw_ctx,
"wireplumber.settings", do_parse_settings, &data));
self->settings = g_steal_pointer (&settings);
/* total no.of settings in the conf file */
g_assert_cmpint (data.count, ==, 13);
self->settings = do_parse_settings (json);
g_assert_nonnull (self->settings);
}
}
@ -129,7 +102,7 @@ static void
test_parsing (TestSettingsFixture *self, gconstpointer data)
{
/* total no.of settings in the conf file */
g_assert_cmpint (wp_properties_get_count(self->settings), ==, 13);
g_assert_cmpint (wp_properties_get_count(self->settings), ==, 10);
}
static void
@ -516,9 +489,6 @@ main (gint argc, gchar *argv[])
wp_init (WP_INIT_ALL);
/* take a close look at .conf file that is loaded, all the test work on it */
g_test_add ("/wp/settings/conf-file-loading", TestSettingsFixture, NULL,
test_conf_file_setup, test_conf_file, test_conf_file_teardown);
g_test_add ("/wp/settings/parsing", TestSettingsFixture, NULL,
test_parsing_setup, test_parsing, test_parsing_teardown);
g_test_add ("/wp/settings/metadata-creation", TestSettingsFixture, NULL,

View file

@ -1,170 +0,0 @@
# Client config file for PipeWire version "0.3.48" #
#
# Copy and edit this file in /usr/local/etc/pipewire for system-wide changes
# or in ~/.config/pipewire for local changes.
#
# It is also possible to place a file with an updated section in
# /usr/local/etc/pipewire/client.conf.d/ for system-wide changes or in
# ~/.config/pipewire/client.conf.d/ for local changes.
#
context.properties = {
## Configure properties in the system.
#mem.warn-mlock = false
#mem.allow-mlock = true
#mem.mlock-all = false
log.level = 0
#default.clock.quantum-limit = 8192
}
context.spa-libs = {
#<factory-name regex> = <library-name>
#
# Used to find spa factory names. It maps an spa factory name
# regular expression to a library name that should contain
# that factory.
#
audio.convert.* = audioconvert/libspa-audioconvert
support.* = support/libspa-support
}
context.modules = [
#{ name = <module-name>
# [ args = { <key> = <value> ... } ]
# [ flags = [ [ ifexists ] [ nofail ] ]
#}
#
# Loads a module with the given parameters.
# If ifexists is given, the module is ignored when it is not found.
# If nofail is given, module initialization failures are ignored.
#
# The native communication protocol.
{ name = libpipewire-module-protocol-native }
# Allows creating nodes that run in the context of the
# client. Is used by all clients that want to provide
# data to PipeWire.
{ name = libpipewire-module-client-node }
# Allows creating devices that run in the context of the
# client. Is used by the session manager.
{ name = libpipewire-module-client-device }
# Makes a factory for wrapping nodes in an adapter with a
# converter and resampler.
{ name = libpipewire-module-adapter }
# Allows applications to create metadata objects. It creates
# a factory for Metadata objects.
{ name = libpipewire-module-metadata }
# Provides factories to make session manager objects.
{ name = libpipewire-module-session-manager }
]
wireplumber.settings = {
test-setting1 = false
test-setting2 = true
test-setting3-int = -20
test-setting4-string = "blahblah"
test-setting5-string-with-quotes = "a string with \"quotes\""
rule_one = [
{
matches = [
{
test-string1 = "copper"
test-int1 = 100
}
{
test-string2 = "juggler"
}
]
actions = {
update-props = {
prop-string1 = "metal"
prop-int1 = 123
}
}
}
{
matches = [
{
test-string4 = "ferrous"
test-int2 = 100
test-string5 = "blend"
}
{
test-string6 = "alum"
test-int3 = 24
}
]
actions = {
update-props = {
prop-string2 = "standard"
prop-int2 = 26
prop-bool1 = true
}
}
}
]
rule_two = [
{
matches = [
{
test-string6 = "ethylene"
test-int2 = 625
test-string5 = "blend"
}
]
actions = {
update-props = {
prop-string2 = "spray"
prop-int2 = 111
}
}
}
]
test-setting-float1 = 3.14
test-setting-float2 = 0.4
rule_three = [
{
matches = [
{
test.string6 = "~metal*"
test.table.entry = true
}
{
test-string6-wildcard = "~*"
}
]
actions = {
update-props = {
prop.electrical.conductivity = true
prop.state = "solid"
prop.example = "ferrous"
}
}
}
{
matches = [
{
test.string6 = "~gas*"
test.table.entry = "maybe"
}
]
actions = {
update-props = {
prop.electrical.conductivity = false
prop.example = "neon"
prop.state = "gas"
}
}
}
]
test-setting-json = [1, 2, 3]
test-setting-json2 = ["test1", "test 2", "test three", "test-four"]
test-setting-json3 = { key1: "value", key2: 2, key3: true }
}

View file

@ -0,0 +1,17 @@
context.modules = [
{ name = libpipewire-module-protocol-native }
{ name = libpipewire-module-metadata }
]
wireplumber.settings = {
test-setting1 = false
test-setting2 = true
test-setting3-int = -20
test-setting4-string = "blahblah"
test-setting5-string-with-quotes = "a string with \"quotes\""
test-setting-float1 = 3.14
test-setting-float2 = 0.4
test-setting-json = [1, 2, 3]
test-setting-json2 = ["test1", "test 2", "test three", "test-four"]
test-setting-json3 = { key1: "value", key2: 2, key3: true }
}

1
tests/wplua/settings Symbolic link
View file

@ -0,0 +1 @@
../wp/settings

View file

@ -1 +0,0 @@
../wp/settings.conf