summaryrefslogtreecommitdiff
path: root/tests/test-keyfile-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-keyfile-utils.c')
-rw-r--r--tests/test-keyfile-utils.c155
1 files changed, 46 insertions, 109 deletions
diff --git a/tests/test-keyfile-utils.c b/tests/test-keyfile-utils.c
index 49ac10fd..198e71d2 100644
--- a/tests/test-keyfile-utils.c
+++ b/tests/test-keyfile-utils.c
@@ -19,57 +19,41 @@
#include "config.h"
#include "libglnx.h"
+#include "ot-keyfile-utils.h"
+#include <gio/gio.h>
#include <glib.h>
#include <stdlib.h>
-#include <gio/gio.h>
#include <string.h>
-#include "ot-keyfile-utils.h"
static GKeyFile *g_keyfile;
static void
test_get_boolean_with_default (void)
{
- g_autoptr(GError) error = NULL;
+ g_autoptr (GError) error = NULL;
gboolean out = FALSE;
- g_assert (ot_keyfile_get_boolean_with_default (g_keyfile,
- "section",
- "a_boolean_true",
- FALSE,
- &out,
- &error));
+ g_assert (ot_keyfile_get_boolean_with_default (g_keyfile, "section", "a_boolean_true", FALSE,
+ &out, &error));
g_assert_true (out);
- g_assert (ot_keyfile_get_boolean_with_default (g_keyfile,
- "section",
- "a_boolean_false",
- TRUE,
- &out,
- &error));
+ g_assert (ot_keyfile_get_boolean_with_default (g_keyfile, "section", "a_boolean_false", TRUE,
+ &out, &error));
g_assert_false (out);
- g_assert (ot_keyfile_get_boolean_with_default (g_keyfile,
- "section",
- "a_not_existing_boolean",
- TRUE,
- &out,
- &error));
+ g_assert (ot_keyfile_get_boolean_with_default (g_keyfile, "section", "a_not_existing_boolean",
+ TRUE, &out, &error));
g_assert_true (out);
g_clear_error (&error);
- g_assert (ot_keyfile_get_boolean_with_default (g_keyfile,
- "a_fake_section",
- "a_boolean_true",
- FALSE,
- &out,
- &error));
+ g_assert (ot_keyfile_get_boolean_with_default (g_keyfile, "a_fake_section", "a_boolean_true",
+ FALSE, &out, &error));
}
static void
test_get_value_with_default (void)
{
- g_autoptr(GError) error = NULL;
+ g_autoptr (GError) error = NULL;
g_autofree char *out = NULL;
GLogLevelFlags always_fatal_mask;
const char *section = "section";
@@ -77,55 +61,31 @@ 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",
- "none",
- &out,
- &error));
+ g_assert_false (
+ ot_keyfile_get_value_with_default (g_keyfile, NULL, "value_foo", "none", &out, &error));
g_clear_pointer (&out, g_free);
- g_assert_false (ot_keyfile_get_value_with_default (g_keyfile,
- section,
- NULL,
- "none",
- &out,
- &error));
+ g_assert_false (
+ ot_keyfile_get_value_with_default (g_keyfile, section, NULL, "none", &out, &error));
g_clear_pointer (&out, g_free);
- g_assert_false (ot_keyfile_get_value_with_default (g_keyfile,
- section,
- NULL,
- "something",
- &out,
- &error));
+ g_assert_false (
+ ot_keyfile_get_value_with_default (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 (g_keyfile,
- section,
- "value_foo",
- "none",
- &out,
- &error));
+ g_assert (
+ ot_keyfile_get_value_with_default (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 (g_keyfile,
- section,
- "a_not_existing_value",
- "correct",
- &out,
- &error));
+ g_assert (ot_keyfile_get_value_with_default (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 (g_keyfile,
- "a_fake_section",
- "a_value_true",
- "no value",
- &out,
- &error));
+ g_assert (ot_keyfile_get_value_with_default (g_keyfile, "a_fake_section", "a_value_true",
+ "no value", &out, &error));
g_assert_cmpstr (out, ==, "no value");
g_clear_pointer (&out, g_free);
}
@@ -133,63 +93,39 @@ test_get_value_with_default (void)
static void
test_get_value_with_default_group_optional (void)
{
- g_autoptr(GError) error = NULL;
+ 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. */
+ /* 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_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_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_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 (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 (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_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);
}
@@ -204,7 +140,7 @@ test_copy_group (void)
/* Avoid that g_return_val_if_fail causes the test to fail. */
always_fatal_mask = g_log_set_always_fatal (0);
- g_autoptr(GKeyFile) tmp = g_key_file_new ();
+ g_autoptr (GKeyFile) tmp = g_key_file_new ();
g_assert_false (ot_keyfile_copy_group (NULL, tmp, section));
g_assert_false (ot_keyfile_copy_group (g_keyfile, NULL, section));
@@ -215,9 +151,9 @@ test_copy_group (void)
g_assert_true (ot_keyfile_copy_group (g_keyfile, tmp, section));
- g_auto(GStrv) keys = g_key_file_get_keys (g_keyfile, section, &length, NULL);
+ g_auto (GStrv) keys = g_key_file_get_keys (g_keyfile, section, &length, NULL);
g_strfreev (g_key_file_get_keys (tmp, section, &length2, NULL));
- g_assert_cmpint(length, ==, length2);
+ g_assert_cmpint (length, ==, length2);
for (gsize ii = 0; ii < length; ii++)
{
@@ -225,7 +161,6 @@ test_copy_group (void)
g_autofree char *value2 = g_key_file_get_value (g_keyfile, section, keys[ii], NULL);
g_assert_cmpstr (value, ==, value2);
}
-
}
static void
@@ -238,7 +173,8 @@ fill_keyfile (GKeyFile *file)
g_key_file_set_value (file, "section", "value_bar", "bar");
}
-int main (int argc, char **argv)
+int
+main (int argc, char **argv)
{
int ret;
g_test_init (&argc, &argv, NULL);
@@ -247,10 +183,11 @@ 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/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();
+ ret = g_test_run ();
g_key_file_free (g_keyfile);