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:
@@ -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));
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user