a16d1b9e8d8f540a4e87215e6ab9c2162eebc4d9
2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
9 #include <common/config/session-config.h>
10 #include <common/utils.h>
12 #include <lttng/constant.h>
23 int lttng_opt_quiet
= 1;
24 int lttng_opt_verbose
= 0;
27 static int entry_handler(const struct config_entry
*entry
, struct state
*state
)
31 if (!entry
|| !state
) {
36 if (!strcmp(entry
->section
, "section1")) {
38 if (!strcmp(entry
->name
, "section1_entry") &&
39 !strcmp(entry
->value
, "42")) {
44 if (!strcmp(entry
->section
, "section2")) {
48 if (!strcmp(entry
->section
, "section 3")) {
50 if (!strcmp(entry
->name
, "name with a space") &&
51 !strcmp(entry
->value
, "another value")) {
52 state
->text_entry
= 1;
56 if (!strcmp(entry
->section
, "")) {
57 state
->section_global
= 1;
63 int main(int argc
, char **argv
)
67 struct state state
= {};
70 diag("Usage: path_to_sample_INI_file");
74 if (strlen(argv
[1]) >= LTTNG_PATH_MAX
) {
75 diag("The provided path exceeds the maximal permitted length of %i bytes",
79 path
= utils_expand_path(argv
[1]);
81 fail("Failed to resolve sample INI file path")
85 ret
= config_get_section_entries(path
, NULL
,
86 (config_entry_handler_cb
)entry_handler
, &state
);
87 ok(ret
== 0, "Successfully opened a config file, registered to all sections");
88 ok(state
.section_1
&& state
.section_2
&& state
.section_3
&&
89 state
.section_global
, "Processed entries from each sections");
90 ok(state
.text_entry
, "Text value parsed correctly");
92 memset(&state
, 0, sizeof(struct state
));
93 ret
= config_get_section_entries(path
, "section1",
94 (config_entry_handler_cb
)entry_handler
, &state
);
95 ok(ret
== 0, "Successfully opened a config file, registered to one section");
96 ok(state
.section_1
&& !state
.section_2
&& !state
.section_3
&&
97 !state
.section_global
, "Processed an entry from section1 only");
98 ok(state
.int_entry
, "Int value parsed correctly");
100 memset(&state
, 0, sizeof(struct state
));
101 ret
= config_get_section_entries(path
, "",
102 (config_entry_handler_cb
)entry_handler
, &state
);
103 ok(ret
== 0, "Successfully opened a config file, registered to the global section");
104 ok(!state
.section_1
&& !state
.section_2
&& !state
.section_3
&&
105 state
.section_global
, "Processed an entry from the global section only");
108 return exit_status();
This page took 0.033154 seconds and 5 git commands to generate.