Remove member soap_handler from statserv_options_block
[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_include1(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 static void tst_xml_include2(void)
67 {
68 #if YAZ_HAVE_XML2
69     const char *srcdir = getenv("srcdir");
70     xmlDocPtr doc;
71     xmlNodePtr node;
72     const char *xml_in = "<x><include src=\"test_xml_no.xml\"/></x>";
73
74     if (srcdir == 0)
75         srcdir = ".";
76
77     doc = xmlParseMemory(xml_in, strlen(xml_in));
78     YAZ_CHECK(doc);
79     if (!doc)
80         return;
81     node = xmlDocGetRootElement(doc);
82     YAZ_CHECK(node);
83     if (node)
84     {
85         int ret = yaz_xml_include_glob(node, srcdir,
86                                        YAZ_FILE_GLOB_FAIL_NOTEXIST);
87         YAZ_CHECK_EQ(ret, -1);
88     }
89     if (node)
90     {
91         int ret = yaz_xml_include_glob(node, srcdir,
92                                        0);
93         YAZ_CHECK_EQ(ret, 0);
94     }
95     xmlFreeDoc(doc);
96 #endif
97 }
98
99 static void tst_xml_include3(void)
100 {
101 #if YAZ_HAVE_XML2
102     const char *srcdir = getenv("srcdir");
103     xmlDocPtr doc;
104     xmlNodePtr node;
105     const char *xml_in = "<x><include src=\"test_xml_no*.xml\"/></x>";
106
107     if (srcdir == 0)
108         srcdir = ".";
109
110     doc = xmlParseMemory(xml_in, strlen(xml_in));
111     YAZ_CHECK(doc);
112     if (!doc)
113         return;
114     node = xmlDocGetRootElement(doc);
115     YAZ_CHECK(node);
116     if (node)
117     {
118         const char *expect =
119             "<?xml version=\"1.0\"?>\n"
120             "<x><!-- begin include src=\"test_xml_no*.xml\" -->"
121             "<!-- end include src=\"test_xml_no*.xml\" --></x>\n";
122
123         xmlChar *xml_out;
124         int len_out;
125         int ret = yaz_xml_include_simple(node, srcdir);
126         YAZ_CHECK(ret == 0);
127         xmlDocDumpMemory(doc, &xml_out, &len_out);
128         YAZ_CHECK(xml_out && len_out > 0);
129         if (xml_out && len_out > 0)
130         {
131             YAZ_CHECK(strlen(expect) == len_out);
132             if (strlen(expect) == len_out)
133             {
134                 YAZ_CHECK(memcmp(expect, xml_out, len_out) == 0);
135             }
136             else
137             {
138                 fwrite(xml_out, 1, len_out, stdout);
139                 fflush(stdout);
140             }
141             xmlFree(xml_out);
142         }
143     }
144     xmlFreeDoc(doc);
145 #endif
146 }
147
148
149
150 int main (int argc, char **argv)
151 {
152     YAZ_CHECK_INIT(argc, argv);
153     YAZ_CHECK_LOG();
154     tst_xml_include1();
155     tst_xml_include2();
156     tst_xml_include3();
157     YAZ_CHECK_TERM;
158 }
159
160 /*
161  * Local variables:
162  * c-basic-offset: 4
163  * c-file-style: "Stroustrup"
164  * indent-tabs-mode: nil
165  * End:
166  * vim: shiftwidth=4 tabstop=8 expandtab
167  */
168