1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 Index Data
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
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
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
20 /** testlib - utilities for the api tests */
23 #include <yaz/yconfig.h>
24 #include <yaz/pquery.h>
26 #include <idzebra/api.h>
28 #include <yaz/oid_db.h>
31 * tl_start_up : Does all the usual start functions
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
38 ZebraService tl_start_up(char *cfgname, int argc, char **argv);
41 * get_srcdir : returns the source dir. Most often ".", but when
42 * making distcheck, some other dir
44 const char *tl_get_srcdir(void);
47 * start_log: open a log file
49 /* FIXME - parse command line arguments to set log levels etc */
50 void tl_start_log(int argc, char **argv);
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
58 ZebraService tl_zebra_start(const char *cfgname);
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()
68 int tl_close_down(ZebraHandle zh, ZebraService zs
69 ) ZEBRA_GCC_ATTR((warn_unused_result));
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));
76 * tl_query does a simple query, and checks that the number of hits matches
78 int tl_query(ZebraHandle zh, const char *query, zint exphits
79 ) ZEBRA_GCC_ATTR((warn_unused_result));
83 * tl_query does a simple query, and checks that error is what is expected
85 int tl_query_x(ZebraHandle zh, const char *query, zint exphits,
87 ) ZEBRA_GCC_ATTR((warn_unused_result));
90 * tl_scan is a utility for scan testing
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));
98 int tl_sort(ZebraHandle zh, const char *query, zint hits, zint *exp
99 ) ZEBRA_GCC_ATTR((warn_unused_result));
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
106 int tl_ranking_query(ZebraHandle zh, char *query,
107 int exphits, char *firstrec, int firstscore
108 ) ZEBRA_GCC_ATTR((warn_unused_result));
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)
114 int tl_meta_query(ZebraHandle zh, char *query, int exphits,
116 ) ZEBRA_GCC_ATTR((warn_unused_result));
119 * if filter given by name does not exist, exit nicely but warn in log
121 void tl_check_filter(ZebraService zs, const char *name);
123 ZEBRA_RES tl_fetch_first_compare(ZebraHandle zh,
124 const char *element_set,
125 const Odr_oid *format, const char *cmp_rec);
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);
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; }
140 * c-file-style: "Stroustrup"
141 * indent-tabs-mode: nil
143 * vim: shiftwidth=4 tabstop=8 expandtab