-# $Id: Makefile.am,v 1.20 2004-10-28 10:37:15 heikki Exp $
+# $Id: Makefile.am,v 1.21 2004-10-28 15:24:36 heikki Exp $
noinst_PROGRAMS = testclient
testclient_SOURCES = testclient.c
EXTRA_DIST=zebra.cfg zebra6.cfg zebra8.cfg
-t1_SOURCES = t1.c
-t2_SOURCES = t2.c
-t3_SOURCES = t3.c
-t4_SOURCES = t4.c
-t5_SOURCES = t5.c
-t6_SOURCES = t6.c
-t7_SOURCES = t7.c
-t8_SOURCES = t8.c
+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
-/* $Id: t1.c,v 1.8 2004-08-25 09:23:39 adam Exp $
+/* $Id: t1.c,v 1.9 2004-10-28 15:24:36 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
02111-1307, USA.
*/
+/** t1 - just start and stop */
+
#include <stdlib.h>
#include <yaz/log.h>
#include <idzebra/api.h>
+#include "testlib.h"
-/* 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%szebra.cfg", srcdir ? srcdir : "", srcdir ? "/" : "");
- return zebra_start(cfg);
-}
int main(int argc, char **argv)
{
yaz_log_init_file("t1.log");
nmem_init();
- zs = start_service();
+ zs = start_service(0);
zh = zebra_open (zs);
zebra_close (zh);
zebra_stop (zs);
nmem_exit ();
xmalloc_trav ("x");
+ logf(LOG_LOG,"================ All tests OK ");
exit (0);
}
-/* $Id: t10.c,v 1.1 2004-10-28 10:37:15 heikki Exp $
+/* $Id: t10.c,v 1.2 2004-10-28 15:24:36 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
#include <yaz/log.h>
#include <yaz/pquery.h>
#include <idzebra/api.h>
+#include <assert.h>
#include "testlib.h"
#include "rankingrecords.h"
int main(int argc, char **argv)
{
int i;
- char *addinfo;
ZebraService zs;
ZebraHandle zh;
nmem_init ();
zs = start_service("zebrazv.cfg");
+ assert(zs);
zh = zebra_open (zs);
- zebra_select_database(zh, "Default");
- logf(LOG_LOG,"going to call init");
- i=zebra_init(zh);
- logf(LOG_LOG,"init returned %d",i);
- if (i) {
- printf("init failed with %d\n",i);
- zebra_result(zh, &i, &addinfo);
- 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);
- // yaz_log_init_level(LOG_ALL);
+ init_data(zh, recs);
zebra_close(zh);
nmem_exit ();
xmalloc_trav ("x");
logf(LOG_LOG,"============ ALL TESTS PASSED OK ============");
- exit (0);
+ exit(0);
}
-/* $Id: t2.c,v 1.12 2004-08-25 09:23:39 adam Exp $
+/* $Id: t2.c,v 1.13 2004-10-28 15:24:36 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
#include <stdlib.h>
#include <yaz/log.h>
#include <idzebra/api.h>
+#include "testlib.h"
/* 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%szebra.cfg", srcdir ? srcdir : "", srcdir ? "/" : "");
- return zebra_start(cfg);
-}
int main(int argc, char **argv)
{
- int exit_code = 0;
- int hits;
ZebraService zs;
ZebraHandle zh;
- const char *myrec =
+ const char *myrec[] = {
"<gils>\n"
" <title>My title</title>\n"
- "</gils>\n";
+ "</gils>\n",
+ 0};
+
yaz_log_init_file("t2.log");
nmem_init ();
- zs = start_service();
+ zs = start_service(0);
zh = zebra_open (zs);
- zebra_select_database(zh, "Default");
- zebra_init(zh);
- zebra_begin_trans (zh, 1);
-
- zebra_add_record (zh, myrec, strlen(myrec));
+ init_data(zh,myrec);
- zebra_search_PQF (zh, "@attr 1=4 my", "set1", &hits);
- if (hits != 1)
- {
- yaz_log(LOG_FATAL, "Expected 1 hit. Got %d", hits);
- exit_code = 1;
- }
+ Query(__LINE__,zh, "@attr 1=4 my", 1);
zebra_end_trans (zh);
zebra_commit (zh);
nmem_exit ();
xmalloc_trav ("x");
- exit (exit_code);
+ logf(LOG_LOG,"================ All tests OK ");
+ exit (0);
}
-/* $Id: t3.c,v 1.10 2004-10-15 10:07:34 heikki Exp $
+/* $Id: t3.c,v 1.11 2004-10-28 15:24:36 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
#include <yaz/log.h>
#include <yaz/pquery.h>
#include <idzebra/api.h>
+#include "testlib.h"
-/* 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%szebra.cfg", srcdir ? srcdir : "", srcdir ? "/" : "");
- return zebra_start(cfg);
-}
int main(int argc, char **argv)
{
nmem_init ();
- zs = start_service();
+ zs = start_service(0);
zh = zebra_open (zs);
zebra_select_database(zh, "Default");
zebra_init(zh);
zebra_end_trans (zh);
yaz_pqf_destroy(parser);
#if 0
+ /*FIXME Why is this disabled ??? */
zebra_records_retrieve (zh, odr_output, setname, 0,
VAL_TEXT_XML, 1, &retrievalRecord);
#endif
nmem_exit ();
xmalloc_trav ("x");
+ logf(LOG_LOG,"================ All tests OK ");
exit (0);
}
-/* $Id: t4.c,v 1.9 2004-08-25 09:23:39 adam Exp $
+/* $Id: t4.c,v 1.10 2004-10-28 15:24:36 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
#include <yaz/log.h>
#include <yaz/pquery.h>
#include <idzebra/api.h>
+#include "testlib.h"
-/* 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%szebra.cfg", srcdir ? srcdir : "", srcdir ? "/" : "");
- return zebra_start(cfg);
-}
int main(int argc, char **argv)
{
int i;
ZebraService zs;
ZebraHandle zh;
- const char *myrec =
+ const char *myrec[] = {
"<gils>\n"
" <title>My title</title>\n"
- "</gils>\n";
+ "</gils>\n",
+ 0};
yaz_log_init_file("t4.log");
nmem_init ();
- zs = start_service();
+ zs = start_service(0);
zh = zebra_open (zs);
- zebra_init(zh);
- zebra_select_database(zh, "Default");
+ init_data(zh,myrec);
zebra_begin_trans (zh, 1);
for (i = 0; i<1200; i++)
- zebra_add_record (zh, myrec, strlen(myrec));
+ zebra_add_record (zh, myrec[0], strlen(myrec[0]));
zebra_end_trans (zh);
zebra_close(zh);
zebra_stop(zs);
- zs = start_service();
+ zs = start_service("");
zh = zebra_open (zs);
zebra_select_database(zh, "Default");
nmem_exit ();
xmalloc_trav ("x");
+ logf(LOG_LOG,"================ All tests OK ");
exit (0);
}
-/* $Id: t5.c,v 1.7 2004-10-20 14:32:29 heikki Exp $
+/* $Id: t5.c,v 1.8 2004-10-28 15:24:36 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
#include <yaz/pquery.h>
#include <idzebra/api.h>
-/* 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%szebra.cfg", srcdir ? srcdir : "", srcdir ? "/" : "");
- return zebra_start(cfg);
-}
+#include "testlib.h"
+
-static void expect(ZebraHandle zh, const char *pqf, int hits_expect,
- int *exit_code)
-{
- int hits;
- if (zebra_search_PQF (zh, pqf, "set1", &hits) != 0)
- {
- yaz_log(LOG_FATAL, "Search %s: failed", pqf);
- *exit_code = 1;
- }
- else if (hits != hits_expect)
- {
- yaz_log(LOG_FATAL, "Search %s: Expected %d, got %d", pqf,
- hits_expect, hits);
- *exit_code = 2;
- }
-}
int main(int argc, char **argv)
{
- int i;
- int exit_code = 0;
ZebraService zs;
ZebraHandle zh;
const char *myrec[] = {
nmem_init ();
- zs = start_service();
+ zs = start_service(0);
zh = zebra_open (zs);
- zebra_select_database(zh, "Default");
- zebra_init(zh);
-
- zebra_begin_trans (zh, 1);
- for (i = 0; myrec[i]; i++)
- zebra_add_record (zh, myrec[i], strlen(myrec[i]));
- zebra_end_trans (zh);
-
- expect(zh, "@attr 1=4 my", 3, &exit_code);
- expect(zh, "@attr 1=4 {my x}", 1, &exit_code);
- expect(zh, "@attr 1=4 {my x}", 1, &exit_code);
- expect(zh, "@attr 1=4 {x my}", 0, &exit_code);
- expect(zh, "@attr 1=4 {my x title}", 1, &exit_code);
- expect(zh, "@attr 1=4 {my title}", 2, &exit_code);
- expect(zh, "@attr 1=4 @and x title", 2, &exit_code);
+ 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);
/* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */
- expect(zh, "@prox 0 2 1 2 k 2 my x", 2, &exit_code);
+ Query(__LINE__,zh, "@prox 0 2 1 2 k 2 my x", 2);
/* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */
- expect(zh, "@prox 0 2 1 2 k 2 x my", 0, &exit_code);
+ Query(__LINE__,zh, "@prox 0 2 1 2 k 2 x my", 0);
/* exl=0 distance=2 order=0 relation=2 (<=), known, unit=word */
- expect(zh, "@prox 0 2 0 2 k 2 x my", 2, &exit_code);
+ Query(__LINE__,zh, "@prox 0 2 0 2 k 2 x my", 2);
/* exl=0 distance=2 order=0 relation=3 (=), known, unit=word */
- expect(zh, "@prox 0 2 1 3 k 2 my x", 1, &exit_code);
+ Query(__LINE__,zh, "@prox 0 2 1 3 k 2 my x", 1);
/* exl=1 distance=2 order=0 relation=3 (=), known, unit=word */
- expect(zh, "@prox 1 2 1 3 k 2 my x", 1, &exit_code);
+ Query(__LINE__,zh, "@prox 1 2 1 3 k 2 my x", 1);
zebra_close (zh);
zebra_stop (zs);
nmem_exit ();
xmalloc_trav ("x");
- exit (exit_code);
+ logf(LOG_LOG,"======== All tests OK");
+ exit (0);
}
-/* $Id: t6.c,v 1.3 2004-08-25 09:23:39 adam Exp $
+/* $Id: t6.c,v 1.4 2004-10-28 15:24:36 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
#include <yaz/pquery.h>
#include <idzebra/api.h>
-/* 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%szebra6.cfg", srcdir ? srcdir : "", srcdir ? "/" : "");
- return zebra_start(cfg);
-}
+#include "testlib.h"
+
int main(int argc, char **argv)
{
srand(17);
- zs = start_service();
+ zs = start_service("");
zh = zebra_open(zs);
zebra_select_database(zh, "Default");
zebra_init(zh);
nmem_exit ();
xmalloc_trav ("x");
+ logf(LOG_LOG,"========= all tests OK");
exit (0);
}
-/* $Id: t7.c,v 1.2 2004-10-01 09:13:06 heikki Exp $
+/* $Id: t7.c,v 1.3 2004-10-28 15:24:36 heikki Exp $
Copyright (C) 2004
Index Data Aps
#include <yaz/sortspec.h>
#include <idzebra/api.h>
-/* 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%szebra.cfg", srcdir ? srcdir : "", srcdir ? "/" : "");
- return zebra_start(cfg);
-}
+#include "testlib.h"
+
int main(int argc, char **argv)
{
ZebraService zs;
ZebraHandle zh;
- const char *myrec =
+ const char *recs[] = {
"<gils>\n"
" <title>My title</title>\n"
- "</gils>\n";
+ "</gils>\n",
+ 0};
const char *setname1="set1";
const char *setname2="set2";
const char *setname3="set3";
nmem_init ();
- zs = start_service();
+ zs = start_service(""); /* default to zebra.cfg */
zh = zebra_open (zs);
- zebra_select_database(zh, "Default");
- zebra_init(zh);
- zebra_begin_trans (zh, 1);
- zebra_add_record (zh, myrec, strlen(myrec));
- zebra_end_trans (zh);
+ init_data(zh,recs);
+
zebra_begin_trans (zh, 0);
zebra_search_RPN (zh, odr_input, query, setname1, &hits);
rc=zebra_sort(zh, odr_output, 1, &setname1, setname2, spec, &status);
- if (rc) { printf("sort A returned %d %d \n",rc,status); exit(1);}
+ if (rc)
+ {
+ printf("sort A returned %d %d \n",rc,status);
+ exit(1);
+ }
+
rc=zebra_sort(zh, odr_output, 1, &setname2, setname3, spec, &status);
- if (rc) { printf("sort B returned %d %d \n",rc,status); exit(1);}
+ if (rc)
+ {
+ printf("sort B returned %d %d \n",rc,status);
+ exit(1);
+ }
zebra_end_trans (zh);
yaz_pqf_destroy(parser);
/*
zebra_deleleResultSet(zh, Z_DeleteRequest_list,
1, &setnamep, &status);
- */
+ */
odr_destroy (odr_input);
odr_destroy (odr_output);
nmem_exit ();
xmalloc_trav ("x");
+ logf(LOG_LOG,"========= all tests OK");
exit (0);
}
-/* $Id: t8.c,v 1.3 2004-10-24 13:34:45 adam Exp $
+/* $Id: t8.c,v 1.4 2004-10-28 15:24:36 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
#include <yaz/log.h>
#include <yaz/pquery.h>
#include <idzebra/api.h>
+#include "testlib.h"
#define LOGLEVEL LOG_ALL
-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%szebra8.cfg",
- srcdir ? srcdir : "", srcdir ? "/" : "");
- return zebra_start(cfg);
-}
-static void insertdata(ZebraHandle zh)
-{
- const char *rec1 =
+const char *recs[] = {
"<gils>\n"
" <title>My title</title>\n"
" <abstract>test record with single coordset, negatives</abstract>\n"
" <North-Bounding-Coordinate> 49 </North-Bounding-Coordinate>\n"
" <South-Bounding-Coordinate> 31 </South-Bounding-Coordinate>\n"
" </Bounding-Coordinates></Spatial-Domain>"
- "</gils>\n";
- const char *rec2 =
+ "</gils>\n",
+
"<gils>\n"
" <title>Another title</title>\n"
" <abstract>second test with two coord sets</abstract>\n"
" <North-Bounding-Coordinate> 41 </North-Bounding-Coordinate>\n"
" <South-Bounding-Coordinate> 25 </South-Bounding-Coordinate>\n"
" </Bounding-Coordinates></Spatial-Domain>"
- "</gils>\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);
+ "</gils>\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)
nmem_init ();
- zs = start_service();
+ zs = start_service("zebra8.cfg");
zh = zebra_open (zs);
- insertdata(zh);
+ init_data(zh, recs);
-#define Q(q,n) query(zh,__LINE__,q,n)
+#define Q(q,n) 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 );
-/* $Id: t9.c,v 1.1 2004-10-28 10:37:15 heikki Exp $
+/* $Id: t9.c,v 1.2 2004-10-28 15:24:36 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
#include <yaz/log.h>
#include <yaz/pquery.h>
#include <idzebra/api.h>
+
#include "testlib.h"
+
#include "rankingrecords.h"
#define qry(zh,query,hits,string,score) \
int main(int argc, char **argv)
{
- int i;
- char *addinfo;
ZebraService zs;
ZebraHandle zh;
zs = start_service(""); /* default to zebra.cfg */
zh = zebra_open (zs);
- zebra_select_database(zh, "Default");
- logf(LOG_LOG,"going to call init");
- i=zebra_init(zh);
- logf(LOG_LOG,"init returned %d",i);
- if (i) {
- printf("init failed with %d\n",i);
- zebra_result(zh, &i, &addinfo);
- 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);
+ init_data(zh, recs);
zebra_select_database(zh, "Default");
3, "third title", 895 );
- zebra_commit (zh);
zebra_close (zh);
zebra_stop (zs);
nmem_exit ();
xmalloc_trav ("x");
- exit (0);
+ logf(LOG_LOG,"============ ALL TESTS PASSED OK ============");
+ exit(0);
}
-/* $Id: testlib.c,v 1.1 2004-10-28 10:37:15 heikki Exp $
+/* $Id: testlib.c,v 1.2 2004-10-28 15:24:36 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
/** testlib - utilities for the api tests */
+#include <assert.h>
#include <yaz/log.h>
#include <yaz/pquery.h>
#include <idzebra/api.h>
{
char cfg[256];
char *srcdir = getenv("srcdir");
+ ZebraService zs;
if (!srcdir || ! *srcdir)
srcdir=".";
if (!cfgname || ! *cfgname )
/*sprintf(cfg, "%.200s%szebra.cfg", srcdir ? srcdir : "", srcdir ? "/" : ""); */
sprintf(cfg, "%.200s/%s",srcdir, cfgname);
- return zebra_start(cfg);
+ zs=zebra_start(cfg);
+ if (!zs)
+ {
+ printf("zebra_start failed, probably because missing config file \n"
+ "check %s\n", cfg);
+ exit(9);
+ }
+ return zs;
}
-/**
- * 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 )
+/** inits the database and inserts test data */
+
+void init_data( ZebraHandle zh, const char **recs)
{
- ZebraRetrievalRecord retrievalRecord[10];
- ODR odr_output = odr_createmem (ODR_DECODE);
- ODR odr_input = odr_createmem (ODR_DECODE);
- YAZ_PQF_Parser parser = yaz_pqf_create();
- Z_RPNQuery *rpn = yaz_pqf_parse(parser, odr_input, query);
+ int i;
+ char *addinfo;
+ assert(zh);
+ zebra_select_database(zh, "Default");
+ logf(LOG_LOG,"going to call init");
+ i=zebra_init(zh);
+ logf(LOG_LOG,"init returned %d",i);
+ if (i)
+ {
+ printf("init failed with %d\n",i);
+ zebra_result(zh, &i, &addinfo);
+ 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);
+
+}
+
+
+
+int Query(int lineno, ZebraHandle zh, char *query, int exphits)
+{
+ ODR odr;
+ YAZ_PQF_Parser parser;
+ Z_RPNQuery *rpn;
const char *setname="rsetname";
int hits;
int rc;
- int i;
+
logf(LOG_LOG,"======================================");
logf(LOG_LOG,"qry[%d]: %s", lineno, query);
+ odr=odr_createmem (ODR_DECODE);
+ parser = yaz_pqf_create();
+ rpn = yaz_pqf_parse(parser, odr, query);
if (!rpn) {
printf("Error: Parse failed \n%s\n",query);
exit(1);
}
- rc=zebra_search_RPN (zh, odr_input, rpn, setname, &hits);
+ rc=zebra_search_RPN (zh, odr, rpn, setname, &hits);
if (rc) {
printf("Error: search returned %d \n%s\n",rc,query);
exit (1);
exit (1);
}
yaz_pqf_destroy(parser);
+ odr_destroy (odr);
+ return hits;
+}
+
+
+/**
+ * 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 )
+{
+ ZebraRetrievalRecord retrievalRecord[10];
+ ODR odr_output = odr_createmem (ODR_ENCODE);
+ const char *setname="rsetname";
+ int hits;
+ int rc;
+ int i;
+
+ hits=Query(lineno, zh, query, exphits);
for (i = 0; i<10; i++)
- {
retrievalRecord[i].position = i+1;
- retrievalRecord[i].score = i+20000;
- }
rc=zebra_records_retrieve (zh, odr_output, setname, 0,
VAL_TEXT_XML, hits, retrievalRecord);
exit(1);
}
odr_destroy (odr_output);
- odr_destroy (odr_input);
}
-/* $Id: testlib.h,v 1.1 2004-10-28 10:43:38 heikki Exp $
+/* $Id: testlib.h,v 1.2 2004-10-28 15:24:36 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
Index Data Aps
/** read zebra.cfg from env var srcdir if it exists; otherwise current dir */
-ZebraService start_service();
+ZebraService start_service(char *cfgfile);
+
+/** initialises the zebra base and inserts some test data in it */
+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);
+
/**
* makes a query, checks number of hits, and for the first hit, that
void RankingQuery(int lineno, ZebraHandle zh, char *query,
int exphits, char *firstrec, int firstscore );
-