Code

Fix base64 test (known string wasn't null-terminated)
[nagiosplug.git] / lib / tests / test_ini.c
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 2 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, write to the Free Software
15  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  $Id$
18  
19 ******************************************************************************/
21 #include "common.h"
22 #include "parse_ini.h"
24 #include "tap.h"
26 void my_free(char *string) {
27         if (string != NULL) {
28                 printf("string:\n\t|%s|\n", string);
29                 free(string);
30         }
31 }
33 int
34 main (int argc, char **argv)
35 {
36         char *optstr=NULL;
38         plan_tests(4);
40         optstr=np_get_defaults("section@./config-tiny.ini", "check_disk");
41         ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "config-tiny.ini's section as expected");
42         my_free(optstr);
44         optstr=np_get_defaults("@./config-tiny.ini", "section");
45         ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name, without specific");
46         my_free(optstr);
48         /* This test currently crashes */
49         /*
50         optstr=np_get_defaults("section_unknown@./config-tiny.ini", "section");
51         ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name over specified one");
52         my_free(optstr);
53         */
55         optstr=np_get_defaults("Section Two@./config-tiny.ini", "check_disk");
56         ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected");
57         my_free(optstr);
59         /* These tests currently crash parse_ini.c */
60         /*
61         optstr=np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk");
62         ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's filename as section name");
63         my_free(optstr);
65         optstr=np_get_defaults("section2@./config-tiny.ini", "check_disk");
66         ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name");
67         my_free(optstr);
69         optstr=np_get_defaults("section3@./config-tiny.ini", "check_disk");
70         ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name");
71         my_free(optstr);
72         */
74         optstr=np_get_defaults("check_mysql@./plugin.ini", "check_disk");
75         ok( !strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected");
76         my_free(optstr);
78         /* This test crashes at the moment. I think it is not expecting single character parameter names */
79         /*
80         optstr=np_get_defaults("check_mysql2@./config-tiny.ini", "check_disk");
81         ok( !strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected");
82         my_free(optstr);
83         */
85         return exit_status();
86 }