bc9aedf1063e73a032c85900fcd55642ea9f82d4
2 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
9 #include <common/ini-config/ini-config.hpp>
10 #include <common/utils.hpp>
11 #include <common/path.hpp>
13 #include <lttng/constant.h>
26 int lttng_opt_quiet
= 1;
27 int lttng_opt_verbose
= 0;
30 static int entry_handler(const struct config_entry
*entry
, struct state
*state
)
34 if (!entry
|| !state
) {
39 if (!strcmp(entry
->section
, "section1")) {
41 if (!strcmp(entry
->name
, "section1_entry") &&
42 !strcmp(entry
->value
, "42")) {
47 if (!strcmp(entry
->section
, "section2")) {
51 if (!strcmp(entry
->section
, "section 3")) {
53 if (!strcmp(entry
->name
, "name with a space") &&
54 !strcmp(entry
->value
, "another value")) {
55 state
->text_entry
= 1;
59 if (!strcmp(entry
->section
, "")) {
60 state
->section_global
= 1;
66 int main(int argc
, char **argv
)
70 struct state state
= {};
73 diag("Usage: path_to_sample_INI_file");
77 if (strlen(argv
[1]) >= LTTNG_PATH_MAX
) {
78 diag("The provided path exceeds the maximal permitted length of %i bytes",
82 path
= utils_expand_path(argv
[1]);
84 fail("Failed to resolve sample INI file path");
88 ret
= config_get_section_entries(path
, NULL
,
89 (config_entry_handler_cb
)entry_handler
, &state
);
90 ok(ret
== 0, "Successfully opened a config file, registered to all sections");
91 ok(state
.section_1
&& state
.section_2
&& state
.section_3
&&
92 state
.section_global
, "Processed entries from each sections");
93 ok(state
.text_entry
, "Text value parsed correctly");
95 memset(&state
, 0, sizeof(struct state
));
96 ret
= config_get_section_entries(path
, "section1",
97 (config_entry_handler_cb
)entry_handler
, &state
);
98 ok(ret
== 0, "Successfully opened a config file, registered to one section");
99 ok(state
.section_1
&& !state
.section_2
&& !state
.section_3
&&
100 !state
.section_global
, "Processed an entry from section1 only");
101 ok(state
.int_entry
, "Int value parsed correctly");
103 memset(&state
, 0, sizeof(struct state
));
104 ret
= config_get_section_entries(path
, "",
105 (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
&&
108 state
.section_global
, "Processed an entry from the global section only");
111 return exit_status();
This page took 0.031133 seconds and 4 git commands to generate.