c014f851ab147a685a965ca47eb3d68cb19ed850
[idzebra-moved-to-github.git] / test / api / safari1.c
1 /* $Id: safari1.c,v 1.12 2006-07-04 14:10:32 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 /* safari1 - insert a few Safari records */
24
25 #include "testlib.h"
26
27 const char *myrec[] = 
28 {
29     "1234\n"  /* ID first record */
30     /* chunk owner seq idx term */
31     "00024338 125060 1 any the\n"
32     "00024338 125060 2 any art\n"
33     "00024338 125060 3 any mand\n"
34     ,
35     "5678\n"  /* other record - same owner id */
36     "00024339 125060 1 any den\n"
37     "00024339 125060 2 any gamle\n"
38     "00024339 125060 3 any mand\n"
39     ,
40     "5678\n"  /* same record chunk id as before .. */
41     "00024339 125060 1 any the\n"
42     "00024339 125060 2 any gamle\n"
43     "00024339 125060 3 any mand\n"
44     ,
45     "1000\n"  /* separate record */
46     "00024339 125061 1 any the\n"
47     "00024339 125061 2 any gamle\n"
48     "00024339 125061 3 any mand\n"
49     ,
50     "1001\n"  /* separate record */
51     "00024340 125062 1 any the\n"
52     "00024340 125062 1 any the\n" /* DUP KEY, bug #432 */
53     "00024340 125062 2 any old\n"
54     "00024340 125062 3 any mand\n"
55     ,
56     "1002\n"  /* segment testing record */
57     "00024341 125062 1 title a\n"
58     "00024341 125062 2 title b\n"
59
60     "00024341 125062 1024 title b\n"
61     "00024341 125062 1025 title c\n"
62     "00024341 125062 1026 title d\n"
63     "00024341 125062 1027 title e\n"
64     "00024341 125062 1028 title f\n"
65
66     "00024341 125062 2048 title g\n"
67     "00024341 125062 2049 title c\n"
68     ,
69
70     0
71 };
72
73 static void tst(int argc, char **argv)
74 {
75     zint ids[3];
76     zint limits[3];
77     ZebraService zs = tl_start_up("safari.cfg", argc, argv);
78     
79     ZebraHandle zh = zebra_open(zs, 0);
80
81     YAZ_CHECK(tl_init_data(zh, myrec));
82
83     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any the", 3));
84     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the art", 1));
85     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and den gamle", 0));
86     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the gamle", 1));
87     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the of", 0));
88
89     /* verify that we get these records exactly */
90     ids[0] = 24338;
91     ids[1] = 24339;
92     ids[2] = 24340;
93     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 3, ids));
94
95     /* limit to 125061 */
96     limits[0] = 125061;
97     limits[1] = 0;
98     zebra_set_limit(zh, 0, limits);
99     ids[0] = 24339;
100     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 1, ids));
101
102     /* limit to 125060, 125061 */
103     limits[0] = 125061;
104     limits[1] = 125060;
105     limits[2] = 0;
106     zebra_set_limit(zh, 0, limits);
107     ids[0] = 24338;
108     ids[1] = 24339;
109     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 2, ids));
110
111     /* all except 125062 */
112     limits[0] = 125062;
113     limits[1] = 0;
114     zebra_set_limit(zh, 1, limits);
115
116     ids[0] = 24338;
117     ids[1] = 24339;
118     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 2, ids));
119
120     /* no limit */
121     zebra_set_limit(zh, 1, 0);
122     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any mand", 3));
123
124     /* test segments */
125     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title a", 1));
126     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title b", 1));
127     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title c", 1));
128
129     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and a b", 1));
130     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and a c", 1));
131     
132     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and c d", 1));
133     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and b f", 1));
134     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and f g", 0));
135     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and g f", 0));
136     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and d g", 0));
137     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and g c", 0));
138     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and c g", 0));
139     YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=title @and c c", 1));
140
141     YAZ_CHECK(tl_close_down(zh, zs));
142 }
143
144 TL_MAIN
145 /*
146  * Local variables:
147  * c-basic-offset: 4
148  * indent-tabs-mode: nil
149  * End:
150  * vim: shiftwidth=4 tabstop=8 expandtab
151  */
152