diff options
author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-03-15 16:17:49 (GMT) |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2008-03-15 16:17:49 (GMT) |
commit | ffab7ee68b32d44ae2f35f688f417cd0109b0b45 (patch) | |
tree | 664a4d469f3772e5c91d483262fe384f2f7f6197 /lib/tests | |
parent | 6004d95868fcd9badbc0f026980a4a3597eb22db (diff) | |
download | monitoring-plugins-ffab7ee68b32d44ae2f35f688f417cd0109b0b45.tar.gz |
Fix segfault in test_ini.c and uncomment the affected tests
Fix bug in stanza parsing where full section could be skipped
Fix single-argument options
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1946 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib/tests')
-rw-r--r-- | lib/tests/test_ini.c | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/lib/tests/test_ini.c b/lib/tests/test_ini.c index b02d145..de9f8ad 100644 --- a/lib/tests/test_ini.c +++ b/lib/tests/test_ini.c | |||
@@ -36,12 +36,13 @@ list2str(np_arg_list *optlst) | |||
36 | char *optstr=NULL; | 36 | char *optstr=NULL; |
37 | 37 | ||
38 | /* Put everything as a space-separated string */ | 38 | /* Put everything as a space-separated string */ |
39 | asprintf(&optstr, ""); | ||
39 | while (optlst) { | 40 | while (optlst) { |
40 | asprintf(&optstr, "%s%s ", optstr?optstr:"", optlst->arg); | 41 | asprintf(&optstr, "%s%s ", optstr, optlst->arg); |
41 | optlst=optlst->next; | 42 | optlst=optlst->next; |
42 | } | 43 | } |
43 | /* Strip last whitespace */ | 44 | /* Strip last whitespace */ |
44 | optstr[strlen(optstr)-1]='\0'; | 45 | if (strlen(optstr)>1) optstr[strlen(optstr)-1]='\0'; |
45 | 46 | ||
46 | return optstr; | 47 | return optstr; |
47 | } | 48 | } |
@@ -51,7 +52,7 @@ main (int argc, char **argv) | |||
51 | { | 52 | { |
52 | char *optstr=NULL; | 53 | char *optstr=NULL; |
53 | 54 | ||
54 | plan_tests(4); | 55 | plan_tests(9); |
55 | 56 | ||
56 | optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); | 57 | 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"); | 58 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "config-tiny.ini's section as expected"); |
@@ -61,42 +62,33 @@ main (int argc, char **argv) | |||
61 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name, without specific"); | 62 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name, without specific"); |
62 | my_free(optstr); | 63 | my_free(optstr); |
63 | 64 | ||
64 | /* This test currently crashes */ | 65 | optstr=list2str(np_get_defaults("section_unknown@./config-tiny.ini", "section")); |
65 | /* | ||
66 | optstr=np_get_defaults("section_unknown@./config-tiny.ini", "section"); | ||
67 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name over specified one"); | 66 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank="), "Used default section name over specified one"); |
68 | my_free(optstr); | 67 | my_free(optstr); |
69 | */ | ||
70 | 68 | ||
71 | optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk")); | 69 | optstr=list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk")); |
72 | ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected"); | 70 | ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected"); |
73 | my_free(optstr); | 71 | my_free(optstr); |
74 | 72 | ||
75 | /* These tests currently crash parse_ini.c */ | 73 | optstr=list2str(np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk")); |
76 | /* | ||
77 | optstr=np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk"); | ||
78 | ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's filename as section name"); | 74 | ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's filename as section name"); |
79 | my_free(optstr); | 75 | my_free(optstr); |
80 | 76 | ||
81 | optstr=np_get_defaults("section2@./config-tiny.ini", "check_disk"); | 77 | optstr=list2str(np_get_defaults("section2@./config-tiny.ini", "check_disk")); |
82 | ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name"); | 78 | ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name"); |
83 | my_free(optstr); | 79 | my_free(optstr); |
84 | 80 | ||
85 | optstr=np_get_defaults("section3@./config-tiny.ini", "check_disk"); | 81 | optstr=list2str(np_get_defaults("section3@./config-tiny.ini", "check_disk")); |
86 | ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name"); | 82 | ok( !strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name"); |
87 | my_free(optstr); | 83 | my_free(optstr); |
88 | */ | ||
89 | 84 | ||
90 | optstr=list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk")); | 85 | optstr=list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk")); |
91 | ok( !strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected"); | 86 | ok( !strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected"); |
92 | my_free(optstr); | 87 | my_free(optstr); |
93 | 88 | ||
94 | /* This test crashes at the moment. I think it is not expecting single character parameter names */ | 89 | optstr=list2str(np_get_defaults("check_mysql2@./plugin.ini", "check_disk")); |
95 | /* | ||
96 | optstr=np_get_defaults("check_mysql2@./config-tiny.ini", "check_disk"); | ||
97 | ok( !strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected"); | 90 | ok( !strcmp(optstr, "-u=admin -p=secret"), "plugin.ini's check_mysql2 as expected"); |
98 | my_free(optstr); | 91 | my_free(optstr); |
99 | */ | ||
100 | 92 | ||
101 | return exit_status(); | 93 | return exit_status(); |
102 | } | 94 | } |