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