Omit CVS Id. Update copyright year.
[idzebra-moved-to-github.git] / test / xslt / dom1.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1995-2008 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 #include <yaz/test.h>
21 #include "testlib.h"
22
23
24 void index_more(ZebraHandle zh, const char *filter, const char *file)
25 {
26     char path[256];
27     char profile_path[256];
28
29     sprintf(profile_path, "%.80s:%.80s/../../tab", 
30             tl_get_srcdir(), tl_get_srcdir());
31     zebra_set_resource(zh, "profilePath", profile_path);
32
33     zebra_set_resource(zh, "recordType", filter);
34
35     YAZ_CHECK(zebra_begin_trans(zh, 1) == ZEBRA_OK);
36     sprintf(path, "%.80s/%.80s", tl_get_srcdir(), file);
37
38     YAZ_CHECK(zebra_repository_update(zh, path) == ZEBRA_OK);
39     YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK);
40     zebra_commit(zh);
41 }
42
43 ZebraHandle index_some(ZebraService zs,
44                        const char *filter, const char *file)
45 {
46     ZebraHandle zh = zebra_open(zs, 0);
47
48     tl_check_filter(zs, "dom");
49
50     YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
51
52     zebra_init(zh);
53
54     index_more(zh, filter, file);
55     return zh;
56 }
57
58 void tst(int argc, char **argv)
59 {
60     ZebraHandle zh;
61     
62     ZebraService zs = tl_start_up(0, argc, argv);
63
64     zh = index_some(zs, "dom.bad.xml", "marc-col.xml");
65     zebra_close(zh);
66
67    
68     /* testing XMLREADER input with PI stylesheet */ 
69     zh = index_some(zs, "dom.dom-config-col.xml", "marc-col.xml");
70     YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 3));
71     YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
72     YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));
73     YAZ_CHECK(tl_query_x(zh, "@attr 1=4 computer", 0, 121));
74     zebra_close(zh);
75
76     /* testing XMLREADER input with ELEMENT stylesheet */ 
77     zh = index_some(zs, "dom.dom-config-one.xml", "marc-one.xml");
78     YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 1));
79     YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
80     YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));
81     YAZ_CHECK(tl_query_x(zh, "@attr 1=4 computer", 0, 121));
82     zebra_close(zh);
83
84     /* testing MARC input with ELEMENT stylesheet */ 
85     zh = index_some(zs, "dom.dom-config-marc.xml", "marc-col.mrc");
86     YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 3));
87     YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 1));
88     YAZ_CHECK(tl_query_x(zh, "@attr 1=titl computer", 0, 114));
89     YAZ_CHECK(tl_query_x(zh, "@attr 1=4 computer", 0, 121));
90     zebra_close(zh);
91
92     /* testing XMLREADER input with ELEMENT stylesheet and skipped records */ 
93     zh = index_some(zs, "dom.dom-config-skipped.xml", "marc-col.xml");
94     YAZ_CHECK(tl_query(zh, "@attr 1=title computer", 1));
95     YAZ_CHECK(tl_query(zh, "@attr 1=control 11224466", 0));
96     YAZ_CHECK(tl_query(zh, "@attr 1=control 11224467", 1));
97     YAZ_CHECK(tl_query(zh, "@attr 1=control 73090924", 0));
98
99     /* testing XMLREADER input with type attributes (insert,delete,..) */ 
100     zh = index_some(zs, "dom.dom-config-del.xml", "del-col.xml");
101     YAZ_CHECK(tl_query(zh, "@attr 1=title a", 1));
102     YAZ_CHECK(tl_query(zh, "@attr 1=title 1", 0));
103     YAZ_CHECK(tl_query(zh, "@attr 1=title 2", 0));
104     YAZ_CHECK(tl_query(zh, "@attr 1=title 3", 1));
105     YAZ_CHECK(tl_query(zh, "@attr 1=title b", 1));
106
107     zebra_close(zh);
108
109
110     YAZ_CHECK(tl_close_down(0, zs));
111 }
112
113 TL_MAIN
114
115 /*
116  * Local variables:
117  * c-basic-offset: 4
118  * indent-tabs-mode: nil
119  * End:
120  * vim: shiftwidth=4 tabstop=8 expandtab
121  */
122