1 /* $Id: xpath4.c,v 1.4 2005-09-13 11:51:11 adam Exp $
2 Copyright (C) 1995-2005
5 This file is part of the Zebra server.
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
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
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
23 #include "../api/testlib.h"
25 /** xpath4.c - Attributes */
27 const char *myrec[] = {
29 " <title>foo</title> \n"
30 " <title>bar</title> \n"
31 " <author>gryf</author> \n"
35 " <title>foo bar</title> \n"
36 " <author>gryf</author> \n"
40 " <title lang=en>foo gryf</title> \n"
41 " <author>grunt</author> \n"
45 " <title lang=da>foo grunt</title> \n"
46 " <value>bar</value> \n"
50 " <title lang=en>double english</title> \n"
51 " <title lang=da>double danish</title> \n"
52 " <author>grunt</author> \n"
56 " <title>hamlet</title> \n"
57 " <author>foo bar grunt grunt grunt</author> \n"
74 " <nestattr level=outer> \n"
76 " <nestattr level=inner> \n"
86 int main(int argc, char **argv)
88 ZebraService zs = start_up(0, argc, argv);
89 ZebraHandle zh = zebra_open(zs, 0);
92 yaz_log_init_level( yaz_log_mask_str_x("xpath4,rsbetween", LOG_DEFAULT_LEVEL));
97 #define q(qry,hits) do_query(__LINE__,zh,qry,hits)
99 q("@attr 1=/record/title foo",4);
100 q("@attr 1=/record/title bar",2);
101 q("@attr 1=/record/title[@lang='da'] foo",1);
102 q("@attr 1=/record/title[@lang='en'] foo",1);
104 q("@attr 1=/record/title[@lang='en'] english",1);
105 q("@attr 1=/record/title[@lang='da'] english",0);
106 q("@attr 1=/record/title[@lang='da'] danish",1);
107 q("@attr 1=/record/title[@lang='en'] danish",0);
109 q("@attr 1=/record/title @and foo bar",2);
110 /* The previous one returns two hits, as the and applies to the whole
111 record, so it matches <title>foo</title><title>bar</title>
112 This might not have to be like that, but currently that is what
114 q("@and @attr 1=/record/title foo @attr 1=/record/title bar ",2);
116 /* check we get all the occureences for 'grunt' */
117 /* this can only be seen in the log, with debugs on. bug #202 */
118 q("@attr 1=/record/author grunt",3);
120 /* check nested tags */
121 q("@attr 1=/record/nested before",0);
122 q("@attr 1=/record/nested early",1);
123 q("@attr 1=/record/nested middle",1);
124 q("@attr 1=/record/nested late",1);
125 q("@attr 1=/record/nested after",0);
127 q("@attr 1=/record/nested/nested before",0);
128 q("@attr 1=/record/nested/nested early",0);
129 q("@attr 1=/record/nested/nested middle",1);
130 q("@attr 1=/record/nested/nested late",0);
131 q("@attr 1=/record/nested/nested after",0);
133 q("@attr 1=/record/nestattr[@level='outer'] before",0);
134 q("@attr 1=/record/nestattr[@level='outer'] early",1);
135 q("@attr 1=/record/nestattr[@level='outer'] middle",1);
136 q("@attr 1=/record/nestattr[@level='outer'] late",1);
137 q("@attr 1=/record/nestattr[@level='outer'] after",0);
139 q("@attr 1=/record/nestattr[@level='inner'] before",0);
140 q("@attr 1=/record/nestattr[@level='inner'] early",0);
141 q("@attr 1=/record/nestattr[@level='inner'] middle",0);
142 q("@attr 1=/record/nestattr[@level='inner'] late",0);
143 q("@attr 1=/record/nestattr[@level='inner'] after",0);
145 q("@attr 1=/record/nestattr/nestattr[@level='inner'] before",0);
146 q("@attr 1=/record/nestattr/nestattr[@level='inner'] early",0);
147 q("@attr 1=/record/nestattr/nestattr[@level='inner'] middle",1);
148 q("@attr 1=/record/nestattr/nestattr[@level='inner'] late",0);
149 q("@attr 1=/record/nestattr/nestattr[@level='inner'] after",0);
151 return close_down(zh, zs, 0);