1 /* $Id: testlib.c,v 1.1 2004-10-28 10:37:15 heikki Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
5 This file is part of the Zebra server.
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
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
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
23 /** testlib - utilities for the api tests */
26 #include <yaz/pquery.h>
27 #include <idzebra/api.h>
30 /* read zebra.cfg from env var srcdir if it exists; otherwise current dir */
31 ZebraService start_service(char *cfgname)
34 char *srcdir = getenv("srcdir");
35 if (!srcdir || ! *srcdir)
37 if (!cfgname || ! *cfgname )
39 /*sprintf(cfg, "%.200s%szebra.cfg", srcdir ? srcdir : "", srcdir ? "/" : ""); */
41 sprintf(cfg, "%.200s/%s",srcdir, cfgname);
42 return zebra_start(cfg);
46 * makes a query, checks number of hits, and for the first hit, that
47 * it contains the given string, and that it gets the right score
49 void RankingQuery(int lineno, ZebraHandle zh, char *query,
50 int exphits, char *firstrec, int firstscore )
52 ZebraRetrievalRecord retrievalRecord[10];
53 ODR odr_output = odr_createmem (ODR_DECODE);
54 ODR odr_input = odr_createmem (ODR_DECODE);
55 YAZ_PQF_Parser parser = yaz_pqf_create();
56 Z_RPNQuery *rpn = yaz_pqf_parse(parser, odr_input, query);
57 const char *setname="rsetname";
62 logf(LOG_LOG,"======================================");
63 logf(LOG_LOG,"qry[%d]: %s", lineno, query);
66 printf("Error: Parse failed \n%s\n",query);
69 rc=zebra_search_RPN (zh, odr_input, rpn, setname, &hits);
71 printf("Error: search returned %d \n%s\n",rc,query);
75 if (hits != exphits) {
76 printf("Error: search returned %d hits instead of %d\n",
80 yaz_pqf_destroy(parser);
82 for (i = 0; i<10; i++)
84 retrievalRecord[i].position = i+1;
85 retrievalRecord[i].score = i+20000;
88 rc=zebra_records_retrieve (zh, odr_output, setname, 0,
89 VAL_TEXT_XML, hits, retrievalRecord);
92 printf("Error: retrieve returned %d \n%s\n",rc,query);
96 if (!strstr(retrievalRecord[0].buf, firstrec))
98 printf("Error: Got the wrong record first\n");
99 printf("Expected '%s' but got \n",firstrec);
100 printf("%.*s\n",retrievalRecord[0].len,retrievalRecord[0].buf);
104 if (retrievalRecord[0].score != firstscore)
106 printf("Error: first rec got score %d instead of %d\n",
107 retrievalRecord[0].score, firstscore);
110 odr_destroy (odr_output);
111 odr_destroy (odr_input);