Align YAML config getlist with libconfig implementation

This aligns the behavior of params_yaml with params_config library so that
when a mapping is read using getlist it returns the number of elements in
the mapping instead of 0.
This commit is contained in:
Bartosz Podrygajlo
2024-12-02 13:32:19 +01:00
parent 03946cd47b
commit b6b377ffc0
4 changed files with 23 additions and 1 deletions
+1 -1
View File
@@ -286,10 +286,10 @@ extern "C" int config_yaml_getlist(configmodule_interface_t *cfg,
return -1;
}
ParamList->numelt = node.size();
if (!node.IsSequence()) {
return -1;
}
ParamList->numelt = node.size();
if (ParamList->numelt > 0 && params != NULL) {
ParamList->paramarray = static_cast<paramdef_t **>(config_allocate_new(cfg, ParamList->numelt * sizeof(paramdef_t *), true));
+1
View File
@@ -9,3 +9,4 @@ configure_file(test_list.yaml test_list.yaml COPYONLY)
configure_file(test_string.yaml test_string.yaml COPYONLY)
configure_file(test_list_of_mappings.yml test_list_of_mappings.yml COPYONLY)
configure_file(test_int_array.yaml test_int_array.yaml COPYONLY)
configure_file(test_read_mapping_as_list.yaml test_read_mapping_as_list.yaml COPYONLY)
@@ -0,0 +1,4 @@
fhi_72:
element1: value1
element2: value2
element3: value3
@@ -364,6 +364,23 @@ TEST(yaml_config, test_int_array) {
end_configmodule(cfg);
}
TEST(yaml_config, test_read_mapping_as_list) {
configmodule_interface_t *cfg = static_cast<configmodule_interface_t*>(calloc(1, sizeof(*cfg)));
cfg->cfgP[0] = strdup("test_read_mapping_as_list.yaml");
EXPECT_EQ(config_yaml_init(cfg), 0);
paramlist_def_t pl = {0};
strncpy(pl.listname, "fhi_72", sizeof(pl.listname) - 1);
config_yaml_getlist(cfg, &pl, NULL, 0, /* prefix */ NULL);
EXPECT_NE(pl.numelt, 0);
EXPECT_EQ(pl.numelt, 3);
config_yaml_end(cfg);
free(cfg->cfgP[0]);
end_configmodule(cfg);
}
int main(int argc, char** argv)
{
logInit();