1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2011 Index Data
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
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
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
20 #include "../api/testlib.h"
22 /** xpath4.c - Attributes */
24 const char *myrec[] = {
26 " <title>foo</title> \n"
27 " <title>bar</title> \n"
28 " <author>gryf</author> \n"
32 " <title>foo bar</title> \n"
33 " <author>gryf</author> \n"
37 " <title lang=en>foo gryf</title> \n"
38 " <author>grunt</author> \n"
42 " <title lang=da>foo grunt</title> \n"
43 " <value>bar</value> \n"
47 " <title lang=en>double english</title> \n"
48 " <title lang=da>double danish</title> \n"
49 " <author>grunt</author> \n"
53 " <title>hamlet</title> \n"
54 " <author>foo bar grunt grunt grunt</author> \n"
71 " <nestattr level=outer> \n"
73 " <nestattr level=inner> \n"
83 static void tst(int argc, char **argv)
85 ZebraService zs = tl_start_up(0, argc, argv);
86 ZebraHandle zh = zebra_open(zs, 0);
89 yaz_log_init_level( yaz_log_mask_str_x("xpath4,rsbetween", LOG_DEFAULT_LEVEL));
92 YAZ_CHECK(tl_init_data(zh, myrec));
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));
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));
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
109 YAZ_CHECK(tl_query(zh, "@and @attr 1=/record/title foo @attr 1=/record/title bar ",2));
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));
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));
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));
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));
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));
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));
146 YAZ_CHECK(tl_close_down(zh, zs));
153 * c-file-style: "Stroustrup"
154 * indent-tabs-mode: nil
156 * vim: shiftwidth=4 tabstop=8 expandtab