From: Adam Dickmeiss Date: Mon, 9 Dec 2013 09:57:07 +0000 (+0100) Subject: yaz-ztest: returns MARC-in-JSON for JSON format X-Git-Tag: v5.0.5~4 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=2a7d35ce3d1bad977c9cf4f8d586e3699b4d20b3 yaz-ztest: returns MARC-in-JSON for JSON format --- diff --git a/ztest/read-marc.c b/ztest/read-marc.c index b11b697..487d9ab 100644 --- a/ztest/read-marc.c +++ b/ztest/read-marc.c @@ -1683,6 +1683,26 @@ char *dummy_xml_record(int num, ODR odr, const char *esn) return 0; } +char *dummy_json_record(int num, ODR odr, const char *esn) +{ + if (!esn || !strcmp(esn, "marcinjson")) + { + char *rec = dummy_marc_record(num, odr); + if (rec) + { + WRBUF w = wrbuf_alloc(); + yaz_marc_t mt = yaz_marc_create(); + yaz_marc_xml(mt, YAZ_MARC_JSON); + yaz_marc_decode_wrbuf(mt, rec, -1, w); + rec = odr_strdup(odr, wrbuf_cstr(w)); + yaz_marc_destroy(mt); + wrbuf_destroy(w); + return rec; + } + } + return 0; +} + /* * Local variables: * c-basic-offset: 4 diff --git a/ztest/ztest.c b/ztest/ztest.c index b7807d9..7299be0 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -944,6 +944,21 @@ int ztest_fetch(void *handle, bend_fetch_rr *r) return 0; } } + else if (!oid_oidcmp(oid, yaz_oid_recsyn_json)) + { + if ((cp = dummy_json_record(r->number, r->stream, esn))) + { + r->len = strlen(cp); + r->record = cp; + r->schema = "info:srw/schema/1/marcxml-1.1"; + } + else + { + r->errcode = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS; + r->surrogate_flag = 1; + return 0; + } + } else { char buf[OID_STR_MAX]; diff --git a/ztest/ztest.h b/ztest/ztest.h index f895df1..d829b77 100644 --- a/ztest/ztest.h +++ b/ztest/ztest.h @@ -34,6 +34,7 @@ Z_GenericRecord *dummy_grs_record(int num, ODR o); char *dummy_marc_record(int num, ODR odr); char *dummy_xml_record(int num, ODR odr, const char *esn); +char *dummy_json_record(int num, ODR odr, const char *esn); Z_OPACRecord *dummy_opac(int num, ODR odr, const char *marc_input); /*