Happy new year
[idzebra-moved-to-github.git] / test / xpath / xpath1.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 /** xpath1.c - index a simple sgml record and search in it */
23
24 static void tst(int argc, char **argv)
25 {
26     ZebraService zs;
27     ZebraHandle zh;
28     const char *myrec[] = {
29         "<sgml> \n"
30         "  before \n"
31         "  <tag x='v'> \n"
32         "    inside it\n"
33         "  </tag> \n"
34         "  after \n"
35         "</sgml> \n",
36         0};
37
38     zs = tl_start_up(0, argc, argv);
39     zh = zebra_open(zs, 0);
40     YAZ_CHECK(tl_init_data(zh, myrec));
41
42     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag before", 0));
43     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag inside", 1));
44     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag {inside it}", 1));
45     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag after", 0));
46
47     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/none after", 0));
48     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/none inside", 0));
49
50     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml before", 1));
51     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml inside", 1));
52     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml after", 1));
53
54     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag/@x v", 1));
55     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag/@x no", 0));
56     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag/@y v", 0));
57
58     YAZ_CHECK(tl_query(zh, "@attr 1=_XPATH_BEGIN @attr 4=3 tag/sgml/", 1));
59     YAZ_CHECK(tl_query(zh, "@attr 1=_XPATH_BEGIN @attr 4=3 sgml/", 1));
60     YAZ_CHECK(tl_query(zh, "@attr 1=_XPATH_BEGIN @attr 4=3 tag/", 0));
61
62     /* bug #617 */
63     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag @attr 2=103 dummy", 1));
64     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml @attr 2=103 dummy", 1));
65     YAZ_CHECK(tl_query(zh, "@attr 1=/tag @attr 2=103 dummy", 0));
66     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag/@x @attr 2=103 dummy", 1));
67     YAZ_CHECK(tl_query(zh, "@attr 1=/sgml/tag/@y @attr 2=103 dummy", 0));
68
69     YAZ_CHECK(tl_close_down(zh, zs));
70 }
71
72 TL_MAIN
73 /*
74  * Local variables:
75  * c-basic-offset: 4
76  * indent-tabs-mode: nil
77  * End:
78  * vim: shiftwidth=4 tabstop=8 expandtab
79  */
80