2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #include <common/ini-config/ini-config.hpp>
9 #include <common/path.hpp>
10 #include <common/utils.hpp>
12 #include <lttng/constant.h>
28 int lttng_opt_quiet
= 1;
29 int lttng_opt_verbose
= 0;
32 static int entry_handler(const struct config_entry
*entry
, struct state
*state
)
36 if (!entry
|| !state
) {
41 if (!strcmp(entry
->section
, "section1")) {
43 if (!strcmp(entry
->name
, "section1_entry") && !strcmp(entry
->value
, "42")) {
48 if (!strcmp(entry
->section
, "section2")) {
52 if (!strcmp(entry
->section
, "section 3")) {
54 if (!strcmp(entry
->name
, "name with a space") &&
55 !strcmp(entry
->value
, "another value")) {
56 state
->text_entry
= 1;
60 if (!strcmp(entry
->section
, "")) {
61 state
->section_global
= 1;
67 int main(int argc
, char **argv
)
71 struct state state
= {};
74 diag("Usage: path_to_sample_INI_file");
78 if (strlen(argv
[1]) >= LTTNG_PATH_MAX
) {
79 diag("The provided path exceeds the maximal permitted length of %i bytes",
83 path
= utils_expand_path(argv
[1]);
85 fail("Failed to resolve sample INI file path");
89 ret
= config_get_section_entries(
90 path
, nullptr, (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
&& state
.section_global
,
93 "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(
98 path
, "section1", (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
&& !state
.section_global
,
101 "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
, "", (config_entry_handler_cb
) entry_handler
, &state
);
106 ok(ret
== 0, "Successfully opened a config file, registered to the global section");
107 ok(!state
.section_1
&& !state
.section_2
&& !state
.section_3
&& state
.section_global
,
108 "Processed an entry from the global section only");
111 return exit_status();
This page took 0.031366 seconds and 4 git commands to generate.