From d72e1bb8f40e57e62944199c576e22e14f1b2b60 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 30 Nov 2007 10:08:01 +0000 Subject: [PATCH] Added testlib functions for fetch of records --- test/api/safari1.c | 12 ++++++- test/api/t16.c | 101 +++++++++++++--------------------------------------- test/api/testlib.c | 51 +++++++++++++++++++++++++- test/api/testlib.h | 10 +++++- 4 files changed, 95 insertions(+), 79 deletions(-) diff --git a/test/api/safari1.c b/test/api/safari1.c index cdcb03e..1ffd12a 100644 --- a/test/api/safari1.c +++ b/test/api/safari1.c @@ -1,4 +1,4 @@ -/* $Id: safari1.c,v 1.17 2007-11-14 13:12:41 adam Exp $ +/* $Id: safari1.c,v 1.18 2007-11-30 10:08:01 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -95,6 +95,16 @@ static void tst(int argc, char **argv) ids[1] = 24339; ids[2] = 24340; YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 3, ids)); + +#if 0 + { + zint sysnos[10]; + int no_sysnos = 10; + YAZ_CHECK_EQ(zebra_recid_to_sysno(zh, "Default", 24338, sysnos, + &no_sysnos), ZEBRA_OK); + YAZ_CHECK_EQ(no_sysnos, 1); + } +#endif /* limit to 125061 */ limits[0] = 125061; diff --git a/test/api/t16.c b/test/api/t16.c index 608d510..aa2cc65 100644 --- a/test/api/t16.c +++ b/test/api/t16.c @@ -1,4 +1,4 @@ -/* $Id: t16.c,v 1.12 2007-05-08 12:50:05 adam Exp $ +/* $Id: t16.c,v 1.13 2007-11-30 10:08:01 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -30,57 +30,6 @@ const char *myrec[] = { "\n", 0}; -#define NUMBER_TO_FETCH_MAX 1000 - -static ZEBRA_RES fetch_first(ZebraHandle zh, const char *element_set, - const Odr_oid * format, ODR odr, - const char **rec_buf, size_t *rec_len) -{ - ZebraRetrievalRecord retrievalRecord[1]; - Z_RecordComposition *comp; - ZEBRA_RES res; - - retrievalRecord[0].position = 1; /* get from this position */ - - yaz_set_esn(&comp, element_set, odr->mem); - - res = zebra_records_retrieve(zh, odr, "default", comp, format, 1, - retrievalRecord); - if (res != ZEBRA_OK) - { - int code = zebra_errCode(zh); - yaz_log(YLOG_FATAL, "zebra_records_retrieve returned error %d", - code); - } - else - { - *rec_buf = retrievalRecord[0].buf; - *rec_len = retrievalRecord[0].len; - } - return res; -} - -static ZEBRA_RES fetch_first_compare(ZebraHandle zh, const char *element_set, - const Odr_oid *format, const char *cmp_rec) -{ - const char *rec_buf = 0; - size_t rec_len = 0; - ODR odr = odr_createmem(ODR_ENCODE); - ZEBRA_RES res = fetch_first(zh, element_set, format, odr, - &rec_buf, &rec_len); - if (res == ZEBRA_OK) - { - if (strlen(cmp_rec) != rec_len) - res = ZEBRA_FAIL; - else if (memcmp(cmp_rec, rec_buf, rec_len)) - res = ZEBRA_FAIL; - } - odr_destroy(odr); - return res; -} - - - static void tst(int argc, char **argv) { zint hits; @@ -105,35 +54,35 @@ static void tst(int argc, char **argv) YAZ_CHECK_EQ(res, ZEBRA_OK); YAZ_CHECK_EQ(hits, 1); - YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml, - "mismatch"), ZEBRA_FAIL); - - YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_sutrs, - myrec[0]), ZEBRA_OK); - - YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml, - myrec[0]), ZEBRA_OK); + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml, + "mismatch"), ZEBRA_FAIL); - YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::meta::sysno", - yaz_oid_recsyn_sutrs, - "2"), ZEBRA_OK); - - YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::meta::sysno", - yaz_oid_recsyn_xml, - zebra_xml_sysno), ZEBRA_OK); + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_sutrs, + myrec[0]), ZEBRA_OK); + + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::data", yaz_oid_recsyn_xml, + myrec[0]), ZEBRA_OK); + + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno", + yaz_oid_recsyn_sutrs, + "2"), ZEBRA_OK); + + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta::sysno", + yaz_oid_recsyn_xml, + zebra_xml_sysno), ZEBRA_OK); - YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::meta", yaz_oid_recsyn_xml, - zebra_xml_meta), ZEBRA_OK); + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::meta", yaz_oid_recsyn_xml, + zebra_xml_meta), ZEBRA_OK); - YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::index::title:p", - yaz_oid_recsyn_xml, - zebra_xml_index_title_p), ZEBRA_OK); + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::title:p", + yaz_oid_recsyn_xml, + zebra_xml_index_title_p), ZEBRA_OK); - YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::nonexistent", - yaz_oid_recsyn_xml, ""), ZEBRA_OK); + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::nonexistent", + yaz_oid_recsyn_xml, ""), ZEBRA_OK); - YAZ_CHECK_EQ(fetch_first_compare(zh, "zebra::index::nonexistent", - yaz_oid_recsyn_xml, ""), ZEBRA_OK); + YAZ_CHECK_EQ(tl_fetch_first_compare(zh, "zebra::index::nonexistent", + yaz_oid_recsyn_xml, ""), ZEBRA_OK); YAZ_CHECK(tl_close_down(zh, zs)); } diff --git a/test/api/testlib.c b/test/api/testlib.c index 583a2c4..7773351 100644 --- a/test/api/testlib.c +++ b/test/api/testlib.c @@ -1,4 +1,4 @@ -/* $Id: testlib.c,v 1.45 2007-04-18 11:37:39 adam Exp $ +/* $Id: testlib.c,v 1.46 2007-11-30 10:08:01 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -450,6 +450,55 @@ void tl_check_filter(ZebraService zs, const char *name) } } +ZEBRA_RES tl_fetch_first(ZebraHandle zh, const char *element_set, + const Odr_oid * format, ODR odr, + const char **rec_buf, size_t *rec_len) +{ + ZebraRetrievalRecord retrievalRecord[1]; + Z_RecordComposition *comp; + ZEBRA_RES res; + + retrievalRecord[0].position = 1; /* get from this position */ + + yaz_set_esn(&comp, element_set, odr->mem); + + res = zebra_records_retrieve(zh, odr, "default", comp, format, 1, + retrievalRecord); + if (res != ZEBRA_OK) + { + int code = zebra_errCode(zh); + yaz_log(YLOG_FATAL, "zebra_records_retrieve returned error %d", + code); + } + else + { + *rec_buf = retrievalRecord[0].buf; + *rec_len = retrievalRecord[0].len; + } + return res; +} + +ZEBRA_RES tl_fetch_first_compare(ZebraHandle zh, + const char *element_set, + const Odr_oid *format, const char *cmp_rec) +{ + const char *rec_buf = 0; + size_t rec_len = 0; + ODR odr = odr_createmem(ODR_ENCODE); + ZEBRA_RES res = tl_fetch_first(zh, element_set, format, odr, + &rec_buf, &rec_len); + if (res == ZEBRA_OK) + { + if (strlen(cmp_rec) != rec_len) + res = ZEBRA_FAIL; + else if (memcmp(cmp_rec, rec_buf, rec_len)) + res = ZEBRA_FAIL; + } + odr_destroy(odr); + return res; +} + + diff --git a/test/api/testlib.h b/test/api/testlib.h index 1d3fcba..b433436 100644 --- a/test/api/testlib.h +++ b/test/api/testlib.h @@ -1,4 +1,4 @@ -/* $Id: testlib.h,v 1.25 2007-04-16 08:44:32 adam Exp $ +/* $Id: testlib.h,v 1.26 2007-11-30 10:08:01 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -123,6 +123,14 @@ int tl_meta_query(ZebraHandle zh, char *query, int exphits, */ void tl_check_filter(ZebraService zs, const char *name); +ZEBRA_RES tl_fetch_first_compare(ZebraHandle zh, + const char *element_set, + const Odr_oid *format, const char *cmp_rec); + +ZEBRA_RES tl_fetch_first(ZebraHandle zh, const char *element_set, + const Odr_oid * format, ODR odr, + const char **rec_buf, size_t *rec_len); + #define TL_MAIN int main(int argc, char **argv) { \ YAZ_CHECK_INIT(argc, argv); YAZ_CHECK_LOG(); tst(argc, argv); YAZ_CHECK_TERM; } /* -- 1.7.10.4