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