From 9a6e6e95d703c4f42f83e969404daa74ef7e2c20 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 14 Apr 2005 12:01:50 +0000 Subject: [PATCH] Test case for retrieval out of range of sortmax. --- test/api/t4.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/test/api/t4.c b/test/api/t4.c index ffc3355..3590701 100644 --- a/test/api/t4.c +++ b/test/api/t4.c @@ -1,4 +1,4 @@ -/* $Id: t4.c,v 1.15 2005-03-09 12:14:42 adam Exp $ +/* $Id: t4.c,v 1.16 2005-04-14 12:01:50 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -30,17 +30,24 @@ const char *myrec[] = { "\n", 0}; +#define NUMBER_TO_FETCH_MAX 1000 + int main(int argc, char **argv) { int i; + int number_to_be_inserted = 5; + int number_to_fetch = 5; + ZebraService zs = start_up(0, argc, argv); ZebraHandle zh = zebra_open(zs); init_data(zh, myrec); zebra_begin_trans (zh, 1); - for (i = 0; i<1200; i++) + for (i = 0; i< number_to_be_inserted-1; i++) + { /* -1 since already inserted one in init_data */ zebra_add_record(zh, myrec[0], strlen(myrec[0])); + } zebra_end_trans(zh); zebra_close(zh); zebra_stop(zs); @@ -48,21 +55,27 @@ int main(int argc, char **argv) zs = start_service(""); zh = zebra_open(zs); zebra_select_database(zh, "Default"); + zebra_set_resource(zh, "sortmax", "3"); /* make small sort boundary */ for (i = 0; i<2; i++) { - ZebraRetrievalRecord retrievalRecord[1001]; + ZebraRetrievalRecord retrievalRecord[NUMBER_TO_FETCH_MAX]; char setname[20]; int j; ODR odr_input = odr_createmem(ODR_DECODE); ODR odr_output = odr_createmem(ODR_DECODE); YAZ_PQF_Parser parser = yaz_pqf_create(); - Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, - "@attr 1=4 my"); + Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, "@attr 1=4 my"); zint hits; sprintf(setname, "s%d", i+1); zebra_search_RPN(zh, odr_input, query, setname, &hits); + if (hits != number_to_be_inserted) + { + yaz_log(YLOG_WARN, "Unexpected hit count " ZINT_FORMAT + "(should be %d)", hits, number_to_be_inserted); + exit(1); + } yaz_pqf_destroy(parser); @@ -70,13 +83,32 @@ int main(int argc, char **argv) zebra_begin_trans(zh, 1); - for (j = 0; j<1001; j++) + for (j = 0; j < number_to_fetch; j++) retrievalRecord[j].position = j+1; zebra_records_retrieve(zh, odr_output, setname, 0, - VAL_TEXT_XML, 1001, retrievalRecord); + VAL_TEXT_XML, number_to_fetch, retrievalRecord); - + if (zebra_errCode(zh)) + { + yaz_log(YLOG_FATAL, "zebra_records_retrieve returned error %d", + zebra_errCode(zh)); + exit(1); + } + + for (j = 0; j < number_to_fetch; j++) + { + if (!retrievalRecord[j].buf) + { + yaz_log(YLOG_FATAL, "No record buf at position %d", j); + exit(1); + } + if (!retrievalRecord[j].len) + { + yaz_log(YLOG_FATAL, "No record len at position %d", j); + exit(1); + } + } odr_destroy(odr_output); zebra_end_trans(zh); -- 1.7.10.4