]> git.ozlabs.org Git - ccan/blob - ccan/ciniparser/test/run.c
merge
[ccan] / ccan / ciniparser / test / run.c
1 #include <ciniparser/ciniparser.h>
2 #include <ciniparser/ciniparser.c>
3 #include <ciniparser/dictionary.h>
4 #include <ciniparser/dictionary.c>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include <stdbool.h>
10
11 #include <tap/tap.h>
12
13 #define NUM_TESTS 12
14
15 int main(int argc, char * argv[])
16 {
17         dictionary *ini;
18         char *ini_name;
19         char *stmp, *stmp1, *stmp2, *stmp3;
20         int itmp, itmp1, i;
21         bool btmp;
22         double dtmp;
23
24         if (argc < 2)
25                 ini_name = "ccan/ciniparser/test/test.ini";
26         else
27                 ini_name = argv[1] ;
28
29         plan_tests(NUM_TESTS);
30
31         ok(ini = ciniparser_load(ini_name),
32                 "ciniparser_load()      : loading %s", ini_name);
33         ok(itmp = ciniparser_getnsec(ini),
34                 "ciniparser_getnsec()   : %d entries in dictionary %s",
35                         itmp, ini_name);
36         ok(stmp = ciniparser_getsecname(ini, itmp),
37                 "ciniparser_getsecname(): last dict entry (%d) is %s", itmp, stmp);
38         ok(stmp2 = ciniparser_getsecname(ini, 1),
39                 "ciniparser_getsecname(): first dict entry is %s", stmp2);
40         ok(i = ciniparser_find_entry(ini, "Foo:shemp"),
41                 "ciniparser_find_entry(): checking if Foo:shemp exists (%s)",
42                         i ? "yes" : "no");
43         ok(stmp1 = ciniparser_getstring(ini, "Wine:Grape", NULL),
44                 "ciniparser_getstring() : Wine:Grape = %s", stmp1);
45         ok(!ciniparser_set(ini, "Wine:Grape", "Grape Ape"),
46                 "ciniparser_set()       : Wine:Grape is now Grape Ape");
47         ok(stmp2 = ciniparser_getstring(ini, "Wine:Grape", NULL),
48                 "ciniparser_getstring() : Wine:Grape = %s", stmp2);
49         ciniparser_unset(ini, "Wine:Grape");
50         ok(! (stmp3 = ciniparser_getstring(ini, "Wine:Grape", NULL)),
51                 "ciniparser_unset()     : Wine:Grape should be unset if "
52                 "stmp3 is uninitialized (%s)",
53                         stmp3 == NULL ? "Yes" : "no");
54         ok(itmp1 = ciniparser_getint(ini, "Pizza:Capres", 0),
55                 "ciniparser_getint()    : Pizza:Capres = %d", itmp1);
56         ok(btmp = ciniparser_getboolean(ini, "Pizza:Mushrooms", 0),
57                 "ciniparser_getboolean(): Pizza:Capres = %s", btmp ? "true" : "false");
58         ok(dtmp = ciniparser_getdouble(ini, "Wine:Alcohol", 0.00),
59                 "ciniparser_getdouble() : Wine:Alcohol = %-2.1f", dtmp);
60
61         /* Just make sure we don't segfault here */
62
63         ciniparser_dump(ini, stdout);
64         ciniparser_dump_ini(ini, stdout);
65
66         ciniparser_freedict(ini);
67
68         return exit_status();
69 }