Added xpath tests in test/api, disables test/xpath
[idzebra-moved-to-github.git] / test / api / xpath4.c
1
2
3 /* $Id: xpath4.c,v 1.1 2004-10-29 14:16:22 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>hamlet</title> \n"
54     "  <author>foo bar grunt</author> \n"
55     "</record> \n",
56
57     0};
58
59
60 int main(int argc, char **argv)
61 {
62     ZebraService zs = start_up("zebraxpath.cfg", argc, argv);
63     ZebraHandle zh = zebra_open (zs);
64     init_data(zh,myrec);
65
66 #define q(qry,hits) do_query(__LINE__,zh,qry,hits)
67
68     q("@attr 1=/record/title foo",4);
69     q("@attr 1=/record/title bar",2);
70     q("@attr 1=/record/title[@lang='da'] foo",1);
71     q("@attr 1=/record/title[@lang='en'] foo",1);
72     q("@attr 1=/record/title @and foo bar",2);
73     /* The last one returns two hits, as the and applies to the whole
74     record, so it matches <title>foo</title><title>bar</title>
75     This might not have to be like that, but currently that is what
76     zebra does.  */
77     q("@and @attr 1=/record/title foo @attr 1=/record/title bar ",2);
78     return close_down(zh, zs, 0);
79 }