Put local variables footer in all c, h files.
[idzebra-moved-to-github.git] / test / api / t5.c
1 /* $Id: t5.c,v 1.16 2006-05-10 08:13:35 adam Exp $
2    Copyright (C) 1995-2005
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 Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23 /** t5.c: proximity searches */
24 #include <yaz/test.h>
25 #include "testlib.h"
26
27 const char *myrec[] = {
28         "<gils>\n<title>My title</title>\n</gils>\n",
29         "<gils>\n<title>My x title</title>\n</gils>\n",
30         "<gils>\n<title>My title x</title>\n</gils>\n" ,
31         0} ;
32         
33 static void tst(int argc, char **argv)
34 {
35     ZebraService zs = tl_start_up(0, argc, argv);
36     ZebraHandle zh = zebra_open(zs, 0);
37
38     YAZ_CHECK(tl_init_data(zh, myrec));
39
40     /* phrase searches */
41     YAZ_CHECK(tl_query(zh, "@attr 1=4 my", 3));
42     YAZ_CHECK(tl_query(zh, "@attr 1=4 {my x}", 1));
43     YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=1 {my x}", 1));
44     YAZ_CHECK(tl_query(zh, "@attr 1=4 {my x}", 1));
45     YAZ_CHECK(tl_query(zh, "@attr 1=4 {x my}", 0));
46     YAZ_CHECK(tl_query(zh, "@attr 1=4 {my x title}", 1));
47     YAZ_CHECK(tl_query(zh, "@attr 1=4 {my title}", 2));
48
49     /* and-list searches */
50     YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {x my}", 2));
51     YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {my x}", 2));
52     YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {my my}", 3));
53     YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=6 {e x}", 0));
54
55     /* or-list searches */
56     YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {x my}", 3));
57     YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {my x}", 3));
58     YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {my my}", 3));
59     YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=105 {e x}", 2));
60     YAZ_CHECK(tl_query(zh, "@attr 1=4 @attr 4=106 {e x}", 2));
61
62     YAZ_CHECK(tl_query(zh, "@attr 1=4 @and x title", 2));
63
64     /* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */
65     YAZ_CHECK(tl_query(zh, "@prox 0 2 1 2 k 2 my x", 2));
66
67     /* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */
68     YAZ_CHECK(tl_query(zh, "@prox 0 2 1 2 k 2 x my", 0));
69
70     /* exl=0 distance=2 order=0 relation=2 (<=), known, unit=word */
71     YAZ_CHECK(tl_query(zh, "@prox 0 2 0 2 k 2 x my", 2));
72
73     /* exl=0 distance=2 order=0 relation=3 (=), known, unit=word */
74     YAZ_CHECK(tl_query(zh, "@prox 0 2 1 3 k 2 my x", 1));
75
76     /* exl=1 distance=2 order=0 relation=3 (=), known, unit=word */
77     YAZ_CHECK(tl_query(zh, "@prox 1 2 1 3 k 2 my x", 1));
78
79     /* provoke unsupported use attribute */
80     YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=1 x", 0, 114));
81     YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=6 x", 0, 114));
82     YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=105 x", 0, 114));
83     YAZ_CHECK(tl_query_x(zh, "@attr 1=999 @attr 4=109 123", 0, 114));
84     YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.840.10003.3.1 @attr 1=999 x",
85                          0, 114));
86     /* provoke unsupported attribute set */
87     YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=1 x", 0, 121));
88     YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=6 x", 0,
89                121));
90     YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=105 x", 0,
91                121));
92     YAZ_CHECK(tl_query_x(zh, "@attrset 1.2.8 @attr 1=999 @attr 4=109 123",
93                0, 121));
94
95     /* provoke unsupported relation */
96     YAZ_CHECK(tl_query_x(zh, "@attr 1=1016 @attr 2=6 x", 0, 117));
97     YAZ_CHECK(tl_query_x(zh, "@attr 1=1016 @attr 2=6 @attr 4=109 x", 0, 114));
98  
99     YAZ_CHECK(tl_close_down(zh, zs));
100 }
101
102 TL_MAIN
103
104 /*
105  * Local variables:
106  * c-basic-offset: 4
107  * indent-tabs-mode: nil
108  * End:
109  * vim: shiftwidth=4 tabstop=8 expandtab
110  */
111