diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2007-02-07 14:46:50 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2007-02-07 14:46:50 +0000 |
commit | 88ff55667012171c688471eaa84d16311018ec9c (patch) | |
tree | eb9dffa003f14fceed03241128e7872398559865 /lib/tests/test_ini.c | |
parent | c391272975965ded901818c73abc492e1e354acb (diff) | |
download | monitoring-plugins-88ff55667012171c688471eaa84d16311018ec9c.tar.gz |
Added test files to test the parse_ini.c routines. Requires libtap
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1614 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/tests/test_ini.c')
-rw-r--r-- | lib/tests/test_ini.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/lib/tests/test_ini.c b/lib/tests/test_ini.c new file mode 100644 index 00000000..f0e5cf42 --- /dev/null +++ b/lib/tests/test_ini.c | |||
@@ -0,0 +1,87 @@ | |||
1 | /****************************************************************************** | ||
2 | |||
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. | ||
7 | |||
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. | ||
12 | |||
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. | ||
16 | |||
17 | $Id$ | ||
18 | |||
19 | ******************************************************************************/ | ||
20 | |||
21 | #include "common.h" | ||
22 | #include "parse_ini.h" | ||
23 | |||
24 | #include "tap.h" | ||
25 | |||
26 | void my_free(char *string) { | ||
27 | if (string != NULL) { | ||
28 | printf("string:\n\t|%s|\n", string); | ||
29 | free(string); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | int | ||
34 | main (int argc, char **argv) | ||
35 | { | ||
36 | char *optstr=NULL; | ||
37 | |||
38 | plan_tests(4); | ||
39 | |||
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); | ||
43 | |||
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); | ||
47 | |||
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 | */ | ||
54 | |||
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); | ||
58 | |||
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); | ||
64 | |||
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); | ||
68 | |||
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 | */ | ||
73 | |||
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); | ||
77 | |||
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 | */ | ||
84 | |||
85 | return exit_status(); | ||
86 | } | ||
87 | |||