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