Scan: allow preferred position > number + 1
[idzebra-moved-to-github.git] / test / api / test_scan.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2011 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 /** testing of scan */
21 #if HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24 #include "testlib.h"
25
26 const char *myrec[] = {
27         "<gils>\n<title>a b</title>\n</gils>\n",
28         "<gils>\n<title>c d</title>\n</gils>\n",
29         "<gils>\n<title>e f</title>\n</gils>\n" ,
30         0} ;
31         
32 static void tst(int argc, char **argv)
33 {
34     ZebraService zs = tl_start_up(0, argc, argv);
35     ZebraHandle zh = zebra_open(zs, 0);
36
37     YAZ_CHECK(zh);
38
39     YAZ_CHECK(tl_init_data(zh, myrec));
40
41     /*
42       int tl_scan
43       (
44       ZebraHandle zh, const char *query,
45       int pos, int num,
46       int exp_pos, int exp_num, int exp_partial,
47       const char **exp_entries
48       )
49     */
50
51
52     {
53         /* bad string use attrite, bug #647 */
54         YAZ_CHECK(tl_scan(zh, "@attr 1=bad 0", 1, 1, 1, 1, 0, 0));
55     }
56
57     {
58         /* bad numeric use attributes, bug #647 */
59         YAZ_CHECK(tl_scan(zh, "@attr 1=1234 0", 1, 1, 1, 1, 0, 0));
60     }
61
62     {
63         /* scan before. nothing must be returned */
64         const char *ent[] = { "a", 0 };
65         YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 1, 1, 1, 1, 0, ent));
66     }
67
68     {
69         /* scan after. nothing must be returned */
70         const char *ent[] = { 0 };
71         YAZ_CHECK(tl_scan(zh, "@attr 1=4 m", 1, 1, 1, 0, 1, ent));
72     }
73
74     {
75         const char *ent[] = { "a", 0 };
76         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", 1, 1, 1, 1, 0, ent));
77     }
78
79     {
80         const char *ent[] = { "b", "c", 0 };
81         YAZ_CHECK(tl_scan(zh, "@attr 1=4 aa", 1, 2, 1, 2, 0, ent));
82     }
83
84     {
85         const char *ent[] = { "b", "c", 0 };
86         YAZ_CHECK(tl_scan(zh, "@attr 1=4 aa", 1, 2, 1, 2, 0, ent));
87     }
88
89     {
90         const char *ent[] = { "e", "f", 0 };
91         YAZ_CHECK(tl_scan(zh, "@attr 1=4 e", 1, 3, 1, 2, 1, ent));
92     }
93
94     {
95         const char *ent[] = { "c", "d", 0 };
96         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -1, 2, -1, 2, 0, ent));
97     }
98
99     {
100         const char *ent[] = { "d", 0 };
101         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -2, 1, -2, 1, 0, ent));
102     }
103
104     {
105         const char *ent[] = { "f", 0 };
106         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -4, 1, -4, 1, 0, ent));
107     }
108
109     {
110         const char *ent[] = { "f", 0 };
111         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -5, 1, -5, 0, 1, ent));
112     }
113
114     {
115         const char *ent[] = { "d", "e", "f", 0 };
116         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -2, 3, -2, 3, 0, ent));
117     }
118
119     {
120         const char *ent[] = { "d", "e", "f", 0 };
121         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -2, 4, -2, 3, 1, ent));
122     }
123
124     {
125         const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 };
126         YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 2, 100, 1, 6, 1, ent));
127     }
128
129     {
130         const char *ent[] = { "b", "c", "d", "e", "f", 0 };
131         YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 0, 100, 0, 5, 1, ent));
132     }
133
134     {
135         const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 };
136         YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 10, 100, 1, 6, 1, ent));
137     }
138
139
140     {
141         const char *ent[] = { 0 };
142         YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 22, 10, 1, 0, 1, ent));
143     }
144
145     {
146         const char *ent[] = { "a", "b", "c", "d", 0 };
147         YAZ_CHECK(tl_scan(zh, "@attr 1=4 f", 6, 4, 6, 4, 0, ent));
148     }
149
150     {
151         const char *ent[] = { "a", "b", "c", "d", "e", 0 };
152         YAZ_CHECK(tl_scan(zh, "@attr 1=4 f", 6, 5, 6, 5, 0, ent));
153     }
154
155     {
156         const char *ent[] = { "a", "b", 0 };
157         YAZ_CHECK(tl_scan(zh, "@attr 1=4 c", 6, 5, 3, 2, 1, ent));
158     }
159
160     {
161         const char *ent[] = { "c", "d", "e", "f", 0 };
162         YAZ_CHECK(tl_scan(zh, "@attr 1=4 c", 1, 6, 1, 4, 1, ent));
163     }
164
165     {
166         const char *ent[] = { 0 };
167         YAZ_CHECK(tl_scan(zh, "@attr 1=4 z", -22, 10, -22, 0, 1, ent));
168     }
169
170     {
171         const char *ent[] = { "c", "d", 0 };
172
173         YAZ_CHECK(tl_query(zh, "@attr 1=4 c", 1));
174
175         /* must fail, because x is not a result set */
176         YAZ_CHECK(tl_scan(zh, "@attr 8=x @attr 1=4 a", 1, 3, 0, 0, 0, 0));
177
178         /* bug 1114 */
179         YAZ_CHECK(tl_scan(zh, "@attr 8=rsetname @attr 1=4 0",
180                           1, 20, 1, 2, 1, ent));
181
182     }
183     YAZ_CHECK(tl_close_down(zh, zs));
184 }
185
186 TL_MAIN
187
188 /*
189  * Local variables:
190  * c-basic-offset: 4
191  * c-file-style: "Stroustrup"
192  * indent-tabs-mode: nil
193  * End:
194  * vim: shiftwidth=4 tabstop=8 expandtab
195  */
196