summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2007-02-07 14:46:50 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2007-02-07 14:46:50 +0000
commit88ff55667012171c688471eaa84d16311018ec9c (patch)
treeeb9dffa003f14fceed03241128e7872398559865
parentc391272975965ded901818c73abc492e1e354acb (diff)
downloadmonitoring-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
-rw-r--r--lib/Makefile.config-opts2
-rw-r--r--lib/parse_ini.c9
-rw-r--r--lib/tests/Makefile.config-opts6
-rw-r--r--lib/tests/config-tiny.ini24
-rw-r--r--lib/tests/plugin.ini10
-rw-r--r--lib/tests/test_ini.c87
6 files changed, 129 insertions, 9 deletions
diff --git a/lib/Makefile.config-opts b/lib/Makefile.config-opts
new file mode 100644
index 00000000..6546cb05
--- /dev/null
+++ b/lib/Makefile.config-opts
@@ -0,0 +1,2 @@
1parse_ini.o: parse_ini.c
2 gcc -I ../plugins -I ../gl -I .. -g -c -o parse_ini.o parse_ini.c
diff --git a/lib/parse_ini.c b/lib/parse_ini.c
index 5155b6df..b19537c2 100644
--- a/lib/parse_ini.c
+++ b/lib/parse_ini.c
@@ -236,12 +236,3 @@ static int add_option(FILE *f, char **optbuf, size_t *bufsize){
236 return 0; 236 return 0;
237} 237}
238 238
239int main(){
240 char *optstr=NULL;
241 optstr=np_get_defaults("check_foo@./foo.ini", "check_bar");
242 if(optstr!=NULL) {
243 printf("optstr:\n\t%s\n", optstr);
244 free(optstr);
245 }
246 return 0;
247}
diff --git a/lib/tests/Makefile.config-opts b/lib/tests/Makefile.config-opts
new file mode 100644
index 00000000..96326d34
--- /dev/null
+++ b/lib/tests/Makefile.config-opts
@@ -0,0 +1,6 @@
1
2test_ini: test_ini.o ../parse_ini.o
3 gcc -g -o test_ini test_ini.o ../parse_ini.o ../utils_base.o -L/usr/local/lib /usr/local/lib/libtap.so -Wl,--rpath -Wl,/usr/local/lib
4
5test_ini.o: test_ini.c
6 gcc -g test_ini.c -I ../../plugins -I ../../gl -I ../.. -I .. -c -o test_ini.o
diff --git a/lib/tests/config-tiny.ini b/lib/tests/config-tiny.ini
new file mode 100644
index 00000000..60f3dad4
--- /dev/null
+++ b/lib/tests/config-tiny.ini
@@ -0,0 +1,24 @@
1# This config file is amended from perl's Config::Tiny's testcases
2
3# Line below is allowed in perl's Config::Tiny, but not in our parse_ini.c
4#root=something
5
6[section]
7one=two
8Foo=Bar
9this=Your Mother!
10blank=
11
12[Section Two]
13something else=blah
14 remove = whitespace
15
16[ /path/to/file.txt ]
17this=that
18
19[ section2]
20this=that
21
22[section3 ]
23this=that
24
diff --git a/lib/tests/plugin.ini b/lib/tests/plugin.ini
new file mode 100644
index 00000000..eb869c63
--- /dev/null
+++ b/lib/tests/plugin.ini
@@ -0,0 +1,10 @@
1
2[check_mysql]
3username=operator
4password=secret # Remember to change later
5
6[check_mysql2]
7u=admin
8p=secret
9
10
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
26void my_free(char *string) {
27 if (string != NULL) {
28 printf("string:\n\t|%s|\n", string);
29 free(string);
30 }
31}
32
33int
34main (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