Add new function nmem_strsplitx.
[yaz-moved-to-github.git] / test / test_xml_include.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2011 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     const char *srcdir = getenv("srcdir");
19     xmlDocPtr doc;
20     xmlNodePtr node;
21     const char *xml_in = "<x><include src=\"test_xml_inc*.xml\"/></x>";
22
23     if (srcdir == 0)
24         srcdir = ".";
25
26     doc = xmlParseMemory(xml_in, strlen(xml_in));
27     YAZ_CHECK(doc);
28     if (!doc)
29         return;
30     node = xmlDocGetRootElement(doc);
31     YAZ_CHECK(node);
32     if (node)
33     {
34         const char *expect =
35             "<?xml version=\"1.0\"?>\n"
36             "<x><!-- begin include src=\"test_xml_inc*.xml\" -->"
37             "<y>some</y>"
38             "<!-- end include src=\"test_xml_inc*.xml\" --></x>\n";
39
40         xmlChar *xml_out;
41         int len_out;
42         int ret = yaz_xml_include_simple(node, srcdir);
43         YAZ_CHECK(ret == 0);
44         xmlDocDumpMemory(doc, &xml_out, &len_out);
45         YAZ_CHECK(xml_out && len_out > 0);
46         if (xml_out && len_out > 0)
47         {
48             YAZ_CHECK(strlen(expect) == len_out);
49             if (strlen(expect) == len_out)
50             {
51                 YAZ_CHECK(memcmp(expect, xml_out, len_out) == 0);
52             }
53             else
54             {
55                 fwrite(xml_out, 1, len_out, stdout);
56                 fflush(stdout);
57             }
58             xmlFree(xml_out);
59         }
60     }
61     xmlFreeDoc(doc);
62 }
63
64
65 int main (int argc, char **argv)
66 {
67     YAZ_CHECK_INIT(argc, argv);
68     YAZ_CHECK_LOG();
69     tst_xml_include();
70     YAZ_CHECK_TERM;
71 }
72
73 /*
74  * Local variables:
75  * c-basic-offset: 4
76  * c-file-style: "Stroustrup"
77  * indent-tabs-mode: nil
78  * End:
79  * vim: shiftwidth=4 tabstop=8 expandtab
80  */
81