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>
11 #include <common/path.h>
13 #include <lttng/constant.h>
24 int lttng_opt_quiet
= 1;
25 int lttng_opt_verbose
= 0;
28 static int entry_handler(const struct config_entry
*entry
, struct state
*state
)
32 if (!entry
|| !state
) {
37 if (!strcmp(entry
->section
, "section1")) {
39 if (!strcmp(entry
->name
, "section1_entry") &&
40 !strcmp(entry
->value
, "42")) {
45 if (!strcmp(entry
->section
, "section2")) {
49 if (!strcmp(entry
->section
, "section 3")) {
51 if (!strcmp(entry
->name
, "name with a space") &&
52 !strcmp(entry
->value
, "another value")) {
53 state
->text_entry
= 1;
57 if (!strcmp(entry
->section
, "")) {
58 state
->section_global
= 1;
64 int main(int argc
, char **argv
)
68 struct state state
= {};
71 diag("Usage: path_to_sample_INI_file");
75 if (strlen(argv
[1]) >= LTTNG_PATH_MAX
) {
76 diag("The provided path exceeds the maximal permitted length of %i bytes",
80 path
= utils_expand_path(argv
[1]);
82 fail("Failed to resolve sample INI file path")
86 ret
= config_get_section_entries(path
, NULL
,
87 (config_entry_handler_cb
)entry_handler
, &state
);
88 ok(ret
== 0, "Successfully opened a config file, registered to all sections");
89 ok(state
.section_1
&& state
.section_2
&& state
.section_3
&&
90 state
.section_global
, "Processed entries from each sections");
91 ok(state
.text_entry
, "Text value parsed correctly");
93 memset(&state
, 0, sizeof(struct state
));
94 ret
= config_get_section_entries(path
, "section1",
95 (config_entry_handler_cb
)entry_handler
, &state
);
96 ok(ret
== 0, "Successfully opened a config file, registered to one section");
97 ok(state
.section_1
&& !state
.section_2
&& !state
.section_3
&&
98 !state
.section_global
, "Processed an entry from section1 only");
99 ok(state
.int_entry
, "Int value parsed correctly");
101 memset(&state
, 0, sizeof(struct state
));
102 ret
= config_get_section_entries(path
, "",
103 (config_entry_handler_cb
)entry_handler
, &state
);
104 ok(ret
== 0, "Successfully opened a config file, registered to the global section");
105 ok(!state
.section_1
&& !state
.section_2
&& !state
.section_3
&&
106 state
.section_global
, "Processed an entry from the global section only");
109 return exit_status();
This page took 0.032141 seconds and 4 git commands to generate.