charmap test using api
[idzebra-moved-to-github.git] / test / api / xpath4.c
1 /* $Id: xpath4.c,v 1.5 2004-12-02 11:28:20 adam Exp $
2    Copyright (C) 2003,2004
3    Index Data Aps
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23 #include "testlib.h"
24
25
26 /** xpath4.c - Attributes */
27
28 const char *myrec[] = {
29     "<record> \n"
30     "  <title>foo</title> \n"
31     "  <title>bar</title> \n"
32     "  <author>gryf</author> \n"
33     "</record> \n",
34     
35     "<record> \n"
36     "  <title>foo bar</title> \n"
37     "  <author>gryf</author> \n"
38     "</record> \n",
39    
40     "<record> \n"
41     "  <title lang=en>foo gryf</title> \n"
42     "  <author>grunt</author> \n"
43     "</record> \n",
44   
45     "<record> \n"
46     "  <title lang=da>foo grunt</title> \n"
47     "  <value>bar</value> \n"
48     "</record> \n",
49  
50     "<record> \n"
51     "  <title lang=en>double english</title> \n"
52     "  <title lang=da>double danish</title> \n"
53     "  <author>grunt</author> \n"
54     "</record> \n",
55
56     "<record> \n"
57     "  <title>hamlet</title> \n"
58     "  <author>foo bar grunt grunt grunt</author> \n"
59     "</record> \n",
60
61     "<record> \n"
62     "  before \n"
63     "  <nested> \n"
64     "     early \n"
65     "     <nested> \n"
66     "        middle \n"
67     "     </nested> \n"
68     "     late \n"
69     "  </nested> \n"
70     "  after \n"
71     "</record> \n",
72
73     "<record> \n"
74     "  before \n"
75     "  <nestattr level=outer> \n"
76     "     early \n"
77     "     <nestattr level=inner> \n"
78     "        middle \n"
79     "     </nestattr> \n"
80     "     late \n"
81     "  </nestattr> \n"
82     "  after \n"
83     "</record> \n",
84     0};
85
86
87 int main(int argc, char **argv)
88 {
89     ZebraService zs = start_up("zebraxpath.cfg", argc, argv);
90     ZebraHandle zh = zebra_open(zs);
91
92 #if 0
93     yaz_log_init_level( yaz_log_mask_str_x("xpath4,rsbetween", LOG_DEFAULT_LEVEL));
94 #endif
95
96     init_data(zh, myrec);
97
98 #define q(qry,hits) do_query(__LINE__,zh,qry,hits)
99
100     q("@attr 1=/record/title foo",4);
101     q("@attr 1=/record/title bar",2);
102     q("@attr 1=/record/title[@lang='da'] foo",1);
103     q("@attr 1=/record/title[@lang='en'] foo",1);
104
105     q("@attr 1=/record/title[@lang='en'] english",1); 
106     q("@attr 1=/record/title[@lang='da'] english",0); 
107     q("@attr 1=/record/title[@lang='da'] danish",1);  
108     q("@attr 1=/record/title[@lang='en'] danish",0);  
109
110     q("@attr 1=/record/title @and foo bar",2);
111     /* The previous one returns two hits, as the and applies to the whole
112     record, so it matches <title>foo</title><title>bar</title>
113     This might not have to be like that, but currently that is what
114     zebra does.  */
115     q("@and @attr 1=/record/title foo @attr 1=/record/title bar ",2);
116
117     /* check we get all the occureences for 'grunt' */
118     /* this can only be seen in the log, with debugs on. bug #202 */
119     q("@attr 1=/record/author grunt",3);
120
121     /* check nested tags */
122     q("@attr 1=/record/nested before",0);
123     q("@attr 1=/record/nested early",1);
124     q("@attr 1=/record/nested middle",1);
125     q("@attr 1=/record/nested late",1);
126     q("@attr 1=/record/nested after",0);
127
128     q("@attr 1=/record/nested/nested before",0);
129     q("@attr 1=/record/nested/nested early",0);
130     q("@attr 1=/record/nested/nested middle",1);
131     q("@attr 1=/record/nested/nested late",0);
132     q("@attr 1=/record/nested/nested after",0);
133
134     q("@attr 1=/record/nestattr[@level='outer'] before",0);
135     q("@attr 1=/record/nestattr[@level='outer'] early",1);
136     q("@attr 1=/record/nestattr[@level='outer'] middle",1);
137     q("@attr 1=/record/nestattr[@level='outer'] late",1);
138     q("@attr 1=/record/nestattr[@level='outer'] after",0);
139
140     q("@attr 1=/record/nestattr[@level='inner'] before",0);
141     q("@attr 1=/record/nestattr[@level='inner'] early",0);
142     q("@attr 1=/record/nestattr[@level='inner'] middle",0);
143     q("@attr 1=/record/nestattr[@level='inner'] late",0);
144     q("@attr 1=/record/nestattr[@level='inner'] after",0);
145
146     q("@attr 1=/record/nestattr/nestattr[@level='inner'] before",0);
147     q("@attr 1=/record/nestattr/nestattr[@level='inner'] early",0);
148     q("@attr 1=/record/nestattr/nestattr[@level='inner'] middle",1);
149     q("@attr 1=/record/nestattr/nestattr[@level='inner'] late",0);
150     q("@attr 1=/record/nestattr/nestattr[@level='inner'] after",0);
151
152     return close_down(zh, zs, 0);
153 }