X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=test%2Fapi%2Ft8.c;h=9b8c60aa15a6bc73495e5d8aa6cf17a61f036a8e;hb=6c9fcd3b5d3108702fa1ffc92dab4ab6060f9a19;hp=741e5ea181e5ddf4a43e95e913e33ffc3d08fa37;hpb=35b09bd81ef9079e33f4b4d197c9d8299aceb955;p=idzebra-moved-to-github.git diff --git a/test/api/t8.c b/test/api/t8.c index 741e5ea..9b8c60a 100644 --- a/test/api/t8.c +++ b/test/api/t8.c @@ -1,6 +1,6 @@ -/* $Id: t8.c,v 1.1 2004-10-01 15:36:41 heikki Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 - Index Data Aps +/* $Id: t8.c,v 1.7 2005-01-15 19:38:35 adam Exp $ + Copyright (C) 1995-2005 + Index Data ApS This file is part of the Zebra server. @@ -20,28 +20,11 @@ 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" -static int testno=1; - -/* read zebra.cfg from env var srcdir if it exists; otherwise current dir */ -static ZebraService start_service() -{ - char cfg[256]; - char *srcdir = getenv("srcdir"); - sprintf(cfg, "%.200s%szebragils.cfg", - srcdir ? srcdir : "", srcdir ? "/" : ""); - return zebra_start(cfg); -} - -static void insertdata(ZebraHandle zh) -{ - const char *rec1 = +const char *recs[] = { "\n" " My title\n" " test record with single coordset, negatives\n" @@ -51,8 +34,8 @@ static void insertdata(ZebraHandle zh) " 49 \n" " 31 \n" " " - "\n"; - const char *rec2 = + "\n", + "\n" " Another title\n" " second test with two coord sets\n" @@ -68,74 +51,20 @@ static void insertdata(ZebraHandle zh) " 41 \n" " 25 \n" " " - "\n"; - - zebra_select_database(zh, "Default"); - zebra_init(zh); - zebra_begin_trans (zh, 1); - zebra_add_record (zh, rec1, strlen(rec1)); - zebra_add_record (zh, rec2, strlen(rec2)); - zebra_end_trans (zh); - -} - -static void query( ZebraHandle zh, int lineno, char *qry, int expectedhits) -{ - ODR odr_input = odr_createmem (ODR_DECODE); - YAZ_PQF_Parser parser = yaz_pqf_create(); - Z_RPNQuery *query; - - int hits; - int thistest=testno++; - int rc; - - logf(LOG_LOG,"Test %d (line %d): expecting %d", - thistest, lineno,expectedhits); - logf(LOG_LOG,"%s", qry); - - query = yaz_pqf_parse(parser, odr_input, qry); - assert(query); - zebra_begin_trans (zh, 0); + "\n", + 0}; - logf(LOG_DEBUG,"calling search"); - rc=zebra_search_RPN (zh, odr_input, query, "nameless", &hits); - logf(LOG_DEBUG,"search returned %d",rc); - if (rc) - printf("search returned %d",rc); - if (hits != expectedhits) - { - printf( "FAIL: Test %d (line %d):\n" - "got %d hits, expected %d\n" - "in '%s'\n", - thistest, lineno,hits, expectedhits, qry); - logf( LOG_FATAL, "FAIL: Test %d (line %d): got %d hits, expected %d\n", - thistest, lineno, hits,expectedhits); - exit(1); - } - - zebra_end_trans (zh); - yaz_pqf_destroy(parser); - odr_destroy (odr_input); - logf(LOG_LOG,"Test %d ok",thistest); -} int main(int argc, char **argv) { - ZebraService zs; - ZebraHandle zh; - yaz_log_init_file("t8.log"); - /* yaz_log_init_level(LOG_ALL); */ + ZebraService zs = start_up("zebra8.cfg", argc, argv); + ZebraHandle zh = zebra_open (zs); - nmem_init (); - - zs = start_service(); - zh = zebra_open (zs); - - insertdata(zh); + init_data(zh, recs); -#define Q(q,n) query(zh,__LINE__,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 ); @@ -162,12 +91,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); }