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