875dcb54d3df82bec1df8d787eef1a59d35dbda4
[idzebra-moved-to-github.git] / test / api / testlib.h
1 /* This file is part of the Zebra server.
2    Copyright (C) 2004-2013 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 /** testlib - utilities for the api tests */
21
22 #include <stdlib.h>
23 #include <yaz/yconfig.h>
24 #include <yaz/pquery.h>
25 #include <yaz/log.h>
26 #include <idzebra/api.h>
27 #include <yaz/test.h>
28 #include <yaz/oid_db.h>
29
30 /**
31  * tl_start_up : Does all the usual start functions
32  *    - nmem_init
33  *    - build the name of logfile from argv[0], and open it
34  *      if no argv passed, do not open a log
35  *    - read zebra.cfg from env var srcdir if it exists; otherwise current dir
36  *      default to zebra.cfg, if no name is given
37  */
38 ZebraService tl_start_up(char *cfgname, int argc, char **argv);
39
40 /**
41  * get_srcdir : returns the source dir. Most often ".", but when
42  * making distcheck, some other dir
43  */
44 const char *tl_get_srcdir(void);
45
46 /**
47  * start_log: open a log file
48  */
49 /*    FIXME - parse command line arguments to set log levels etc */
50 void tl_start_log(int argc, char **argv);
51
52 /**
53  * tl_zebra_start - do a zebra_start with a decent config name
54  * Takes care of checking the environment for srcdir (as needed by distcheck)
55  * and uses that if need be.
56  * The name defaults to zebra.cfg, if null or emtpy
57  */
58 ZebraService tl_zebra_start(const char *cfgname);
59
60 /**
61  * close_down closes it all down
62  * Does a zebra_close on zh, if not null.
63  * Does a zebra_stop on zs, if not null
64  * Writes a log message, OK if retcode is zero, error if not
65  * closes down nmem and xmalloc
66  * returns the retcode, for use in return or exit in main()
67  */
68 int tl_close_down(ZebraHandle zh, ZebraService zs
69     ) ZEBRA_GCC_ATTR((warn_unused_result));
70
71 /** inits the database and inserts test data */
72 int tl_init_data(ZebraHandle zh, const char **recs
73     ) ZEBRA_GCC_ATTR((warn_unused_result));
74
75 /**
76  * tl_query does a simple query, and checks that the number of hits matches
77  */
78 int tl_query(ZebraHandle zh, const char *query, zint exphits
79     ) ZEBRA_GCC_ATTR((warn_unused_result));
80
81
82 /**
83  * tl_query does a simple query, and checks that error is what is expected
84  */
85 int tl_query_x(ZebraHandle zh, const char *query, zint exphits,
86                int experror
87     ) ZEBRA_GCC_ATTR((warn_unused_result));
88
89 /**
90  * tl_scan is a utility for scan testing
91  */
92 int tl_scan(ZebraHandle zh, const char *query,
93             int pos, int num,  /* input params */
94             int exp_pos, int exp_num,  int exp_partial, /* expected result */
95             const char **exp_entries  /* expected entries (or NULL) */
96     ) ZEBRA_GCC_ATTR((warn_unused_result));
97
98 int tl_sort(ZebraHandle zh, const char *query, zint hits, zint *exp
99     ) ZEBRA_GCC_ATTR((warn_unused_result));
100
101 /**
102  * ranking_query makes a query, checks number of hits, and for
103  * the first hit, that it contains the given string, and that it
104  * gets the right score
105  */
106 int tl_ranking_query(ZebraHandle zh, char *query,
107                      int exphits, char *firstrec, int firstscore
108     ) ZEBRA_GCC_ATTR((warn_unused_result));
109
110 /**
111  * meta_query makes a query, checks number of hits, and for
112  * checks that the all records in result set has the proper identifiers (ids)
113  */
114 int tl_meta_query(ZebraHandle zh, char *query, int exphits,
115                   zint *ids
116     ) ZEBRA_GCC_ATTR((warn_unused_result));
117
118 /**
119  * if filter given by name does not exist, exit nicely but warn in log
120  */
121 void tl_check_filter(ZebraService zs, const char *name);
122
123 ZEBRA_RES tl_fetch_first_compare(ZebraHandle zh,
124                                  const char *element_set,
125                                  const Odr_oid *format, const char *cmp_rec);
126
127 ZEBRA_RES tl_fetch(ZebraHandle zh,
128                    int position, const char *element_set,
129                    const Odr_oid * format, ODR odr,
130                    const char **rec_buf, size_t *rec_len);
131 ZEBRA_RES tl_fetch_compare(ZebraHandle zh,
132                            int position, const char *element_set,
133                            const Odr_oid *format, const char *cmp_rec);
134
135 #define TL_MAIN int main(int argc, char **argv) { \
136  YAZ_CHECK_INIT(argc, argv); YAZ_CHECK_LOG(); tst(argc, argv); YAZ_CHECK_TERM; }
137 /*
138  * Local variables:
139  * c-basic-offset: 4
140  * c-file-style: "Stroustrup"
141  * indent-tabs-mode: nil
142  * End:
143  * vim: shiftwidth=4 tabstop=8 expandtab
144  */
145