-/* $Id: testlib.c,v 1.32 2006-05-10 08:13:35 adam Exp $
- Copyright (C) 1995-2005
+/* $Id: testlib.c,v 1.38 2006-09-08 09:56:40 adam Exp $
+ Copyright (C) 1995-2006
Index Data ApS
This file is part of the Zebra server.
for more details.
You should have received a copy of the GNU General Public License
-along with Zebra; see the file LICENSE.zebra. If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
*/
/** testlib - utilities for the api tests */
void tl_start_log(int argc, char **argv)
{
- int cmd_level = 0;
char logname[2048];
if (!argv)
return;
log_level = yaz_log_mask_str_x(argv[1], 0);
if (argc >= 3)
yaz_log_time_format(argv[2]);
- yaz_log_init_level(YLOG_DEFAULT_LEVEL | log_level | cmd_level);
+ if (log_level)
+ yaz_log_init_level(log_level);
yaz_log(log_level, "starting %s", argv[0]);
}
#if HAVE_SYS_RESOURCE_H
#if HAVE_SYS_TIME_H
struct rlimit rlim;
- rlim.rlim_cur = 20;
- rlim.rlim_max = 20;
+ rlim.rlim_cur = 60;
+ rlim.rlim_max = 60;
setrlimit(RLIMIT_CPU, &rlim);
#endif
#endif
yaz_pqf_destroy(parser);
if (!rpn)
{
+ yaz_log(log_level, "could not parse pqf query %s\n", query);
+ printf("could not parse pqf query %s\n", query);
odr_destroy(odr);
return 0;
}
rc = zebra_search_RPN(zh, odr, rpn, setname, &hits);
+ odr_destroy(odr);
if (experror)
{
int code;
return 0;
}
}
- odr_destroy(odr);
return 1;
}
int exp_pos, int exp_num, int exp_partial,
const char **exp_entries)
{
+ int ret = 1;
ODR odr = odr_createmem(ODR_ENCODE);
ZebraScanEntry *entries = 0;
int partial = -123;
res = zebra_scan_PQF(zh, odr, query, &pos, &num, &entries, &partial,
0 /* setname */);
- if (res != ZEBRA_OK)
+
+ if (partial == -123)
{
- printf("Error: scan returned %d (FAIL), but no error was expected\n"
- "%s\n", res, query);
- return 0;
+ printf("Error: scan returned OK, but partial was not set\n"
+ "%s\n", query);
+ ret = 0;
+ }
+ if (partial != exp_partial)
+ {
+ printf("Error: scan OK, with partial/expected %d/%d\n",
+ partial, exp_partial);
+ ret = 0;
+ }
+ if (res != ZEBRA_OK) /* failure */
+ {
+ if (exp_entries)
+ {
+ printf("Error: scan failed, but no error was expected\n");
+ ret = 0;
+ }
}
else
{
- int fails = 0;
- if (partial == -123)
- {
- printf("Error: scan returned OK, but partial was not set\n"
- "%s\n", query);
- fails++;
- }
- if (partial != exp_partial)
- {
- printf("Error: scan returned OK, with partial/expected %d/%d\n"
- "%s\n", partial, exp_partial, query);
- fails++;
- }
- if (num != exp_num)
- {
- printf("Error: scan returned OK, with num/expected %d/%d\n"
- "%s\n", num, exp_num, query);
- fails++;
- }
- if (pos != exp_pos)
- {
- printf("Error: scan returned OK, with pos/expected %d/%d\n"
- "%s\n", pos, exp_pos, query);
- fails++;
- }
- if (fails)
- return 0;
- fails = 0;
- if (exp_entries)
- {
- int i;
- for (i = 0; i<num; i++)
- {
- if (strcmp(exp_entries[i], entries[i].term))
- {
- printf("Error: scan OK, but entry %d term/exp %s/%s\n"
- "%s\n",
- i, entries[i].term, exp_entries[i], query);
- fails++;
- }
- }
- }
- if (fails)
- return 0;
+ if (!exp_entries)
+ {
+ printf("Error: scan OK, but error was expected\n");
+ ret = 0;
+ }
+ else
+ {
+ int fails = 0;
+ if (num != exp_num)
+ {
+ printf("Error: scan OK, with num/expected %d/%d\n",
+ num, exp_num);
+ fails++;
+ }
+ if (pos != exp_pos)
+ {
+ printf("Error: scan OK, with pos/expected %d/%d\n",
+ pos, exp_pos);
+ fails++;
+ }
+ if (!fails)
+ {
+ if (exp_entries)
+ {
+ int i;
+ for (i = 0; i<num; i++)
+ {
+ if (strcmp(exp_entries[i], entries[i].term))
+ {
+ printf("Error: scan OK of %s, no %d got=%s exp=%s\n",
+ query, i, entries[i].term, exp_entries[i]);
+ fails++;
+ }
+ }
+ }
+ }
+ if (fails)
+ ret = 0;
+ }
}
odr_destroy(odr);
- return 1;
+ return ret;
}
/**
int exphits, char *firstrec, int firstscore)
{
ZebraRetrievalRecord retrievalRecord[10];
- ODR odr_output = odr_createmem (ODR_ENCODE);
- const char *setname="rsetname";
+ ODR odr_output = 0;
+ const char *setname = "rsetname";
int rc;
int i;
+ int ret = 1;
if (!tl_query(zh, query, exphits))
return 0;
for (i = 0; i<10; i++)
retrievalRecord[i].position = i+1;
- rc = zebra_records_retrieve (zh, odr_output, setname, 0,
- VAL_TEXT_XML, exphits, retrievalRecord);
+ odr_output = odr_createmem(ODR_ENCODE);
+ rc = zebra_records_retrieve(zh, odr_output, setname, 0,
+ VAL_TEXT_XML, exphits, retrievalRecord);
if (rc != ZEBRA_OK)
- return 0;
-
- if (!strstr(retrievalRecord[0].buf, firstrec))
+ ret = 0;
+ else if (!strstr(retrievalRecord[0].buf, firstrec))
{
printf("Error: Got the wrong record first\n");
printf("Expected '%s' but got\n", firstrec);
printf("%.*s\n", retrievalRecord[0].len, retrievalRecord[0].buf);
- return 0;
+ ret = 0;
}
-
- if (retrievalRecord[0].score != firstscore)
+ else if (retrievalRecord[0].score != firstscore)
{
printf("Error: first rec got score %d instead of %d\n",
retrievalRecord[0].score, firstscore);
- return 0;
+ ret = 0;
}
odr_destroy (odr_output);
- return 1;
+ return ret;
}
int tl_meta_query(ZebraHandle zh, char *query, int exphits,
zint *ids)
{
ZebraMetaRecord *meta;
- ODR odr_output = odr_createmem (ODR_ENCODE);
- const char *setname="rsetname";
- zint *positions = (zint *) malloc(1 + (exphits * sizeof(zint)));
- int i;
+ const char *setname= "rsetname";
+ zint *positions = 0;
+ int i, ret = 1;
if (!tl_query(zh, query, exphits))
return 0;
+ positions = (zint *) xmalloc(1 + (exphits * sizeof(zint)));
for (i = 0; i<exphits; i++)
positions[i] = i+1;
- meta = zebra_meta_records_create (zh, setname, exphits, positions);
+ meta = zebra_meta_records_create(zh, setname, exphits, positions);
if (!meta)
{
printf("Error: retrieve returned error\n%s\n", query);
+ xfree(positions);
return 0;
}
{
printf("Expected id=" ZINT_FORMAT " but got id=" ZINT_FORMAT "\n",
ids[i], meta[i].sysno);
- return 0;
+ ret = 0;
}
}
zebra_meta_records_destroy(zh, meta, exphits);
- odr_destroy (odr_output);
- free(positions);
- return 1;
+ xfree(positions);
+ return ret;
}
int tl_sort(ZebraHandle zh, const char *query, zint hits, zint *exp)