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/session-config.h>
20 #include <common/utils.h>
22 #include <lttng/constant.h>
33 int lttng_opt_quiet
= 1;
34 int lttng_opt_verbose
= 0;
37 static int entry_handler(const struct config_entry
*entry
, struct state
*state
)
41 if (!entry
|| !state
) {
46 if (!strcmp(entry
->section
, "section1")) {
48 if (!strcmp(entry
->name
, "section1_entry") &&
49 !strcmp(entry
->value
, "42")) {
54 if (!strcmp(entry
->section
, "section2")) {
58 if (!strcmp(entry
->section
, "section 3")) {
60 if (!strcmp(entry
->name
, "name with a space") &&
61 !strcmp(entry
->value
, "another value")) {
62 state
->text_entry
= 1;
66 if (!strcmp(entry
->section
, "")) {
67 state
->section_global
= 1;
73 int main(int argc
, char **argv
)
77 struct state state
= {};
80 diag("Usage: path_to_sample_INI_file");
84 if (strlen(argv
[1]) >= LTTNG_PATH_MAX
) {
85 diag("The provided path exceeds the maximal permitted length of %i bytes",
89 path
= utils_expand_path(argv
[1]);
91 fail("Failed to resolve sample INI file path")
95 ret
= config_get_section_entries(path
, NULL
,
96 (config_entry_handler_cb
)entry_handler
, &state
);
97 ok(ret
== 0, "Successfully opened a config file, registered to all sections");
98 ok(state
.section_1
&& state
.section_2
&& state
.section_3
&&
99 state
.section_global
, "Processed entries from each sections");
100 ok(state
.text_entry
, "Text value parsed correctly");
102 memset(&state
, 0, sizeof(struct state
));
103 ret
= config_get_section_entries(path
, "section1",
104 (config_entry_handler_cb
)entry_handler
, &state
);
105 ok(ret
== 0, "Successfully opened a config file, registered to one section");
106 ok(state
.section_1
&& !state
.section_2
&& !state
.section_3
&&
107 !state
.section_global
, "Processed an entry from section1 only");
108 ok(state
.int_entry
, "Int value parsed correctly");
110 memset(&state
, 0, sizeof(struct state
));
111 ret
= config_get_section_entries(path
, "",
112 (config_entry_handler_cb
)entry_handler
, &state
);
113 ok(ret
== 0, "Successfully opened a config file, registered to the global section");
114 ok(!state
.section_1
&& !state
.section_2
&& !state
.section_3
&&
115 state
.section_global
, "Processed an entry from the global section only");
118 return exit_status();
This page took 0.044395 seconds and 5 git commands to generate.