From 0ae85f6545b1d4a64836b0a3a5676a0bed9854d5 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 24 Jun 2017 11:45:40 +0200 Subject: 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. --- tests/common/check_config_parser.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/common/check_config_parser.c') 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 @@ -600,6 +600,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) { @@ -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), -- cgit v1.2.3-18-g5258