1 /* $Id: testlib.h,v 1.24 2007-01-15 20:08:26 adam Exp $
2 Copyright (C) 1995-2007
5 This file is part of the Zebra server.
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
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
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
23 /** testlib - utilities for the api tests */
26 #include <yaz/yconfig.h>
27 #include <yaz/pquery.h>
29 #include <idzebra/api.h>
33 * tl_start_up : Does all the usual start functions
35 * - build the name of logfile from argv[0], and open it
36 * if no argv passed, do not open a log
37 * - read zebra.cfg from env var srcdir if it exists; otherwise current dir
38 * default to zebra.cfg, if no name is given
40 ZebraService tl_start_up(char *cfgname, int argc, char **argv);
43 * get_srcdir : returns the source dir. Most often ".", but when
44 * making distcheck, some other dir
46 const char *tl_get_srcdir(void);
49 * start_log: open a log file
51 /* FIXME - parse command line arguments to set log levels etc */
52 void tl_start_log(int argc, char **argv);
55 * tl_zebra_start - do a zebra_start with a decent config name
56 * Takes care of checking the environment for srcdir (as needed by distcheck)
57 * and uses that if need be.
58 * The name defaults to zebra.cfg, if null or emtpy
60 ZebraService tl_zebra_start(const char *cfgname);
63 * close_down closes it all down
64 * Does a zebra_close on zh, if not null.
65 * Does a zebra_stop on zs, if not null
66 * Writes a log message, OK if retcode is zero, error if not
67 * closes down nmem and xmalloc
68 * returns the retcode, for use in return or exit in main()
70 int tl_close_down(ZebraHandle zh, ZebraService zs
71 ) ZEBRA_GCC_ATTR((warn_unused_result));
73 /** inits the database and inserts test data */
74 int tl_init_data(ZebraHandle zh, const char **recs
75 ) ZEBRA_GCC_ATTR((warn_unused_result));
78 * tl_query does a simple query, and checks that the number of hits matches
80 int tl_query(ZebraHandle zh, const char *query, zint exphits
81 ) ZEBRA_GCC_ATTR((warn_unused_result));
85 * tl_query does a simple query, and checks that error is what is expected
87 int tl_query_x(ZebraHandle zh, const char *query, zint exphits,
89 ) ZEBRA_GCC_ATTR((warn_unused_result));
92 * tl_scan is a utility for scan testing
94 int tl_scan(ZebraHandle zh, const char *query,
95 int pos, int num, /* input params */
96 int exp_pos, int exp_num, int exp_partial, /* expected result */
97 const char **exp_entries /* expected entries (or NULL) */
98 ) ZEBRA_GCC_ATTR((warn_unused_result));
100 int tl_sort(ZebraHandle zh, const char *query, zint hits, zint *exp
101 ) ZEBRA_GCC_ATTR((warn_unused_result));
104 * ranking_query makes a query, checks number of hits, and for
105 * the first hit, that it contains the given string, and that it
106 * gets the right score
108 int tl_ranking_query(ZebraHandle zh, char *query,
109 int exphits, char *firstrec, int firstscore
110 ) ZEBRA_GCC_ATTR((warn_unused_result));
113 * meta_query makes a query, checks number of hits, and for
114 * checks that the all records in result set has the proper identifiers (ids)
116 int tl_meta_query(ZebraHandle zh, char *query, int exphits,
118 ) ZEBRA_GCC_ATTR((warn_unused_result));
121 * if filter given by name does not exist, exit nicely but warn in log
123 void tl_check_filter(ZebraService zs, const char *name);
125 #define TL_MAIN int main(int argc, char **argv) { \
126 YAZ_CHECK_INIT(argc, argv); YAZ_CHECK_LOG(); tst(argc, argv); YAZ_CHECK_TERM; }
130 * indent-tabs-mode: nil
132 * vim: shiftwidth=4 tabstop=8 expandtab