Annotation of embedaddon/confuse/tests/annotate.c, revision 1.1.1.1

1.1       misho       1: #include "check_confuse.h"
                      2: #include <string.h>
                      3: 
                      4: int main(void)
                      5: {
                      6:        char *comment;
                      7:        char *expect = "Now, is it this comment that goes with the option?";
                      8:        cfg_t *cfg;
                      9:        cfg_opt_t *opt;
                     10:        cfg_opt_t section_opts[] = {
                     11:                CFG_INT("key", 0, CFGF_NONE),
                     12:                CFG_BOOL("bool", 0, CFGF_NONE),
                     13:                CFG_STR("option", NULL, CFGF_NONE),
                     14:                CFG_END()
                     15:        };
                     16:        cfg_opt_t opts[] = {
                     17:                CFG_STR("option", NULL, CFGF_NONE),
                     18:                CFG_SEC("section", section_opts, CFGF_MULTI),
                     19:                CFG_END()
                     20:        };
                     21: 
                     22:        cfg = cfg_init(opts, CFGF_COMMENTS);
                     23:        fail_unless(cfg != NULL);
                     24: 
                     25:        fail_unless(cfg_parse(cfg, SRC_DIR "/annotate.conf") == CFG_SUCCESS);
                     26: 
                     27:        /* Verify the parser read the correct comment for this tricky option */
                     28:        opt = cfg_getopt(cfg, "section|option");
                     29:        fail_unless(opt != NULL);
                     30:        comment = cfg_opt_getcomment(opt);
                     31:        fail_unless(comment != NULL);
                     32:        fail_unless(strcmp(comment, expect) == 0);
                     33: 
                     34:        expect = "But what's the worst poetry in the universe?";
                     35:        fail_unless(cfg_opt_setcomment(opt, expect) == CFG_SUCCESS);
                     36: 
                     37:        cfg_opt_setnstr(opt, "Paula Nancy Millstone Jennings was a poet who wrote the worst poetry in "
                     38:                        "the universe. In fact, her poetry is still considered to be the worst in "
                     39:                        "the Galaxy, closely followed by that of the Azgoths of Kria and the "
                     40:                        "Vogons, in that order.", 0);
                     41: 
                     42:        /* Verify that the comment is not reset when changing option value */
                     43:        comment = cfg_opt_getcomment(opt);
                     44:        fail_unless(comment != NULL);
                     45:        fail_unless(strcmp(comment, expect) == 0);
                     46: 
                     47:        cfg_print(cfg, stdout);
                     48:        fail_unless(cfg_free(cfg) == CFG_SUCCESS);
                     49: 
                     50:        return 0;
                     51: }
                     52: 
                     53: /**
                     54:  * Local Variables:
                     55:  *  indent-tabs-mode: t
                     56:  *  c-file-style: "linux"
                     57:  * End:
                     58:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>