1 /*****************************************************************************
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *****************************************************************************/
20 #include "utils_base.h"
21 #include "parse_ini.h"
25 void my_free(char *string
) {
27 printf("string:\n\t|%s|\n", string
);
32 char *list2str(np_arg_list
*optlst
) {
36 /* Put everything as a space-separated string */
37 asprintf(&optstr
, "");
39 asprintf(&optstr
, "%s%s ", optstr
, optlst
->arg
);
41 optlst
= optlst
->next
;
44 /* Strip last whitespace */
45 if (strlen(optstr
) > 1)
46 optstr
[strlen(optstr
) - 1] = '\0';
51 int main(int argc
, char **argv
) {
56 optstr
= list2str(np_get_defaults("section@./config-tiny.ini", "check_disk"));
57 ok(!strcmp(optstr
, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected");
60 optstr
= list2str(np_get_defaults("@./config-tiny.ini", "section"));
61 ok(!strcmp(optstr
, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific");
64 optstr
= list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk"));
65 ok(!strcmp(optstr
, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected");
68 optstr
= list2str(np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk"));
69 ok(!strcmp(optstr
, "--this=that"), "config-tiny.ini's filename as section name");
72 optstr
= list2str(np_get_defaults("section2@./config-tiny.ini", "check_disk"));
73 ok(!strcmp(optstr
, "--this=that"), "config-tiny.ini's section2 with whitespace before section name");
76 optstr
= list2str(np_get_defaults("section3@./config-tiny.ini", "check_disk"));
77 ok(!strcmp(optstr
, "--this=that"), "config-tiny.ini's section3 with whitespace after section name");
80 optstr
= list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk"));
81 ok(!strcmp(optstr
, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected");
84 optstr
= list2str(np_get_defaults("check_mysql2@./plugin.ini", "check_disk"));
85 ok(!strcmp(optstr
, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected");
88 optstr
= list2str(np_get_defaults("check space_and_flags@./plugin.ini", "check_disk"));
89 ok(!strcmp(optstr
, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments");
92 optstr
= list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk"));
93 ok(!strcmp(optstr
, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected");
96 optstr
= list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk"));
97 ok(!strcmp(optstr
, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file");
100 optstr
= list2str(np_get_defaults("tcp_long_lines@plugins.ini", "check_tcp"));
101 ok(!strcmp(optstr
, "--escape --send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar "
102 "BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
103 "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
104 "yadda yadda Foo bar BAZ yadda yadda yadda Foo "
105 "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
106 "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
107 "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda --expect=Foo bar BAZ yadda yadda "
108 "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
109 "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo "
110 "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
111 "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
112 "yadda yadda Foo bar BAZ yadda yadda yadda Foo "
113 "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
114 "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
115 "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo "
116 "bar BAZ yadda yadda yadda --jail"),
120 return exit_status();