2 * Copyright (c) - 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by as
6 * published by the Free Software Foundation; only version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <common/config/config.h>
20 #include <common/utils.h>
32 int lttng_opt_quiet
= 1;
33 int lttng_opt_verbose
= 0;
35 int entry_handler(const struct config_entry
*entry
,
40 if (!entry
|| !state
) {
45 if (!strcmp(entry
->section
, "section1")) {
47 if (!strcmp(entry
->name
, "section1_entry") &&
48 !strcmp(entry
->value
, "42")) {
53 if (!strcmp(entry
->section
, "section2")) {
57 if (!strcmp(entry
->section
, "section 3")) {
59 if (!strcmp(entry
->name
, "name with a space") &&
60 !strcmp(entry
->value
, "another value")) {
61 state
->text_entry
= 1;
65 if (!strcmp(entry
->section
, "")) {
66 state
->section_global
= 1;
72 int main(int argc
, char **argv
)
76 struct state state
= {};
79 diag("Usage: path_to_sample_INI_file");
83 path
= utils_expand_path(argv
[1]);
85 fail("Failed to resolve sample INI file path")
89 ret
= config_get_section_entries(path
, NULL
,
90 (config_entry_handler_cb
)entry_handler
, &state
);
91 ok(ret
== 0, "Successfully opened a config file, registered to all sections");
92 ok(state
.section_1
&& state
.section_2
&& state
.section_3
&&
93 state
.section_global
, "Processed entries from each sections");
94 ok(state
.text_entry
, "Text value parsed correctly");
96 memset(&state
, 0, sizeof(struct state
));
97 ret
= config_get_section_entries(path
, "section1",
98 (config_entry_handler_cb
)entry_handler
, &state
);
99 ok(ret
== 0, "Successfully opened a config file, registered to one section");
100 ok(state
.section_1
&& !state
.section_2
&& !state
.section_3
&&
101 !state
.section_global
, "Processed an entry from section1 only");
102 ok(state
.int_entry
, "Int value parsed correctly");
104 memset(&state
, 0, sizeof(struct state
));
105 ret
= config_get_section_entries(path
, "",
106 (config_entry_handler_cb
)entry_handler
, &state
);
107 ok(ret
== 0, "Successfully opened a config file, registered to the global section");
108 ok(!state
.section_1
&& !state
.section_2
&& !state
.section_3
&&
109 state
.section_global
, "Processed an entry from the global section only");
112 return exit_status();
This page took 0.030482 seconds and 4 git commands to generate.