2007.
[idzebra-moved-to-github.git] / test / xpath / xpath1.c
1 /* $Id: xpath1.c,v 1.9 2007-01-15 15:10:25 adam Exp $
2    Copyright (C) 1995-2007
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 this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21 */
22
23 #include "../api/testlib.h"
24
25 /** xpath1.c - index a simple sgml record and search in it */
26
27 static void tst(int argc, char **argv)
28 {
29     ZebraService zs;
30     ZebraHandle zh;
31     const char *myrec[] = {
32         "<sgml> \n"
33         "  before \n"
34         "  <tag x='v'> \n"
35         "    inside it\n"
36         "  </tag> \n"
37         "  after \n"
38         "</sgml> \n",
39         0};
40
41     zs = tl_start_up(0, argc, argv);
42     zh = zebra_open(zs, 0);
43     YAZ_CHECK(tl_init_data(zh, myrec));
44
45     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag before", 0));
46     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag inside", 1));
47     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag {inside it}", 1));
48     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag after", 0));
49
50     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/none after", 0));
51     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/none inside", 0));
52
53     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml before", 1));
54     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml inside", 1));
55     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml after", 1));
56
57     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag/@x v", 1));
58     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag/@x no", 0));
59     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag/@y v", 0));
60
61     YAZ_CHECK(tl_query(zh, "@attr 1=_XPATH_BEGIN @attr 4=3 tag/sgml/", 1));
62     YAZ_CHECK(tl_query(zh, "@attr 1=_XPATH_BEGIN @attr 4=3 sgml/", 1));
63     YAZ_CHECK(tl_query(zh, "@attr 1=_XPATH_BEGIN @attr 4=3 tag/", 0));
64
65     /* bug #617 */
66     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag @attr 2=103 dummy", 1));
67     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml @attr 2=103 dummy", 1));
68     YAZ_CHECK(tl_query(zh, "@attr 1=/tag @attr 2=103 dummy", 0));
69     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag/@x @attr 2=103 dummy", 1));
70     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag/@y @attr 2=103 dummy", 0));
71
72     YAZ_CHECK(tl_close_down(zh, zs));
73 }
74
75 TL_MAIN
76 /*
77  * Local variables:
78  * c-basic-offset: 4
79  * indent-tabs-mode: nil
80  * End:
81  * vim: shiftwidth=4 tabstop=8 expandtab
82  */
83