Bump copyright year
[idzebra-moved-to-github.git] / test / xslt / dom1.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 2004-2013 Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <yaz/test.h>
24 #include "testlib.h"
25
26
27 void index_more(ZebraHandle zh, const char *filter, const char *file)
28 {
29     char path[256];
30     char profile_path[256];
31
32     sprintf(profile_path, "%.80s:%.80s/../../tab",
33             tl_get_srcdir(), tl_get_srcdir());
34     zebra_set_resource(zh, "profilePath", profile_path);
35
36     zebra_set_resource(zh, "recordType", filter);
37
38     YAZ_CHECK(zebra_begin_trans(zh, 1) == ZEBRA_OK);
39     sprintf(path, "%.80s/%.80s", tl_get_srcdir(), file);
40
41     YAZ_CHECK(zebra_repository_update(zh, path) == ZEBRA_OK);
42     YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK);
43     zebra_commit(zh);
44 }
45
46 ZebraHandle index_some(ZebraService zs,
47                        const char *filter, const char *file)
48 {
49     ZebraHandle zh = zebra_open(zs, 0);
50
51     tl_check_filter(zs, "dom");
52
53     YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
54
55     zebra_init(zh);
56
57     index_more(zh, filter, file);
58     return zh;
59 }
60
61 void tst(int argc, char **argv)
62 {
63     ZebraHandle zh;
64
65     ZebraService zs = tl_start_up(0, argc, argv);
66
67     zh = index_some(zs, "dom.bad.xml", "marc-col.xml");
68     zebra_close(zh);
69
70
71     /* testing XMLREADER input with PI stylesheet */
72     zh = index_some(zs, "dom.dom-config-col.xml", "marc-col.xml");
73     YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 3));
74
75     /* fetch first using dom-brief.xsl */
76     YAZ_CHECK_EQ(tl_fetch_first_compare(
77                      zh, "B", yaz_oid_recsyn_xml,
78                      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
79                      "<title>How to program a computer</title>\n"),
80                  ZEBRA_OK);
81     /* fetch first using dom-snippets.xsl */
82     YAZ_CHECK_EQ(tl_fetch_first_compare(
83                      zh, "snippet", yaz_oid_recsyn_xml,
84                      "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
85                      "<root>\n"
86                      "  <record xmlns=\"http://www.indexdata.com/zebra/\">\n"
87                      "  <snippet name=\"title\" type=\"w\">How to program a <s>computer</s></snippet>\n"
88                      "</record>\n"
89                      "  <title>How to program a computer</title>\n"
90                      "</root>\n"),
91                  ZEBRA_OK);
92
93     YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
94
95     YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));
96     YAZ_CHECK(tl_query_x(zh, "@attr 1=4 computer", 0, 121));
97     zebra_close(zh);
98
99
100     /* testing XMLREADER input with ELEMENT stylesheet */
101     zh = index_some(zs, "dom.dom-config-one.xml", "marc-one.xml");
102     YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 1));
103     YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
104     YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));
105     YAZ_CHECK(tl_query_x(zh, "@attr 1=4 computer", 0, 121));
106     zebra_close(zh);
107
108     /* testing MARC input with ELEMENT stylesheet */
109     zh = index_some(zs, "dom.dom-config-marc.xml", "marc-col.mrc");
110     YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 3));
111     YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
112     YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));
113     YAZ_CHECK(tl_query_x(zh, "@attr 1=4 computer", 0, 121));
114     zebra_close(zh);
115
116     /* testing XMLREADER input with ELEMENT stylesheet and skipped records */
117     zh = index_some(zs, "dom.dom-config-skipped.xml", "marc-col.xml");
118     YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 1));
119     YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 0));
120     YAZ_CHECK(tl_query(zh, "@attr 1=control 11224467", 1));
121     YAZ_CHECK(tl_query(zh, "@attr 1=control 73090924", 0));
122
123     /* testing XMLREADER input with type attributes (insert,delete,..) */
124     zh = index_some(zs, "dom.dom-config-del.xml", "del-col.xml");
125     YAZ_CHECK(tl_query(zh, "@attr 1=title a", 1));
126     YAZ_CHECK(tl_query(zh, "@attr 1=title 1", 0));
127     YAZ_CHECK(tl_query(zh, "@attr 1=title 2", 0));
128     YAZ_CHECK(tl_query(zh, "@attr 1=title 3", 1));
129     YAZ_CHECK(tl_query(zh, "@attr 1=title b", 1));
130
131     zh = index_some(zs, "dom.gutenberg.xml", "gutenberg-sample.xml");
132     YAZ_CHECK(tl_query(zh, "oscar", 1));
133
134     YAZ_CHECK_EQ(tl_fetch_first_compare(
135                      zh, "zebra::snippet", yaz_oid_recsyn_xml,
136                      "<record xmlns=\"http://www.indexdata.com/zebra/\">\n"
137                      "  <snippet name=\"any\" type=\"w\" fields=\"title\">"
138                      "Selected Prose of <s>Oscar</s> Wilde"
139                      "</snippet>\n"
140                      "  <snippet name=\"any\" type=\"w\" fields=\"creator\">"
141                      "Wilde, <s>Oscar</s>, 1854-1900"
142                      "</snippet>\n"
143                      "</record>"),
144                  ZEBRA_OK);
145
146     zebra_close(zh);
147
148
149     YAZ_CHECK(tl_close_down(0, zs));
150 }
151
152 TL_MAIN
153
154 /*
155  * Local variables:
156  * c-basic-offset: 4
157  * c-file-style: "Stroustrup"
158  * indent-tabs-mode: nil
159  * End:
160  * vim: shiftwidth=4 tabstop=8 expandtab
161  */
162