aboutsummaryrefslogtreecommitdiffstats
path: root/tests/common/check_config_parser.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2017-06-24 11:45:40 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2017-06-24 11:51:59 +0200
commit0ae85f6545b1d4a64836b0a3a5676a0bed9854d5 (patch)
treeec076c35f4770c1d9a1d9bd8df0b6b9bba1ba352 /tests/common/check_config_parser.c
parent6eacbbe17ea7a7f523240400821a911589486d25 (diff)
downloadblogc-0ae85f6545b1d4a64836b0a3a5676a0bed9854d5.tar.gz
blogc-0ae85f6545b1d4a64836b0a3a5676a0bed9854d5.tar.bz2
blogc-0ae85f6545b1d4a64836b0a3a5676a0bed9854d5.zip
utils: trie: fixed bug in foreach implementation.
when looping through the tree, the algorithm would stop, if found a '\0' in the key of the tree node. there should be no "child" field after a '\0', but "next" fields may exist.
Diffstat (limited to 'tests/common/check_config_parser.c')
-rw-r--r--tests/common/check_config_parser.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/common/check_config_parser.c b/tests/common/check_config_parser.c
index 942facd..b1e42a6 100644
--- a/tests/common/check_config_parser.c
+++ b/tests/common/check_config_parser.c
@@ -601,6 +601,38 @@ test_config_quoted_values(void **state)
static void
+test_config_key_prefix(void **state)
+{
+ const char *a =
+ "[foo]\n"
+ "LAST_FLIGHT = lol\n"
+ "LAST_FLIGHT_SLUG = hehe\n";
+ 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);
+ char **k = bc_config_list_keys(c, "foo");
+ assert_non_null(k);
+ assert_int_equal(bc_strv_length(k), 2);
+ assert_string_equal(k[0], "LAST_FLIGHT");
+ assert_string_equal(k[1], "LAST_FLIGHT_SLUG");
+ assert_null(k[2]);
+ bc_strv_free(k);
+ assert_string_equal(bc_config_get(c, "foo", "LAST_FLIGHT"), "lol");
+ assert_string_equal(bc_config_get(c, "foo", "LAST_FLIGHT_SLUG"), "hehe");
+ bc_config_free(c);
+}
+
+
+static void
test_config_error_start(void **state)
{
const char *a =
@@ -678,6 +710,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_key_prefix),
unit_test(test_config_error_start),
unit_test(test_config_error_section_with_newline),
unit_test(test_config_error_key_without_value),