Put local variables footer in all c, h files.
[idzebra-moved-to-github.git] / test / xpath / xpath4.c
1 /* $Id: xpath4.c,v 1.6 2006-05-10 08:13:41 adam Exp $
2    Copyright (C) 1995-2005
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 "../api/testlib.h"
24
25 /** xpath4.c - Attributes */
26
27 const char *myrec[] = {
28     "<record> \n"
29     "  <title>foo</title> \n"
30     "  <title>bar</title> \n"
31     "  <author>gryf</author> \n"
32     "</record> \n",
33     
34     "<record> \n"
35     "  <title>foo bar</title> \n"
36     "  <author>gryf</author> \n"
37     "</record> \n",
38    
39     "<record> \n"
40     "  <title lang=en>foo gryf</title> \n"
41     "  <author>grunt</author> \n"
42     "</record> \n",
43   
44     "<record> \n"
45     "  <title lang=da>foo grunt</title> \n"
46     "  <value>bar</value> \n"
47     "</record> \n",
48  
49     "<record> \n"
50     "  <title lang=en>double english</title> \n"
51     "  <title lang=da>double danish</title> \n"
52     "  <author>grunt</author> \n"
53     "</record> \n",
54
55     "<record> \n"
56     "  <title>hamlet</title> \n"
57     "  <author>foo bar grunt grunt grunt</author> \n"
58     "</record> \n",
59
60     "<record> \n"
61     "  before \n"
62     "  <nested> \n"
63     "     early \n"
64     "     <nested> \n"
65     "        middle \n"
66     "     </nested> \n"
67     "     late \n"
68     "  </nested> \n"
69     "  after \n"
70     "</record> \n",
71
72     "<record> \n"
73     "  before \n"
74     "  <nestattr level=outer> \n"
75     "     early \n"
76     "     <nestattr level=inner> \n"
77     "        middle \n"
78     "     </nestattr> \n"
79     "     late \n"
80     "  </nestattr> \n"
81     "  after \n"
82     "</record> \n",
83     0};
84
85
86 static void tst(int argc, char **argv)
87 {
88     ZebraService zs = tl_start_up(0, argc, argv);
89     ZebraHandle zh = zebra_open(zs, 0);
90
91 #if 0
92     yaz_log_init_level( yaz_log_mask_str_x("xpath4,rsbetween", LOG_DEFAULT_LEVEL));
93 #endif
94
95     YAZ_CHECK(tl_init_data(zh, myrec));
96
97     YAZ_CHECK(tl_query(zh, "@attr 1=/record/title foo",4));
98     YAZ_CHECK(tl_query(zh, "@attr 1=/record/title bar",2));
99     YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='da'] foo",1));
100     YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='en'] foo",1));
101
102     YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='en'] english",1)); 
103     YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='da'] english",0)); 
104     YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='da'] danish",1));  
105     YAZ_CHECK(tl_query(zh, "@attr 1=/record/title[@lang='en'] danish",0));  
106
107     YAZ_CHECK(tl_query(zh, "@attr 1=/record/title @and foo bar",2));
108     /* The previous one returns two hits, as the and applies to the whole
109     record, so it matches <title>foo</title><title>bar</title>
110     This might not have to be like that, but currently that is what
111     zebra does.  */
112     YAZ_CHECK(tl_query(zh, "@and @attr 1=/record/title foo @attr 1=/record/title bar ",2));
113
114     /* check we get all the occureences for 'grunt' */
115     /* this can only be seen in the log, with debugs on. bug #202 */
116     YAZ_CHECK(tl_query(zh, "@attr 1=/record/author grunt",3));
117
118     /* check nested tags */
119     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nested before",0));
120     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nested early",1));
121     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nested middle",1));
122     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nested late",1));
123     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nested after",0));
124
125     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nested/nested before",0));
126     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nested/nested early",0));
127     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nested/nested middle",1));
128     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nested/nested late",0));
129     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nested/nested after",0));
130
131     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr[@level='outer'] before",0));
132     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr[@level='outer'] early",1));
133     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr[@level='outer'] middle",1));
134     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr[@level='outer'] late",1));
135     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr[@level='outer'] after",0));
136
137     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr[@level='inner'] before",0));
138     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr[@level='inner'] early",0));
139     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr[@level='inner'] middle",0));
140     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr[@level='inner'] late",0));
141     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr[@level='inner'] after",0));
142
143     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr/nestattr[@level='inner'] before",0));
144     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr/nestattr[@level='inner'] early",0));
145     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr/nestattr[@level='inner'] middle",1));
146     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr/nestattr[@level='inner'] late",0));
147     YAZ_CHECK(tl_query(zh, "@attr 1=/record/nestattr/nestattr[@level='inner'] after",0));
148
149     YAZ_CHECK(tl_close_down(zh, zs));
150 }
151
152 TL_MAIN
153 /*
154  * Local variables:
155  * c-basic-offset: 4
156  * indent-tabs-mode: nil
157  * End:
158  * vim: shiftwidth=4 tabstop=8 expandtab
159  */
160