Added yaz_log_trunc() to truncate the log file
[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.3 2006-07-06 13:10:31 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(nfa);
30 }
31
32
33
34 /** \brief  Test parsing of a minimal, invalid xml string */
35 void test2() {
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     yaz_nfa *nfa=yaz_nfa_parse_xml_memory(xmlstr);
44     YAZ_CHECK(!nfa);
45 }
46
47
48 int main(int argc, char **argv)
49 {
50     YAZ_CHECK_INIT(argc, argv);
51     YAZ_CHECK_LOG();
52     nmem_init ();
53
54     test1();
55     test2();
56
57     nmem_exit ();
58     YAZ_CHECK_TERM;
59 }
60
61 #else
62 int main(int argc, char **argv) {
63     YAZ_CHECK_INIT(argc, argv);
64     YAZ_CHECK_TERM;
65 }
66
67 #endif
68
69 /* 
70  * Local variables:
71  * c-basic-offset: 4
72  * indent-tabs-mode: nil
73  * End:
74  * vim: shiftwidth=4 tabstop=8 expandtab
75  */