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