Added YAZ_CHECK_TODO macro, used it in nfaxmltest1.
[yaz-moved-to-github.git] / test / nfaxmltest1.c
1 /*  Copyright (C) 2006, Index Data ApS
2  *  See the file LICENSE for details.
3  *
4  *  $Id: nfaxmltest1.c,v 1.6 2006-07-07 13:39:05 heikki Exp $
5  *
6  */
7
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <yaz/nfa.h>
12 #include <yaz/nmem.h>
13 #include <yaz/test.h>
14 #include <yaz/nfaxml.h>
15
16 #if YAZ_HAVE_XML2
17 #include <libxml/parser.h>
18
19
20 /** \brief  Test parsing of a minimal, valid xml string */
21 void test1() {
22     char *xmlstr = "<ruleset> "
23                    "<rule> "
24                    "  <fromstring>foo</fromstring> "
25                    "  <tostring>bar</tostring> "
26                    "</rule>"
27                    "</ruleset>";
28     yaz_nfa *nfa = yaz_nfa_parse_xml_memory(xmlstr);
29     YAZ_CHECK_TODO(nfa);
30 }
31
32
33 /** \brief  Test parsing of a minimal, invalid xml string */
34 void test2() {
35     yaz_nfa *nfa;
36     char *xmlstr = "<ruleset> "
37                    "<rule> "
38                    "  <fromstring>foo</fromstring> "
39                    "  <tostring>bar</tostring> "
40                    "</rule>";
41                  /* missing "</ruleset>" */
42     yaz_log(YLOG_LOG,"Parsing bad xml, expecting errors:");
43     nfa = yaz_nfa_parse_xml_memory(xmlstr);
44     YAZ_CHECK(!nfa);
45 }
46
47 /** \brief  Test parsing a few minimal xml files */
48 void test3() {
49     char *goodfilenames[] = {
50              "nfaxml-simple.xml",
51              "nfaxml-main.xml", /* x-includes nfaxml-include */
52               0};
53     char *badfilenames[] = {
54              "nfaxml-missing.xml",  /* file not there at all */
55              "nfaxml-badinclude.xml",  /* bad xinclude in it */
56               0};
57     yaz_nfa *nfa;
58     char **f = goodfilenames;
59     do {
60         yaz_log(YLOG_LOG,"Parsing (good) xml file '%s'", *f);
61         nfa=yaz_nfa_parse_xml_file(*f);
62         YAZ_CHECK_TODO(nfa);
63     } while (*++f);
64
65     f = badfilenames;
66     do {
67         yaz_log(YLOG_LOG,"Parsing bad xml file '%s'. Expecting errors", *f);
68         nfa = yaz_nfa_parse_xml_file(*f);
69         YAZ_CHECK(!nfa);
70     } while (*++f);
71 }
72
73
74 int main(int argc, char **argv)
75 {
76     YAZ_CHECK_INIT(argc, argv);
77     YAZ_CHECK_LOG();
78     nmem_init ();
79
80     test1();
81     test2();
82     test3();
83
84     nmem_exit ();
85     YAZ_CHECK_TERM;
86 }
87
88 #else
89 int main(int argc, char **argv) {
90     YAZ_CHECK_INIT(argc, argv);
91     YAZ_CHECK_TERM;
92 }
93
94 #endif
95
96 /* 
97  * Local variables:
98  * c-basic-offset: 4
99  * indent-tabs-mode: nil
100  * End:
101  * vim: shiftwidth=4 tabstop=8 expandtab
102  */