d0cc7c91957057947d99f198a3858385dc3a5aec
[idzebra-moved-to-github.git] / test / api / t11.c
1 /* $Id: t11.c,v 1.7 2006-08-31 08:36:53 adam Exp $
2    Copyright (C) 1995-2006
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 /** testing of scan */
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(ZebraHandle zh, const char *query,
43       int pos, int num,
44       int exp_pos, int exp_num, int exp_partial,
45       const char **exp_entries)
46     */
47
48     if (1)
49     {
50         /* bad string use attrite, bug #647 */
51         const char *ent[] = { "a", 0 };
52         YAZ_CHECK(tl_scan(zh, "@attr 1=bad 0", 1, 1, 1, 1, 0, 0));
53     }
54     if (1)
55     {
56         /* bad numeric use attributes, bug #647 */
57         const char *ent[] = { "a", 0 };
58         YAZ_CHECK(tl_scan(zh, "@attr 1=1234 0", 1, 1, 1, 1, 0, 0));
59     }
60     if (1)
61     {
62         /* scan before. nothing must be returned */
63         const char *ent[] = { "a", 0 };
64         YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 1, 1, 1, 1, 0, ent));
65     }
66     if (1)
67     {
68         /* scan after. nothing must be returned */
69         const char *ent[] = { 0 };
70         YAZ_CHECK(tl_scan(zh, "@attr 1=4 m", 1, 1, 1, 0, 1, ent));
71     }
72     if (1)
73     {
74         const char *ent[] = { "a", 0 };
75         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", 1, 1, 1, 1, 0, ent));
76     }
77     if (1)
78     {
79         const char *ent[] = { "b", "c", 0 };
80         YAZ_CHECK(tl_scan(zh, "@attr 1=4 aa", 1, 2, 1, 2, 0, ent));
81     }
82     if (1)
83     {
84         const char *ent[] = { "b", "c", 0 };
85         YAZ_CHECK(tl_scan(zh, "@attr 1=4 aa", 1, 2, 1, 2, 0, ent));
86     }
87     if (1)
88     {
89         const char *ent[] = { "e", "f", 0 };
90         YAZ_CHECK(tl_scan(zh, "@attr 1=4 e", 1, 3, 1, 2, 1, ent));
91     }
92     if (1)
93     {
94         const char *ent[] = { "c", "d", 0 };
95         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -1, 2, -1, 2, 0, ent));
96     }
97     if (1)
98     {
99         const char *ent[] = { "d", 0 };
100         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -2, 1, -2, 1, 0, ent));
101     }
102     if (1)
103     {
104         const char *ent[] = { "f", 0 };
105         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -4, 1, -4, 1, 0, ent));
106     }
107     if (1)
108     {
109         const char *ent[] = { "f", 0 };
110         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -5, 1, -5, 0, 1, ent));
111     }
112     if (1)
113     {
114         const char *ent[] = { "d", "e", "f", 0 };
115         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -2, 3, -2, 3, 0, ent));
116     }
117     if (1)
118     {
119         const char *ent[] = { "d", "e", "f", 0 };
120         YAZ_CHECK(tl_scan(zh, "@attr 1=4 a", -2, 4, -2, 3, 1, ent));
121     }
122     if (1)
123     {
124         const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 };
125         YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 2, 100, 1, 6, 1, ent));
126     }
127     if (1)
128     {
129         const char *ent[] = { "b", "c", "d", "e", "f", 0 };
130         YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 0, 100, 0, 5, 1, ent));
131     }
132     if (1)
133     {
134         const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 };
135         YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 10, 100, 1, 6, 1, ent));
136     }
137     if (1)
138     {
139         const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 };
140         YAZ_CHECK(tl_scan(zh, "@attr 1=4 0", 22, 10, 1, 0, 1, ent));
141     }
142     if (1)
143     {
144         const char *ent[] = { 0 };
145         YAZ_CHECK(tl_scan(zh, "@attr 1=4 z", -22, 10, -22, 0, 1, ent));
146     }
147     YAZ_CHECK(tl_close_down(zh, zs));
148 }
149
150 TL_MAIN
151
152 /*
153  * Local variables:
154  * c-basic-offset: 4
155  * indent-tabs-mode: nil
156  * End:
157  * vim: shiftwidth=4 tabstop=8 expandtab
158  */
159