Add unit test for ICU rule join
[yaz-moved-to-github.git] / test / test_xml_include.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2013 Index Data
3  * See the file LICENSE for details.
4  */
5 #if HAVE_CONFIG_H
6 #include <config.h>
7 #endif
8
9 #include <stdlib.h>
10 #include <string.h>
11 #include <stdio.h>
12
13 #include <yaz/xml_include.h>
14 #include <yaz/test.h>
15
16 static void tst_xml_include(void)
17 {
18 #if YAZ_HAVE_XML2
19     const char *srcdir = getenv("srcdir");
20     xmlDocPtr doc;
21     xmlNodePtr node;
22     const char *xml_in = "<x><include src=\"test_xml_inc*.xml\"/></x>";
23
24     if (srcdir == 0)
25         srcdir = ".";
26
27     doc = xmlParseMemory(xml_in, strlen(xml_in));
28     YAZ_CHECK(doc);
29     if (!doc)
30         return;
31     node = xmlDocGetRootElement(doc);
32     YAZ_CHECK(node);
33     if (node)
34     {
35         const char *expect =
36             "<?xml version=\"1.0\"?>\n"
37             "<x><!-- begin include src=\"test_xml_inc*.xml\" -->"
38             "<y>some</y>"
39             "<!-- end include src=\"test_xml_inc*.xml\" --></x>\n";
40
41         xmlChar *xml_out;
42         int len_out;
43         int ret = yaz_xml_include_simple(node, srcdir);
44         YAZ_CHECK(ret == 0);
45         xmlDocDumpMemory(doc, &xml_out, &len_out);
46         YAZ_CHECK(xml_out && len_out > 0);
47         if (xml_out && len_out > 0)
48         {
49             YAZ_CHECK(strlen(expect) == len_out);
50             if (strlen(expect) == len_out)
51             {
52                 YAZ_CHECK(memcmp(expect, xml_out, len_out) == 0);
53             }
54             else
55             {
56                 fwrite(xml_out, 1, len_out, stdout);
57                 fflush(stdout);
58             }
59             xmlFree(xml_out);
60         }
61     }
62     xmlFreeDoc(doc);
63 #endif
64 }
65
66
67 int main (int argc, char **argv)
68 {
69     YAZ_CHECK_INIT(argc, argv);
70     YAZ_CHECK_LOG();
71     tst_xml_include();
72     YAZ_CHECK_TERM;
73 }
74
75 /*
76  * Local variables:
77  * c-basic-offset: 4
78  * c-file-style: "Stroustrup"
79  * indent-tabs-mode: nil
80  * End:
81  * vim: shiftwidth=4 tabstop=8 expandtab
82  */
83