aboutsummaryrefslogtreecommitdiffstats
path: root/tests/common
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2018-07-23 00:25:48 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2018-07-23 00:25:48 +0200
commitcc295a26b2228b3c741f0fc0915890e184ca925d (patch)
treea7ba2274c981c2db7bef14cea5187806ba7ba0fe /tests/common
parentf79be78bd541bcb0824663f9233825cd7d901004 (diff)
downloadblogc-cc295a26b2228b3c741f0fc0915890e184ca925d.tar.gz
blogc-cc295a26b2228b3c741f0fc0915890e184ca925d.tar.bz2
blogc-cc295a26b2228b3c741f0fc0915890e184ca925d.zip
common: config-parser: fix empty values support
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/check_config_parser.c318
1 files changed, 318 insertions, 0 deletions
diff --git a/tests/common/check_config_parser.c b/tests/common/check_config_parser.c
index b1e42a6..5114709 100644
--- a/tests/common/check_config_parser.c
+++ b/tests/common/check_config_parser.c
@@ -601,6 +601,323 @@ test_config_quoted_values(void **state)
static void
+test_config_empty_values(void **state)
+{
+ const char *a =
+ "[foo]\n"
+ "asd =";
+ bc_error_t *err = NULL;
+ bc_config_t *c = bc_config_parse(a, strlen(a), NULL, &err);
+ assert_null(err);
+ assert_non_null(c);
+ assert_non_null(c->root);
+ assert_int_equal(bc_trie_size(c->root), 1);
+ char **s = bc_config_list_sections(c);
+ assert_non_null(s);
+ assert_int_equal(bc_strv_length(s), 1);
+ assert_string_equal(s[0], "foo");
+ assert_null(s[1]);
+ bc_strv_free(s);
+ assert_string_equal(bc_config_get(c, "foo", "asd"), "");
+ char **k = bc_config_list_keys(c, "foo");
+ assert_non_null(k);
+ assert_int_equal(bc_strv_length(k), 1);
+ assert_string_equal(k[0], "asd");
+ assert_null(k[1]);
+ bc_strv_free(k);
+ bc_config_free(c);
+
+ a =
+ "[foo]\n"
+ "asd = \n";
+ err = NULL;
+ c = bc_config_parse(a, strlen(a), NULL, &err);
+ assert_null(err);
+ assert_non_null(c);
+ assert_non_null(c->root);
+ assert_int_equal(bc_trie_size(c->root), 1);
+ s = bc_config_list_sections(c);
+ assert_non_null(s);
+ assert_int_equal(bc_strv_length(s), 1);
+ assert_string_equal(s[0], "foo");
+ assert_null(s[1]);
+ bc_strv_free(s);
+ assert_string_equal(bc_config_get(c, "foo", "asd"), "");
+ k = bc_config_list_keys(c, "foo");
+ assert_non_null(k);
+ assert_int_equal(bc_strv_length(k), 1);
+ assert_string_equal(k[0], "asd");
+ assert_null(k[1]);
+ bc_strv_free(k);
+ bc_config_free(c);
+
+ a =
+ "[foo]\n"
+ "asd = foo\n"
+ "qwe =";
+ err = NULL;
+ c = bc_config_parse(a, strlen(a), NULL, &err);
+ assert_null(err);
+ assert_non_null(c);
+ assert_non_null(c->root);
+ assert_int_equal(bc_trie_size(c->root), 1);
+ s = bc_config_list_sections(c);
+ assert_non_null(s);
+ assert_int_equal(bc_strv_length(s), 1);
+ assert_string_equal(s[0], "foo");
+ assert_null(s[1]);
+ bc_strv_free(s);
+ assert_string_equal(bc_config_get(c, "foo", "asd"), "foo");
+ assert_string_equal(bc_config_get(c, "foo", "qwe"), "");
+ k = bc_config_list_keys(c, "foo");
+ assert_non_null(k);
+ assert_int_equal(bc_strv_length(k), 2);
+ assert_string_equal(k[0], "asd");
+ assert_string_equal(k[1], "qwe");
+ assert_null(k[2]);
+ bc_strv_free(k);
+ bc_config_free(c);
+
+ a =
+ "[foo]\n"
+ "asd = foo\n"
+ "qwe = \n";
+ err = NULL;
+ c = bc_config_parse(a, strlen(a), NULL, &err);
+ assert_null(err);
+ assert_non_null(c);
+ assert_non_null(c->root);
+ assert_int_equal(bc_trie_size(c->root), 1);
+ s = bc_config_list_sections(c);
+ assert_non_null(s);
+ assert_int_equal(bc_strv_length(s), 1);
+ assert_string_equal(s[0], "foo");
+ assert_null(s[1]);
+ bc_strv_free(s);
+ assert_string_equal(bc_config_get(c, "foo", "asd"), "foo");
+ assert_string_equal(bc_config_get(c, "foo", "qwe"), "");
+ k = bc_config_list_keys(c, "foo");
+ assert_non_null(k);
+ assert_int_equal(bc_strv_length(k), 2);
+ assert_string_equal(k[0], "asd");
+ assert_string_equal(k[1], "qwe");
+ assert_null(k[2]);
+ bc_strv_free(k);
+ bc_config_free(c);
+
+ a =
+ "[foo]\n"
+ "asd =\n"
+ "qwe = foo";
+ err = NULL;
+ c = bc_config_parse(a, strlen(a), NULL, &err);
+ assert_null(err);
+ assert_non_null(c);
+ assert_non_null(c->root);
+ assert_int_equal(bc_trie_size(c->root), 1);
+ s = bc_config_list_sections(c);
+ assert_non_null(s);
+ assert_int_equal(bc_strv_length(s), 1);
+ assert_string_equal(s[0], "foo");
+ assert_null(s[1]);
+ bc_strv_free(s);
+ assert_string_equal(bc_config_get(c, "foo", "asd"), "");
+ assert_string_equal(bc_config_get(c, "foo", "qwe"), "foo");
+ k = bc_config_list_keys(c, "foo");
+ assert_non_null(k);
+ assert_int_equal(bc_strv_length(k), 2);
+ assert_string_equal(k[0], "asd");
+ assert_string_equal(k[1], "qwe");
+ assert_null(k[2]);
+ bc_strv_free(k);
+ bc_config_free(c);
+
+ a =
+ "[foo]\n"
+ "asd = \n"
+ "qwe = foo\n";
+ err = NULL;
+ c = bc_config_parse(a, strlen(a), NULL, &err);
+ assert_null(err);
+ assert_non_null(c);
+ assert_non_null(c->root);
+ assert_int_equal(bc_trie_size(c->root), 1);
+ s = bc_config_list_sections(c);
+ assert_non_null(s);
+ assert_int_equal(bc_strv_length(s), 1);
+ assert_string_equal(s[0], "foo");
+ assert_null(s[1]);
+ bc_strv_free(s);
+ assert_string_equal(bc_config_get(c, "foo", "asd"), "");
+ assert_string_equal(bc_config_get(c, "foo", "qwe"), "foo");
+ k = bc_config_list_keys(c, "foo");
+ assert_non_null(k);
+ assert_int_equal(bc_strv_length(k), 2);
+ assert_string_equal(k[0], "asd");
+ assert_string_equal(k[1], "qwe");
+ assert_null(k[2]);
+ bc_strv_free(k);
+ bc_config_free(c);
+
+ a =
+ "[foo]\r\n"
+ "asd =";
+ err = NULL;
+ c = bc_config_parse(a, strlen(a), NULL, &err);
+ assert_null(err);
+ assert_non_null(c);
+ assert_non_null(c->root);
+ assert_int_equal(bc_trie_size(c->root), 1);
+ s = bc_config_list_sections(c);
+ assert_non_null(s);
+ assert_int_equal(bc_strv_length(s), 1);
+ assert_string_equal(s[0], "foo");
+ assert_null(s[1]);
+ bc_strv_free(s);
+ assert_string_equal(bc_config_get(c, "foo", "asd"), "");
+ k = bc_config_list_keys(c, "foo");
+ assert_non_null(k);
+ assert_int_equal(bc_strv_length(k), 1);
+ assert_string_equal(k[0], "asd");
+ assert_null(k[1]);
+ bc_strv_free(k);
+ bc_config_free(c);
+
+ a =
+ "[foo]\r\n"
+ "asd = \r\n";
+ err = NULL;
+ c = bc_config_parse(a, strlen(a), NULL, &err);
+ assert_null(err);
+ assert_non_null(c);
+ assert_non_null(c->root);
+ assert_int_equal(bc_trie_size(c->root), 1);
+ s = bc_config_list_sections(c);
+ assert_non_null(s);
+ assert_int_equal(bc_strv_length(s), 1);
+ assert_string_equal(s[0], "foo");
+ assert_null(s[1]);
+ bc_strv_free(s);
+ assert_string_equal(bc_config_get(c, "foo", "asd"), "");
+ k = bc_config_list_keys(c, "foo");
+ assert_non_null(k);
+ assert_int_equal(bc_strv_length(k), 1);
+ assert_string_equal(k[0], "asd");
+ assert_null(k[1]);
+ bc_strv_free(k);
+ bc_config_free(c);
+
+ a =
+ "[foo]\r\n"
+ "asd = foo\r\n"
+ "qwe =";
+ err = NULL;
+ c = bc_config_parse(a, strlen(a), NULL, &err);
+ assert_null(err);
+ assert_non_null(c);
+ assert_non_null(c->root);
+ assert_int_equal(bc_trie_size(c->root), 1);
+ s = bc_config_list_sections(c);
+ assert_non_null(s);
+ assert_int_equal(bc_strv_length(s), 1);
+ assert_string_equal(s[0], "foo");
+ assert_null(s[1]);
+ bc_strv_free(s);
+ assert_string_equal(bc_config_get(c, "foo", "asd"), "foo");
+ assert_string_equal(bc_config_get(c, "foo", "qwe"), "");
+ k = bc_config_list_keys(c, "foo");
+ assert_non_null(k);
+ assert_int_equal(bc_strv_length(k), 2);
+ assert_string_equal(k[0], "asd");
+ assert_string_equal(k[1], "qwe");
+ assert_null(k[2]);
+ bc_strv_free(k);
+ bc_config_free(c);
+
+ a =
+ "[foo]\r\n"
+ "asd = foo\r\n"
+ "qwe = \r\n";
+ err = NULL;
+ c = bc_config_parse(a, strlen(a), NULL, &err);
+ assert_null(err);
+ assert_non_null(c);
+ assert_non_null(c->root);
+ assert_int_equal(bc_trie_size(c->root), 1);
+ s = bc_config_list_sections(c);
+ assert_non_null(s);
+ assert_int_equal(bc_strv_length(s), 1);
+ assert_string_equal(s[0], "foo");
+ assert_null(s[1]);
+ bc_strv_free(s);
+ assert_string_equal(bc_config_get(c, "foo", "asd"), "foo");
+ assert_string_equal(bc_config_get(c, "foo", "qwe"), "");
+ k = bc_config_list_keys(c, "foo");
+ assert_non_null(k);
+ assert_int_equal(bc_strv_length(k), 2);
+ assert_string_equal(k[0], "asd");
+ assert_string_equal(k[1], "qwe");
+ assert_null(k[2]);
+ bc_strv_free(k);
+ bc_config_free(c);
+
+ a =
+ "[foo]\r\n"
+ "asd =\r\n"
+ "qwe = foo";
+ err = NULL;
+ c = bc_config_parse(a, strlen(a), NULL, &err);
+ assert_null(err);
+ assert_non_null(c);
+ assert_non_null(c->root);
+ assert_int_equal(bc_trie_size(c->root), 1);
+ s = bc_config_list_sections(c);
+ assert_non_null(s);
+ assert_int_equal(bc_strv_length(s), 1);
+ assert_string_equal(s[0], "foo");
+ assert_null(s[1]);
+ bc_strv_free(s);
+ assert_string_equal(bc_config_get(c, "foo", "asd"), "");
+ assert_string_equal(bc_config_get(c, "foo", "qwe"), "foo");
+ k = bc_config_list_keys(c, "foo");
+ assert_non_null(k);
+ assert_int_equal(bc_strv_length(k), 2);
+ assert_string_equal(k[0], "asd");
+ assert_string_equal(k[1], "qwe");
+ assert_null(k[2]);
+ bc_strv_free(k);
+ bc_config_free(c);
+
+ a =
+ "[foo]\r\n"
+ "asd = \r\n"
+ "qwe = foo\r\n";
+ err = NULL;
+ c = bc_config_parse(a, strlen(a), NULL, &err);
+ assert_null(err);
+ assert_non_null(c);
+ assert_non_null(c->root);
+ assert_int_equal(bc_trie_size(c->root), 1);
+ s = bc_config_list_sections(c);
+ assert_non_null(s);
+ assert_int_equal(bc_strv_length(s), 1);
+ assert_string_equal(s[0], "foo");
+ assert_null(s[1]);
+ bc_strv_free(s);
+ assert_string_equal(bc_config_get(c, "foo", "asd"), "");
+ assert_string_equal(bc_config_get(c, "foo", "qwe"), "foo");
+ k = bc_config_list_keys(c, "foo");
+ assert_non_null(k);
+ assert_int_equal(bc_strv_length(k), 2);
+ assert_string_equal(k[0], "asd");
+ assert_string_equal(k[1], "qwe");
+ assert_null(k[2]);
+ bc_strv_free(k);
+ bc_config_free(c);
+}
+
+
+static void
test_config_key_prefix(void **state)
{
const char *a =
@@ -710,6 +1027,7 @@ main(void)
unit_test(test_config_section_multiple_sections),
unit_test(test_config_section_list),
unit_test(test_config_quoted_values),
+ unit_test(test_config_empty_values),
unit_test(test_config_key_prefix),
unit_test(test_config_error_start),
unit_test(test_config_error_section_with_newline),