Refactored more stuff into testlib, cleaned up the tests.
[idzebra-moved-to-github.git] / test / api / testlib.h
1 /* $Id: testlib.h,v 1.3 2004-10-29 13:02:39 heikki Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
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 /** testlib - utilities for the api tests */
24
25 #include <stdlib.h>
26 #include <yaz/log.h>
27 #include <yaz/pquery.h>
28 #include <idzebra/api.h>
29
30
31
32 /** 
33  * start_up : Does all the usual start functions
34  *    - nmem_init
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
39  */
40 ZebraService start_up(char *cfgname, int argc, char **argv);
41
42 /** 
43  * start_log: open a log file 
44  */
45 /*    FIXME - parse command line arguments to set log levels etc */
46 void start_log(int argc, char **argv);
47
48 /** 
49  * start_service - do a zebra_start with a decent config name 
50  * Takes care of checking the environment for srcdir (as needed by distcheck)
51  * and uses that if need be. 
52  * The name defaults to zebra.cfg, if null or emtpy
53  */
54 ZebraService start_service(char *cfgname);
55
56
57 /** 
58  * close_down closes it all down
59  * Does a zebra_close on zh, if not null.
60  * Does a zebra_stop on zs, if not null 
61  * Writes a log message, OK if retcode is zero, error if not
62  * closes down nmem and xmalloc
63  * returns the retcode, for use in return or exit in main()
64  */
65 int close_down(ZebraHandle zh, ZebraService zs, int retcode);
66
67 /** inits the database and inserts test data */
68 void init_data( ZebraHandle zh, const char **recs);
69
70
71 /**
72  * do_query does a simple query, and checks that the number of hits matches
73  */
74 int do_query(int lineno, ZebraHandle zh, char *query, int exphits);
75
76
77 /** 
78  * ranking_query makes a query, checks number of hits, and for 
79  * the first hit, that it contains the given string, and that it 
80  * gets the right score
81  */
82 void ranking_query(int lineno, ZebraHandle zh, char *query, 
83           int exphits, char *firstrec, int firstscore );
84