diff options
-rw-r--r-- | lib/tests/config-dos.ini | 24 | ||||
-rw-r--r-- | lib/tests/plugin.ini | 6 | ||||
-rw-r--r-- | lib/tests/test_ini.c | 13 |
3 files changed, 42 insertions, 1 deletions
diff --git a/lib/tests/config-dos.ini b/lib/tests/config-dos.ini new file mode 100644 index 00000000..0cea3f3a --- /dev/null +++ b/lib/tests/config-dos.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] | ||
7 | one=two | ||
8 | Foo=Bar | ||
9 | this=Your Mother! | ||
10 | blank= | ||
11 | |||
12 | [Section Two] | ||
13 | something else=blah | ||
14 | remove = whitespace | ||
15 | |||
16 | [ /path/to/file.txt ] | ||
17 | this=that | ||
18 | |||
19 | [ section2] | ||
20 | this=that | ||
21 | |||
22 | [section3 ] | ||
23 | this=that | ||
24 | |||
diff --git a/lib/tests/plugin.ini b/lib/tests/plugin.ini index d07fc4f3..e22f8bdb 100644 --- a/lib/tests/plugin.ini +++ b/lib/tests/plugin.ini | |||
@@ -3,10 +3,16 @@ | |||
3 | username=operator | 3 | username=operator |
4 | password=secret # Remember to change later | 4 | password=secret # Remember to change later |
5 | 5 | ||
6 | [section_twice] | ||
7 | foo=bar | ||
8 | |||
6 | [check_mysql2] | 9 | [check_mysql2] |
7 | u=admin | 10 | u=admin |
8 | p=secret | 11 | p=secret |
9 | 12 | ||
13 | [section_twice] | ||
14 | bar=foo | ||
15 | |||
10 | [check space_and_flags] | 16 | [check space_and_flags] |
11 | foo=bar | 17 | foo=bar |
12 | a= | 18 | a= |
diff --git a/lib/tests/test_ini.c b/lib/tests/test_ini.c index 9031f7f8..84749279 100644 --- a/lib/tests/test_ini.c +++ b/lib/tests/test_ini.c | |||
@@ -34,12 +34,15 @@ char* | |||
34 | list2str(np_arg_list *optlst) | 34 | list2str(np_arg_list *optlst) |
35 | { | 35 | { |
36 | char *optstr=NULL; | 36 | char *optstr=NULL; |
37 | np_arg_list *optltmp; | ||
37 | 38 | ||
38 | /* Put everything as a space-separated string */ | 39 | /* Put everything as a space-separated string */ |
39 | asprintf(&optstr, ""); | 40 | asprintf(&optstr, ""); |
40 | while (optlst) { | 41 | while (optlst) { |
41 | asprintf(&optstr, "%s%s ", optstr, optlst->arg); | 42 | asprintf(&optstr, "%s%s ", optstr, optlst->arg); |
43 | optltmp=optlst; | ||
42 | optlst=optlst->next; | 44 | optlst=optlst->next; |
45 | free(optltmp); | ||
43 | } | 46 | } |
44 | /* Strip last whitespace */ | 47 | /* Strip last whitespace */ |
45 | if (strlen(optstr)>1) optstr[strlen(optstr)-1]='\0'; | 48 | if (strlen(optstr)>1) optstr[strlen(optstr)-1]='\0'; |
@@ -52,7 +55,7 @@ main (int argc, char **argv) | |||
52 | { | 55 | { |
53 | char *optstr=NULL; | 56 | char *optstr=NULL; |
54 | 57 | ||
55 | plan_tests(10); | 58 | plan_tests(12); |
56 | 59 | ||
57 | optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); | 60 | optstr=list2str(np_get_defaults("section@./config-tiny.ini", "check_disk")); |
58 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected"); | 61 | ok( !strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected"); |
@@ -94,6 +97,14 @@ main (int argc, char **argv) | |||
94 | ok( !strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments"); | 97 | ok( !strcmp(optstr, "--foo=bar -a -b --bar"), "plugin.ini space in stanza and flag arguments"); |
95 | my_free(optstr); | 98 | my_free(optstr); |
96 | 99 | ||
100 | optstr=list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk")); | ||
101 | ok( !strcmp(optstr, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected"); | ||
102 | my_free(optstr); | ||
103 | |||
104 | optstr=list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk")); | ||
105 | ok( !strcmp(optstr, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file"); | ||
106 | my_free(optstr); | ||
107 | |||
97 | return exit_status(); | 108 | return exit_status(); |
98 | } | 109 | } |
99 | 110 | ||