Add test of XML Include
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 22 Jan 2010 22:02:08 +0000 (23:02 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 22 Jan 2010 22:02:08 +0000 (23:02 +0100)
test/.gitignore
test/Makefile.am
test/tst_xml_include.c [new file with mode: 0644]
test/tst_xml_include.xml [new file with mode: 0644]

index dabacdc..0ffa500 100644 (file)
@@ -29,6 +29,7 @@ tst_icu_I18N
 tst_match_glob
 tst_rpn2cql
 tst_json
+tst_xml_include
 nfatest1
 nfaxmltest1
 tst_oid
index 459177c..e813f65 100644 (file)
@@ -6,7 +6,7 @@ check_PROGRAMS = tstxmalloc tsticonv tstnmem tstmatchstr tstwrbuf tstodr \
  tstsoap1 tstsoap2 tstodrstack tstlogthread tstxmlquery tstpquery \
  tst_comstack tst_filepath tst_record_conv tst_retrieval tst_tpath \
  tst_timing tst_query_charset tst_oid tst_icu_I18N tst_match_glob \
- tst_rpn2cql tst_json
+ tst_rpn2cql tst_json tst_xml_include
 
 check_SCRIPTS = tstmarc.sh tstmarccol.sh tstcql2xcql.sh tstcql2pqf.sh tsticu.sh
 
@@ -31,7 +31,7 @@ EXTRA_DIST = tstodr.asn tstodrcodec.c tstodrcodec.h cql2xcqlsample \
  marccol5.u8.marc marccol5.u8.1.lst marccol5.u8.2.lst \
  tsticu-0.xml tsticu-0.input tsticu-0.output \
  tsticu-1.xml tsticu-1.input tsticu-1.output \
- tst_record_conv.xsl 
+ tst_record_conv.xsl tst_xml_include.xml
 
 YAZCOMP = ../util/yaz-asncomp
 YAZCOMPLINE = $(YAZCOMP) -d z.tcl -i yaz -I../include $(YCFLAGS)
@@ -79,3 +79,4 @@ tst_icu_I18N_SOURCES = tst_icu_I18N.c
 tst_match_glob_SOURCES = tst_match_glob.c
 tst_rpn2cql_SOURCES = tst_rpn2cql.c
 tst_json_SOURCES = tst_json.c
+tst_xml_include_SOURCES = tst_xml_include.c
diff --git a/test/tst_xml_include.c b/test/tst_xml_include.c
new file mode 100644 (file)
index 0000000..235cbbe
--- /dev/null
@@ -0,0 +1,78 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <yaz/xml_include.h>
+#include <yaz/test.h>
+
+static void tst_xml_include(void)
+{
+    const char *srcdir = getenv("srcdir");
+    xmlDocPtr doc;
+    xmlNodePtr node;
+    const char *xml_in = "<x><include src=\"tst_xml_include.xml\"/></x>";
+
+    if (srcdir == 0)
+        srcdir = ".";
+
+    doc = xmlParseMemory(xml_in, strlen(xml_in));
+    YAZ_CHECK(doc);
+    if (!doc)
+        return;
+    node = xmlDocGetRootElement(doc);
+    YAZ_CHECK(node);
+    if (node)
+    {
+        const char *expect =
+            "<?xml version=\"1.0\"?>\n"
+            "<x><!-- begin include src=\"tst_xml_include.xml\" -->"
+            "<y>some</y>"
+            "<!-- end include src=\"tst_xml_include.xml\" --></x>\n";
+
+        xmlChar *xml_out;
+        int len_out;
+        int ret = yaz_xml_include_simple(node, srcdir);
+        YAZ_CHECK(ret == 0);
+        xmlDocDumpMemory(doc, &xml_out, &len_out);
+        YAZ_CHECK(xml_out && len_out > 0);
+        if (xml_out && len_out > 0)
+        {
+            YAZ_CHECK(strlen(expect) == len_out);
+            if (strlen(expect) == len_out)
+            {
+                YAZ_CHECK(memcmp(expect, xml_out, len_out) == 0);
+            }
+            else
+            {
+                fwrite(xml_out, 1, len_out, stdout);
+                fflush(stdout);
+            }
+            xmlFree(xml_out);
+        }
+    }
+    xmlFreeDoc(doc);
+}
+
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    YAZ_CHECK_LOG();
+    tst_xml_include();
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/tst_xml_include.xml b/test/tst_xml_include.xml
new file mode 100644 (file)
index 0000000..da253be
--- /dev/null
@@ -0,0 +1 @@
+<y>some</y>