02dfdfaab0a35a639219de1d830a2d0ef28dea09
[idzebra-moved-to-github.git] / test / api / safari1.c
1 /* $Id: safari1.c,v 1.6 2005-09-13 11:51:07 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"  /* first record */
30     "00024338 125060 1 any the\n"
31     "00024338 125060 2 any art\n"
32     "00024338 125060 3 any of\n",
33
34     "5678\n"  /* other record - same owner id */
35     "00024339 125060 1 any den\n"
36     "00024339 125060 2 any gamle\n"
37     "00024339 125060 3 any mand\n",
38
39     "5678\n"  /* same record chunk id as before .. */
40     "00024339 125060 1 any the\n"
41     "00024339 125060 2 any gamle\n"
42     "00024339 125060 3 any mand\n",
43
44     "1000\n"  /* separate record */
45     "00024339 125061 1 any the\n"
46     "00024339 125061 2 any gamle\n"
47     "00024339 125061 3 any mand\n",
48     
49     "1001\n"  /* separate record */
50     "00024340 125062 1 any the\n"
51     "00024340 125062 2 any gamle\n"
52     "00024340 125062 3 any mand\n",
53     
54     0
55 };
56
57 int main(int argc, char **argv)
58 {
59     zint ids[3];
60     zint limits[3];
61     ZebraService zs = start_up("safari.cfg", argc, argv);
62     
63     ZebraHandle zh = zebra_open(zs, 0);
64
65     init_data(zh, myrec);
66     do_query(__LINE__, zh, "@attr 1=any the", 3);
67     do_query(__LINE__, zh, "@attr 1=any {the art}", 1);
68     do_query(__LINE__, zh, "@attr 1=any {den gamle}", 1);
69     do_query(__LINE__, zh, "@attr 1=any {the of}", 0);
70
71     /* verify that we get these records exactly */
72     ids[0] = 24338;
73     ids[1] = 24339;
74     ids[2] = 24340;
75     meta_query(__LINE__, zh, "@attr 1=any the", 3, ids);
76
77     /* limit to 125061 */
78     limits[0] = 125061;
79     limits[1] = 0;
80     zebra_set_limit(zh, 0, limits);
81     ids[0] = 24339;
82     meta_query(__LINE__, zh, "@attr 1=any the", 1, ids);
83
84     /* limit to 125060, 125061 */
85     limits[0] = 125061;
86     limits[1] = 125060;
87     limits[2] = 0;
88     zebra_set_limit(zh, 0, limits);
89     ids[0] = 24338;
90     ids[1] = 24339;
91     meta_query(__LINE__, zh, "@attr 1=any the", 2, ids);
92
93     /* all except 125061 */
94     limits[0] = 125061;
95     limits[1] = 0;
96     zebra_set_limit(zh, 1, limits);
97
98     ids[0] = 24338;
99     ids[1] = 24340;
100     meta_query(__LINE__, zh, "@attr 1=any the", 2, ids);
101
102     /* no limit */
103     zebra_set_limit(zh, 1, 0);
104     do_query(__LINE__, zh, "@attr 1=any the", 3);
105
106     return close_down(zh, zs, 0);
107 }