From cca8a96be6d6ce6de52009e53e23876ce2fc195c Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 16 Dec 2013 14:23:20 +0100 Subject: [PATCH] User-defined retrieval records for yaz-ztest YAZ-714 Man page for yaz-ztest updated too. --- doc/yaz-ztest-man.xml | 16 ++++++++++++++++ ztest/read-marc.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/doc/yaz-ztest-man.xml b/doc/yaz-ztest-man.xml index a6002e6..dfa1b3a 100644 --- a/doc/yaz-ztest-man.xml +++ b/doc/yaz-ztest-man.xml @@ -72,6 +72,22 @@ So record at position 1, 25, 49, etc .. are equivalent. + For XML if no element set is given or element has value "marcxml", + MARCXML is returned (each of the 24 dummy records converted from + ISO2709 to XML). For element set OP, OPAC XML is returned. + + + yaz-ztest may also return predefined XML records (for testing). + This is enabled if YAZ_ZTEST_XML_FETCH environment + variable is defined. A record is fetched form a file (one record per file). + The path for the filename is + FE.d.xml + where F is the YAZ_ZTEST_XML_FETCH value + (possibly + empty), E is element-set, + d is record position (starting from 1). + + The following databases are honored by yaz-ztest: Default, slow and db.* (all databases with prefix "db"). Any diff --git a/ztest/read-marc.c b/ztest/read-marc.c index 487d9ab..7a54ddf 100644 --- a/ztest/read-marc.c +++ b/ztest/read-marc.c @@ -15,6 +15,20 @@ #include "ztest.h" +#if HAVE_SYS_TYPES_H +#include +#endif +#if HAVE_SYS_STAT_H +#include +#endif +#ifdef WIN32 +#include +#endif + +#if HAVE_UNISTD_H +#include +#endif + #define NO_MARC_RECORDS 24 char *marc_records[NO_MARC_RECORDS] = { @@ -1680,6 +1694,28 @@ char *dummy_xml_record(int num, ODR odr, const char *esn) return rec; } } + else + { + char *buf = 0; + const char *e = getenv("YAZ_ZTEST_XML_FETCH"); + if (e) + { + WRBUF w = wrbuf_alloc(); + struct stat sbuf; + FILE *file = 0; + + wrbuf_printf(w, "%s%s.%d.xml", e, esn, num); + if (stat(wrbuf_cstr(w), &sbuf) == 0 && + (file = fopen(wrbuf_cstr(w), "rb"))) + { + buf = odr_malloc(odr, sbuf.st_size); + fread(buf, 1, sbuf.st_size, file); + } + if (file) + fclose(file); + } + return buf; + } return 0; } -- 1.7.10.4