From f84ad20a7a6a45d02da7f162fa6bb1137e79a07f Mon Sep 17 00:00:00 2001 From: Heikki Levanto Date: Fri, 29 Oct 2004 13:02:39 +0000 Subject: [PATCH] Refactored more stuff into testlib, cleaned up the tests. --- test/api/Makefile.am | 35 ++++++++++++++----------- test/api/t1.c | 21 +++------------ test/api/t10.c | 37 +++++++------------------- test/api/t2.c | 36 ++++++-------------------- test/api/t3.c | 42 ++++++++++-------------------- test/api/t4.c | 35 ++++++++----------------- test/api/t5.c | 61 ++++++++++++++++--------------------------- test/api/t6.c | 23 ++++------------- test/api/t7.c | 36 +++++++++----------------- test/api/t8.c | 33 +++++------------------- test/api/t9.c | 28 ++++---------------- test/api/testlib.c | 70 ++++++++++++++++++++++++++++++++++++++++++-------- test/api/testlib.h | 57 ++++++++++++++++++++++++++++++++-------- 13 files changed, 221 insertions(+), 293 deletions(-) diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 29e3fe6..3af503d 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -1,23 +1,28 @@ -# $Id: Makefile.am,v 1.21 2004-10-28 15:24:36 heikki Exp $ +# $Id: Makefile.am,v 1.22 2004-10-29 13:02:39 heikki Exp $ noinst_PROGRAMS = testclient -testclient_SOURCES = testclient.c +testclient_SOURCES = testclient.c -check_PROGRAMS = t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 +simpletests = t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 +xpathtests= xpath1 +#check_PROGRAMS = t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 xpath1 +check_PROGRAMS = ${simpletests} ${xpathtests} TESTS = $(check_PROGRAMS) -EXTRA_DIST=zebra.cfg zebra6.cfg zebra8.cfg - -t1_SOURCES = t1.c testlib.c -t2_SOURCES = t2.c testlib.c -t3_SOURCES = t3.c testlib.c -t4_SOURCES = t4.c testlib.c -t5_SOURCES = t5.c testlib.c -t6_SOURCES = t6.c testlib.c -t7_SOURCES = t7.c testlib.c -t8_SOURCES = t8.c testlib.c -t9_SOURCES = t9.c testlib.c -t10_SOURCES = t10.c testlib.c +EXTRA_DIST=zebra.cfg zebra6.cfg zebra8.cfg zebrazv.cfg + +t1_SOURCES = t1.c testlib.c testlib.h +t2_SOURCES = t2.c testlib.c testlib.h +t3_SOURCES = t3.c testlib.c testlib.h +t4_SOURCES = t4.c testlib.c testlib.h +t5_SOURCES = t5.c testlib.c testlib.h +t6_SOURCES = t6.c testlib.c testlib.h +t7_SOURCES = t7.c testlib.c testlib.h +t8_SOURCES = t8.c testlib.c testlib.h +t9_SOURCES = t9.c testlib.c testlib.h rankingrecords.h +t10_SOURCES = t10.c testlib.c testlib.h rankingrecords.h + +xpath1_SOURCES = xpath1.c testlib.c testlib.h AM_CPPFLAGS = -I$(top_srcdir)/include $(YAZINC) diff --git a/test/api/t1.c b/test/api/t1.c index b6e20c6..22cc182 100644 --- a/test/api/t1.c +++ b/test/api/t1.c @@ -1,4 +1,4 @@ -/* $Id: t1.c,v 1.9 2004-10-28 15:24:36 heikki Exp $ +/* $Id: t1.c,v 1.10 2004-10-29 13:02:39 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -22,26 +22,13 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA /** t1 - just start and stop */ -#include -#include -#include #include "testlib.h" int main(int argc, char **argv) { - ZebraService zs; - ZebraHandle zh; - - yaz_log_init_file("t1.log"); - nmem_init(); - zs = start_service(0); - zh = zebra_open (zs); + ZebraService zs = start_up(0, argc, argv); + ZebraHandle zh = zebra_open (zs); - zebra_close (zh); - zebra_stop (zs); - nmem_exit (); - xmalloc_trav ("x"); - logf(LOG_LOG,"================ All tests OK "); - exit (0); + return close_down(zh,zs,0); } diff --git a/test/api/t10.c b/test/api/t10.c index 636d539..0d2004f 100644 --- a/test/api/t10.c +++ b/test/api/t10.c @@ -1,4 +1,4 @@ -/* $Id: t10.c,v 1.2 2004-10-28 15:24:36 heikki Exp $ +/* $Id: t10.c,v 1.3 2004-10-29 13:02:39 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -22,15 +22,11 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA /** t10.c - test zv-rank */ -#include -#include -#include -#include #include "testlib.h" #include "rankingrecords.h" #define qry(zh,query,hits,string,score) \ - RankingQuery(__LINE__,(zh),(query),(hits),(string),(score)) + ranking_query(__LINE__,(zh),(query),(hits),(string),(score)) struct tst { char *schema; @@ -79,23 +75,13 @@ struct tst tests[] = { int main(int argc, char **argv) { int i; - ZebraService zs; - ZebraHandle zh; - - yaz_log_init_file("t10.log"); - /* yaz_log_init_level(LOG_ALL); */ - - nmem_init (); - - zs = start_service("zebrazv.cfg"); - assert(zs); - zh = zebra_open (zs); + ZebraService zs = start_up("zebrazv.cfg", argc, argv); + ZebraHandle zh = zebra_open (zs); init_data(zh, recs); - zebra_close(zh); - + yaz_log_init_level(LOG_ALL); for (i=0; tests[i].schema; i++) { zh = zebra_open (zs); @@ -103,21 +89,16 @@ int main(int argc, char **argv) zebra_set_resource(zh, "zvrank.weighting-scheme", tests[i].schema); logf(LOG_LOG,"============%d: %s ============", i,tests[i].schema); - RankingQuery( __LINE__, zh, "@attr 1=1016 @attr 2=102 the", + ranking_query( __LINE__, zh, "@attr 1=1016 @attr 2=102 the", 3, tests[i].hit1, tests[i].score1); - RankingQuery( __LINE__, zh, "@attr 1=1016 @attr 2=102 @or foo bar", + ranking_query( __LINE__, zh, "@attr 1=1016 @attr 2=102 @or foo bar", 3, tests[i].hit2, tests[i].score2); - RankingQuery( __LINE__, zh, + ranking_query( __LINE__, zh, "@attr 1=1016 @attr 2=102 @or @or the foo bar", 3, tests[i].hit3, tests[i].score3); zebra_close(zh); } - zebra_stop (zs); - - nmem_exit (); - xmalloc_trav ("x"); - logf(LOG_LOG,"============ ALL TESTS PASSED OK ============"); - exit(0); + return close_down(0,zs,0); } diff --git a/test/api/t2.c b/test/api/t2.c index 51f479f..d981787 100644 --- a/test/api/t2.c +++ b/test/api/t2.c @@ -1,4 +1,4 @@ -/* $Id: t2.c,v 1.13 2004-10-28 15:24:36 heikki Exp $ +/* $Id: t2.c,v 1.14 2004-10-29 13:02:39 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -20,41 +20,21 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include -#include -#include #include "testlib.h" -/* read zebra.cfg from env var srcdir if it exists; otherwise current dir */ - -int main(int argc, char **argv) -{ - ZebraService zs; - ZebraHandle zh; - const char *myrec[] = { +const char *myrec[] = { "\n" " My title\n" "\n", 0}; +int main(int argc, char **argv) +{ + ZebraService zs = start_up(0, argc, argv); + ZebraHandle zh = zebra_open (zs); - yaz_log_init_file("t2.log"); - - nmem_init (); - - zs = start_service(0); - zh = zebra_open (zs); init_data(zh,myrec); + do_query(__LINE__,zh, "@attr 1=4 my", 1); - Query(__LINE__,zh, "@attr 1=4 my", 1); - - zebra_end_trans (zh); - zebra_commit (zh); - zebra_close (zh); - zebra_stop (zs); - - nmem_exit (); - xmalloc_trav ("x"); - logf(LOG_LOG,"================ All tests OK "); - exit (0); + return close_down(zh,zs,0); } diff --git a/test/api/t3.c b/test/api/t3.c index adf8be1..5d7caa5 100644 --- a/test/api/t3.c +++ b/test/api/t3.c @@ -1,4 +1,4 @@ -/* $Id: t3.c,v 1.11 2004-10-28 15:24:36 heikki Exp $ +/* $Id: t3.c,v 1.12 2004-10-29 13:02:39 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -20,35 +20,24 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include -#include -#include +/* Creates a few result sets */ + #include "testlib.h" +const char *myrec[] ={ + "\n" + " My title\n" + "\n", + 0}; + int main(int argc, char **argv) { int i; - ZebraService zs; - ZebraHandle zh; - const char *myrec = - "\n" - " My title\n" - "\n"; - - yaz_log_init_file("t3.log"); - yaz_log_init_level(LOG_ALL); - - nmem_init (); - - zs = start_service(0); - zh = zebra_open (zs); - zebra_select_database(zh, "Default"); - zebra_init(zh); + ZebraService zs = start_up(0, argc, argv); + ZebraHandle zh = zebra_open (zs); - zebra_begin_trans (zh, 1); - zebra_add_record (zh, myrec, strlen(myrec)); - zebra_end_trans (zh); + init_data(zh,myrec); for (i = 0; i<4; i++) { @@ -86,11 +75,6 @@ int main(int argc, char **argv) odr_destroy (odr_output); } zebra_commit (zh); - zebra_close (zh); - zebra_stop (zs); - nmem_exit (); - xmalloc_trav ("x"); - logf(LOG_LOG,"================ All tests OK "); - exit (0); + return close_down(zh,zs,0); } diff --git a/test/api/t4.c b/test/api/t4.c index 4ee95db..b38a9a5 100644 --- a/test/api/t4.c +++ b/test/api/t4.c @@ -1,4 +1,4 @@ -/* $Id: t4.c,v 1.10 2004-10-28 15:24:36 heikki Exp $ +/* $Id: t4.c,v 1.11 2004-10-29 13:02:39 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -20,29 +20,22 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include -#include -#include +/* t4 - insert a small pile of records, search and fetch them */ + #include "testlib.h" - -int main(int argc, char **argv) -{ - int i; - ZebraService zs; - ZebraHandle zh; - const char *myrec[] = { +const char *myrec[] = { "\n" " My title\n" "\n", 0}; + +int main(int argc, char **argv) +{ + int i; + ZebraService zs = start_up(0, argc, argv);; + ZebraHandle zh = zebra_open (zs); - yaz_log_init_file("t4.log"); - - nmem_init (); - - zs = start_service(0); - zh = zebra_open (zs); init_data(zh,myrec); zebra_begin_trans (zh, 1); @@ -90,11 +83,5 @@ int main(int argc, char **argv) } zebra_commit (zh); - zebra_close (zh); - zebra_stop (zs); - - nmem_exit (); - xmalloc_trav ("x"); - logf(LOG_LOG,"================ All tests OK "); - exit (0); + return close_down(zh,zs,0); } diff --git a/test/api/t5.c b/test/api/t5.c index 6a483d5..11b0f69 100644 --- a/test/api/t5.c +++ b/test/api/t5.c @@ -1,4 +1,4 @@ -/* $Id: t5.c,v 1.8 2004-10-28 15:24:36 heikki Exp $ +/* $Id: t5.c,v 1.9 2004-10-29 13:02:39 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -20,62 +20,45 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include -#include -#include - +/** t5.c: proximity searches */ #include "testlib.h" - - -int main(int argc, char **argv) -{ - ZebraService zs; - ZebraHandle zh; - const char *myrec[] = { +const char *myrec[] = { "\nMy title\n\n", "\nMy x title\n\n", "\nMy title x\n\n" , - 0} - ; + 0} ; + - yaz_log_init_file("t5.log"); - yaz_log_init_level(LOG_ALL); +int main(int argc, char **argv) +{ + ZebraService zs = start_up(0, argc, argv); + ZebraHandle zh = zebra_open (zs); - nmem_init (); - - zs = start_service(0); - zh = zebra_open (zs); init_data(zh,myrec); - Query(__LINE__,zh, "@attr 1=4 my", 3); - Query(__LINE__,zh, "@attr 1=4 {my x}", 1); - Query(__LINE__,zh, "@attr 1=4 {my x}", 1); - Query(__LINE__,zh, "@attr 1=4 {x my}", 0); - Query(__LINE__,zh, "@attr 1=4 {my x title}", 1); - Query(__LINE__,zh, "@attr 1=4 {my title}", 2); - Query(__LINE__,zh, "@attr 1=4 @and x title", 2); + do_query(__LINE__,zh, "@attr 1=4 my", 3); + do_query(__LINE__,zh, "@attr 1=4 {my x}", 1); + do_query(__LINE__,zh, "@attr 1=4 {my x}", 1); + do_query(__LINE__,zh, "@attr 1=4 {x my}", 0); + do_query(__LINE__,zh, "@attr 1=4 {my x title}", 1); + do_query(__LINE__,zh, "@attr 1=4 {my title}", 2); + do_query(__LINE__,zh, "@attr 1=4 @and x title", 2); /* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */ - Query(__LINE__,zh, "@prox 0 2 1 2 k 2 my x", 2); + do_query(__LINE__,zh, "@prox 0 2 1 2 k 2 my x", 2); /* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */ - Query(__LINE__,zh, "@prox 0 2 1 2 k 2 x my", 0); + do_query(__LINE__,zh, "@prox 0 2 1 2 k 2 x my", 0); /* exl=0 distance=2 order=0 relation=2 (<=), known, unit=word */ - Query(__LINE__,zh, "@prox 0 2 0 2 k 2 x my", 2); + do_query(__LINE__,zh, "@prox 0 2 0 2 k 2 x my", 2); /* exl=0 distance=2 order=0 relation=3 (=), known, unit=word */ - Query(__LINE__,zh, "@prox 0 2 1 3 k 2 my x", 1); + do_query(__LINE__,zh, "@prox 0 2 1 3 k 2 my x", 1); /* exl=1 distance=2 order=0 relation=3 (=), known, unit=word */ - Query(__LINE__,zh, "@prox 1 2 1 3 k 2 my x", 1); - - zebra_close (zh); - zebra_stop (zs); + do_query(__LINE__,zh, "@prox 1 2 1 3 k 2 my x", 1); - nmem_exit (); - xmalloc_trav ("x"); - logf(LOG_LOG,"======== All tests OK"); - exit (0); + return close_down(zh,zs,0); } diff --git a/test/api/t6.c b/test/api/t6.c index 6052f7d..23f2cef 100644 --- a/test/api/t6.c +++ b/test/api/t6.c @@ -1,4 +1,4 @@ -/* $Id: t6.c,v 1.4 2004-10-28 15:24:36 heikki Exp $ +/* $Id: t6.c,v 1.5 2004-10-29 13:02:39 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -20,11 +20,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include - -#include -#include -#include +/** t6.c Insert a number of randomly generated words */ #include "testlib.h" @@ -32,17 +28,12 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA int main(int argc, char **argv) { int i; - ZebraService zs; - ZebraHandle zh; - - yaz_log_init_file("t6.log"); + ZebraService zs = start_up(0, argc, argv); + ZebraHandle zh = zebra_open (zs); - nmem_init (); srand(17); - zs = start_service(""); - zh = zebra_open(zs); zebra_select_database(zh, "Default"); zebra_init(zh); zebra_close(zh); @@ -74,10 +65,6 @@ int main(int argc, char **argv) zebra_end_trans (zh); zebra_close(zh); } - zebra_stop(zs); - nmem_exit (); - xmalloc_trav ("x"); - logf(LOG_LOG,"========= all tests OK"); - exit (0); + return close_down(0 /*zh*/ ,zs,0); } diff --git a/test/api/t7.c b/test/api/t7.c index 2378a6a..f943cbe 100644 --- a/test/api/t7.c +++ b/test/api/t7.c @@ -1,4 +1,4 @@ -/* $Id: t7.c,v 1.3 2004-10-28 15:24:36 heikki Exp $ +/* $Id: t7.c,v 1.4 2004-10-29 13:02:39 heikki Exp $ Copyright (C) 2004 Index Data Aps @@ -20,23 +20,23 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include -#include -#include -#include +/** t7.c sorting */ #include "testlib.h" +#include - -int main(int argc, char **argv) -{ - ZebraService zs; - ZebraHandle zh; - const char *recs[] = { +const char *recs[] = { "\n" " My title\n" "\n", 0}; + + +int main(int argc, char **argv) +{ + ZebraService zs = start_up(0, argc, argv); + ZebraHandle zh = zebra_open (zs); + const char *setname1="set1"; const char *setname2="set2"; const char *setname3="set3"; @@ -51,13 +51,6 @@ int main(int argc, char **argv) yaz_sort_spec (odr_output, "@attr 1=4 id"); int hits; - yaz_log_init_file("t7.log"); - - nmem_init (); - - zs = start_service(""); /* default to zebra.cfg */ - zh = zebra_open (zs); - init_data(zh,recs); @@ -90,11 +83,6 @@ int main(int argc, char **argv) odr_destroy (odr_output); zebra_commit (zh); - zebra_close (zh); - zebra_stop (zs); - nmem_exit (); - xmalloc_trav ("x"); - logf(LOG_LOG,"========= all tests OK"); - exit (0); + return close_down(zh,zs,0); } diff --git a/test/api/t8.c b/test/api/t8.c index aabf47a..df74fd6 100644 --- a/test/api/t8.c +++ b/test/api/t8.c @@ -1,4 +1,4 @@ -/* $Id: t8.c,v 1.4 2004-10-28 15:24:36 heikki Exp $ +/* $Id: t8.c,v 1.5 2004-10-29 13:02:39 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -20,15 +20,10 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* t8: test numeric attributes */ +/** t8: test numeric attributes */ -#include -#include -#include -#include #include "testlib.h" -#define LOGLEVEL LOG_ALL const char *recs[] = { @@ -66,21 +61,12 @@ const char *recs[] = { int main(int argc, char **argv) { - ZebraService zs; - ZebraHandle zh; - yaz_log_init_file("t8.log"); -#ifdef LOGLEVEL - yaz_log_init_level(LOGLEVEL); -#endif - - nmem_init (); - - zs = start_service("zebra8.cfg"); - zh = zebra_open (zs); + ZebraService zs = start_up("zebra8.cfg", argc, argv); + ZebraHandle zh = zebra_open (zs); init_data(zh, recs); -#define Q(q,n) Query(__LINE__,zh,q,n) +#define Q(q,n) do_query(__LINE__,zh,q,n) /* couple of simple queries just to see that we have indexed the stuff */ Q( "@attr 1=4 title",2 ); Q( "title",2 ); @@ -107,12 +93,5 @@ int main(int argc, char **argv) /* N=41 and N=49 get only rec2 */ Q( "@attr 2=3 @attr gils 1=2040 @attr 4=109 \"41 49\" ",1); - zebra_commit (zh); - zebra_close (zh); - zebra_stop (zs); - - nmem_exit (); - xmalloc_trav ("x"); - logf(LOG_LOG,"All tests OK"); - exit (0); + return close_down(zh,zs,0); } diff --git a/test/api/t9.c b/test/api/t9.c index 07d1f45..bd91356 100644 --- a/test/api/t9.c +++ b/test/api/t9.c @@ -1,4 +1,4 @@ -/* $Id: t9.c,v 1.2 2004-10-28 15:24:36 heikki Exp $ +/* $Id: t9.c,v 1.3 2004-10-29 13:02:39 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -22,33 +22,21 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA /** t9.c - test rank-1 */ -#include -#include -#include #include "testlib.h" #include "rankingrecords.h" #define qry(zh,query,hits,string,score) \ - RankingQuery(__LINE__,(zh),(query),(hits),(string),(score)) + ranking_query(__LINE__,(zh),(query),(hits),(string),(score)) int main(int argc, char **argv) { - ZebraService zs; - ZebraHandle zh; + ZebraService zs = start_up(0, argc, argv); + ZebraHandle zh = zebra_open (zs); - yaz_log_init_file("t9.log"); - /* yaz_log_init_level(LOG_ALL); */ - - nmem_init (); - - zs = start_service(""); /* default to zebra.cfg */ - zh = zebra_open (zs); init_data(zh, recs); - zebra_select_database(zh, "Default"); - qry( zh, "@attr 1=1016 @attr 2=102 the", 3, "first title", 872 ); @@ -61,11 +49,5 @@ int main(int argc, char **argv) 3, "third title", 895 ); - zebra_close (zh); - zebra_stop (zs); - - nmem_exit (); - xmalloc_trav ("x"); - logf(LOG_LOG,"============ ALL TESTS PASSED OK ============"); - exit(0); + return close_down(zh,zs,0); } diff --git a/test/api/testlib.c b/test/api/testlib.c index e66ba92..e3fe048 100644 --- a/test/api/testlib.c +++ b/test/api/testlib.c @@ -1,4 +1,4 @@ -/* $Id: testlib.c,v 1.2 2004-10-28 15:24:36 heikki Exp $ +/* $Id: testlib.c,v 1.3 2004-10-29 13:02:39 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -26,9 +26,37 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include +#include "testlib.h" +/** start_log: open a log file */ +/* FIXME - parse command line arguments to set log levels etc */ +void start_log(int argc, char **argv) +{ + char logname[2048]; + if (!argv) + return; + if (!argv[0]) + return; + sprintf(logname, "%s.log", argv[0]); + yaz_log_init_file(logname); +} + +/** + * start_up : do common start things, and a zebra_start + * - nmem_init + * - build the name of logfile from argv[0], and open it + * if no argv passed, do not open a log + * - read zebra.cfg from env var srcdir if it exists; otherwise current dir + * default to zebra.cfg, if no name is given + */ +ZebraService start_up(char *cfgname, int argc, char **argv) +{ + nmem_init(); + start_log(argc, argv); + return start_service(cfgname); +} -/* read zebra.cfg from env var srcdir if it exists; otherwise current dir */ +/** start_service - do a zebra_start with a decent config name */ ZebraService start_service(char *cfgname) { char cfg[256]; @@ -38,7 +66,6 @@ ZebraService start_service(char *cfgname) srcdir="."; if (!cfgname || ! *cfgname ) cfgname="zebra.cfg"; - /*sprintf(cfg, "%.200s%szebra.cfg", srcdir ? srcdir : "", srcdir ? "/" : ""); */ sprintf(cfg, "%.200s/%s",srcdir, cfgname); zs=zebra_start(cfg); @@ -51,6 +78,24 @@ ZebraService start_service(char *cfgname) return zs; } + +/** close_down closes down the zebra, logfile, nmem, xmalloc etc. logs an OK */ +int close_down(ZebraHandle zh, ZebraService zs, int retcode) +{ + if (zh) + zebra_close(zh); + if (zs) + zebra_stop(zs); + + if (retcode) + logf(LOG_LOG,"========= Exiting with return code %d", retcode); + else + logf(LOG_LOG,"========= All tests OK"); + nmem_exit(); + xmalloc_trav("x"); + return retcode; +} + /** inits the database and inserts test data */ void init_data( ZebraHandle zh, const char **recs) @@ -69,17 +114,20 @@ void init_data( ZebraHandle zh, const char **recs) printf(" Error %d %s\n",i,addinfo); exit(1); } - zebra_begin_trans (zh, 1); - for (i = 0; recs[i]; i++) - zebra_add_record (zh, recs[i], strlen(recs[i])); - zebra_end_trans (zh); - zebra_commit (zh); + if (recs) + { + zebra_begin_trans (zh, 1); + for (i = 0; recs[i]; i++) + zebra_add_record (zh, recs[i], strlen(recs[i])); + zebra_end_trans (zh); + zebra_commit (zh); + } } -int Query(int lineno, ZebraHandle zh, char *query, int exphits) +int do_query(int lineno, ZebraHandle zh, char *query, int exphits) { ODR odr; YAZ_PQF_Parser parser; @@ -120,7 +168,7 @@ int Query(int lineno, ZebraHandle zh, char *query, int exphits) * makes a query, checks number of hits, and for the first hit, that * it contains the given string, and that it gets the right score */ -void RankingQuery(int lineno, ZebraHandle zh, char *query, +void ranking_query(int lineno, ZebraHandle zh, char *query, int exphits, char *firstrec, int firstscore ) { ZebraRetrievalRecord retrievalRecord[10]; @@ -130,7 +178,7 @@ void RankingQuery(int lineno, ZebraHandle zh, char *query, int rc; int i; - hits=Query(lineno, zh, query, exphits); + hits=do_query(lineno, zh, query, exphits); for (i = 0; i<10; i++) retrievalRecord[i].position = i+1; diff --git a/test/api/testlib.h b/test/api/testlib.h index c8b928d..6a4c01d 100644 --- a/test/api/testlib.h +++ b/test/api/testlib.h @@ -1,4 +1,4 @@ -/* $Id: testlib.h,v 1.2 2004-10-28 15:24:36 heikki Exp $ +/* $Id: testlib.h,v 1.3 2004-10-29 13:02:39 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -22,26 +22,63 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA /** testlib - utilities for the api tests */ +#include #include #include #include -/** read zebra.cfg from env var srcdir if it exists; otherwise current dir */ -ZebraService start_service(char *cfgfile); -/** initialises the zebra base and inserts some test data in it */ +/** + * start_up : Does all the usual start functions + * - nmem_init + * - build the name of logfile from argv[0], and open it + * if no argv passed, do not open a log + * - read zebra.cfg from env var srcdir if it exists; otherwise current dir + * default to zebra.cfg, if no name is given + */ +ZebraService start_up(char *cfgname, int argc, char **argv); + +/** + * start_log: open a log file + */ +/* FIXME - parse command line arguments to set log levels etc */ +void start_log(int argc, char **argv); + +/** + * start_service - do a zebra_start with a decent config name + * Takes care of checking the environment for srcdir (as needed by distcheck) + * and uses that if need be. + * The name defaults to zebra.cfg, if null or emtpy + */ +ZebraService start_service(char *cfgname); + + +/** + * close_down closes it all down + * Does a zebra_close on zh, if not null. + * Does a zebra_stop on zs, if not null + * Writes a log message, OK if retcode is zero, error if not + * closes down nmem and xmalloc + * returns the retcode, for use in return or exit in main() + */ +int close_down(ZebraHandle zh, ZebraService zs, int retcode); + +/** inits the database and inserts test data */ void init_data( ZebraHandle zh, const char **recs); -/** makes a query, and compares the number of hits to the expected */ -void Query(int lineno, ZebraHandle zh, char *query, int exphits); +/** + * do_query does a simple query, and checks that the number of hits matches + */ +int do_query(int lineno, ZebraHandle zh, char *query, int exphits); /** - * makes a query, checks number of hits, and for the first hit, that - * it contains the given string, and that it gets the right score + * ranking_query makes a query, checks number of hits, and for + * the first hit, that it contains the given string, and that it + * gets the right score */ -void RankingQuery(int lineno, ZebraHandle zh, char *query, - int exphits, char *firstrec, int firstscore ); +void ranking_query(int lineno, ZebraHandle zh, char *query, + int exphits, char *firstrec, int firstscore ); -- 1.7.10.4