diff options
author | Robert Fairley <rob.t.fairley@gmail.com> | 2019-02-20 00:56:54 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2019-03-01 21:20:35 +0000 |
commit | 99cf13b22519e88d6cce22379d67b50bf6a2aa6b (patch) | |
tree | e189cd106b8de0d122e34bdff3fda866f7f78d2b /tests/test-keyfile-utils.c | |
parent | 91892e3c3f31d104796584c6975f4a198faf750f (diff) | |
download | ostree-99cf13b22519e88d6cce22379d67b50bf6a2aa6b.tar.gz |
libotutil: Add ot_keyfile_get_value_with_default_group_optional()
Add ot_keyfile_get_value_with_default_group_optional() which allows
getting values from keys where the group is optional in the config
file. This is preparatory to add the sysroot.bootloader repo config
key, where the sysroot group is optional.
Closes: #1814
Approved by: jlebon
Diffstat (limited to 'tests/test-keyfile-utils.c')
-rw-r--r-- | tests/test-keyfile-utils.c | 76 |
1 files changed, 70 insertions, 6 deletions
diff --git a/tests/test-keyfile-utils.c b/tests/test-keyfile-utils.c index 8acd0a1c..258e7dd8 100644 --- a/tests/test-keyfile-utils.c +++ b/tests/test-keyfile-utils.c @@ -79,7 +79,6 @@ test_get_value_with_default (void) /* Avoid that g_return_val_if_fail causes the test to fail. */ always_fatal_mask = g_log_set_always_fatal (0); - g_assert_false (ot_keyfile_get_value_with_default (g_keyfile, NULL, "value_foo", @@ -124,11 +123,75 @@ test_get_value_with_default (void) g_clear_pointer (&out, g_free); g_assert_false (ot_keyfile_get_value_with_default (g_keyfile, - "a_fake_section", - "a_value_true", - "no value", - &out, - &error)); + "a_fake_section", + "a_value_true", + "no value", + &out, + &error)); + g_clear_error (&error); + g_clear_pointer (&out, g_free); +} + +static void +test_get_value_with_default_group_optional (void) +{ + g_autoptr(GError) error = NULL; + g_autofree char *out = NULL; + GLogLevelFlags always_fatal_mask; + const char *section = "section"; + +/* Avoid that g_return_val_if_fail causes the test to fail. */ + always_fatal_mask = g_log_set_always_fatal (0); + + g_assert_false (ot_keyfile_get_value_with_default_group_optional (g_keyfile, + NULL, + "value_foo", + "none", + &out, + &error)); + g_clear_pointer (&out, g_free); + g_assert_false (ot_keyfile_get_value_with_default_group_optional (g_keyfile, + section, + NULL, + "none", + &out, + &error)); + g_clear_pointer (&out, g_free); + g_assert_false (ot_keyfile_get_value_with_default_group_optional (g_keyfile, + section, + NULL, + "something", + &out, + &error)); + g_clear_pointer (&out, g_free); + + /* Restore the old mask. */ + g_log_set_always_fatal (always_fatal_mask); + + g_assert (ot_keyfile_get_value_with_default_group_optional (g_keyfile, + section, + "value_foo", + "none", + &out, + &error)); + g_assert_cmpstr (out, ==, "foo"); + g_clear_pointer (&out, g_free); + + g_assert (ot_keyfile_get_value_with_default_group_optional (g_keyfile, + section, + "a_not_existing_value", + "correct", + &out, + &error)); + g_assert_cmpstr (out, ==, "correct"); + g_clear_pointer (&out, g_free); + + g_assert (ot_keyfile_get_value_with_default_group_optional (g_keyfile, + "an_optional_section", + "a_value_true", + "no value", + &out, + &error)); g_clear_error (&error); g_clear_pointer (&out, g_free); } @@ -191,6 +254,7 @@ int main (int argc, char **argv) g_test_add_func ("/keyfile-utils/get-boolean-with-default", test_get_boolean_with_default); g_test_add_func ("/keyfile-utils/get-value-with-default", test_get_value_with_default); + g_test_add_func ("/keyfile-utils/get-value-with-default-group-optional", test_get_value_with_default_group_optional); g_test_add_func ("/keyfile-utils/copy-group", test_copy_group); ret = g_test_run(); |