X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftest_embed_record.c;h=ebb8a6a9d23e0d36192aed433fa39d37639c6760;hp=b3c5393f4e5392d20ff12964f0ca25137392667d;hb=46ef949fc6e8c975ebb5bd6ed1a4f745b2d24aae;hpb=7a64f4dd174fc2ce822202423f159e487cbfc736 diff --git a/test/test_embed_record.c b/test/test_embed_record.c index b3c5393..ebb8a6a 100644 --- a/test/test_embed_record.c +++ b/test/test_embed_record.c @@ -11,16 +11,41 @@ #include #include #include - -#if YAZ_HAVE_XML2 +#include #include #include +#include +#include + +#if YAZ_HAVE_XML2 #include #include +#endif + +void test1(void) +{ + int buflen; + for (buflen = 0; buflen < 256; buflen++) + { + char buf[256]; + char buf_a[1024]; + char buf_b[1024]; + int i; + for (i = 0; i < buflen; i++) + buf[i] = 1 + i; + buf[i] = 0; + + yaz_base64encode(buf, buf_a); -void test(void) + YAZ_CHECK(yaz_base64decode(buf_a, buf_b) == 0); + + YAZ_CHECK(strcmp(buf, buf_b) == 0); + } +} + +void test2(void) { char base_enc[] = "MDA3NjZuYW0gIDIyMDAyNjU4YSA0NTAwMDAxMDAxMjAwMDAwMDAzMDAwNjAwMDEyMDA1MDAx" @@ -44,27 +69,230 @@ void test(void) int marc_size = strlen(bin_marc); char out_rec[1000]; + yaz_marc_t marc = yaz_marc_create(); + WRBUF buf = wrbuf_alloc(); + yaz_base64decode(base_enc, out_rec); YAZ_CHECK(strcmp(out_rec, bin_marc) == 0); - yaz_marc_t marc = yaz_marc_create(); yaz_marc_read_iso2709(marc, out_rec, marc_size); - WRBUF buf = wrbuf_alloc(); yaz_marc_write_marcxml(marc, buf); yaz_marc_destroy(marc); wrbuf_destroy(buf); } -#endif + +static int test_render(const char *type_spec, int is_marc, const char *input, + const char *expected_output) +{ + ODR odr = odr_createmem(ODR_ENCODE); + const char *actual_output; + int actual_len; + int res = 0; + WRBUF wrbuf = wrbuf_alloc(); + + Z_NamePlusRecord *npr = odr_malloc(odr, sizeof(*npr)); + npr->which = Z_NamePlusRecord_databaseRecord; + if (is_marc) + npr->u.databaseRecord = z_ext_record_usmarc(odr, input, strlen(input)); + else + npr->u.databaseRecord = z_ext_record_xml(odr, input, strlen(input)); + + actual_output = yaz_record_render(npr, 0, wrbuf, type_spec, &actual_len); + + if (actual_output && expected_output) + { + if (strlen(expected_output) == actual_len && + !memcmp(expected_output, actual_output, actual_len)) + res = 1; + else + { + yaz_log(YLOG_LOG, "Got result"); + yaz_log(YLOG_LOG, "%.*s", actual_len, actual_output); + yaz_log(YLOG_LOG, "Expected result"); + yaz_log(YLOG_LOG, "%s", expected_output); + } + } + else if (!actual_output && !expected_output) + res = 1; + else if (!actual_output && expected_output) + { + yaz_log(YLOG_LOG, "Got null result, but expected"); + yaz_log(YLOG_LOG, "%s", expected_output); + } + else + { + yaz_log(YLOG_LOG, "Got result, but expected no result"); + yaz_log(YLOG_LOG, "%.*s", actual_len, actual_output); + } + wrbuf_destroy(wrbuf); + odr_destroy(odr); + return res; +} int main(int argc, char **argv) { YAZ_CHECK_INIT(argc, argv); YAZ_CHECK_LOG(); + test1(); + test2(); #if YAZ_HAVE_XML2 - test(); + YAZ_CHECK(test_render("xml", 0, "", "")); + + YAZ_CHECK(test_render( + "xml", 1, + "\x30\x30\x31\x33\x38\x6E\x61\x6D\x20\x20\x32\x32\x30\x30\x30\x37" + "\x33\x38\x61\x20\x34\x35\x30\x30\x30\x30\x31\x30\x30\x31\x33\x30" + "\x30\x30\x30\x30\x30\x30\x33\x30\x30\x30\x34\x30\x30\x30\x31\x33" + "\x31\x30\x30\x30\x30\x31\x37\x30\x30\x30\x31\x37\x32\x34\x35\x30" + "\x30\x33\x30\x30\x30\x30\x33\x34\x1E\x20\x20\x20\x31\x31\x32\x32" + "\x34\x34\x36\x36\x20\x1E\x44\x4C\x43\x1E\x31\x30\x1F\x61\x4A\x61" + "\x63\x6B\x20\x43\x6F\x6C\x6C\x69\x6E\x73\x1E\x31\x30\x1F\x61\x48" + "\x6F\x77\x20\x74\x6F\x20\x70\x72\x6F\x67\x72\x61\x6D\x20\x61\x20" + "\x63\x6F\x6D\x70\x75\x74\x65\x72\x1E\x1D", + "\n" + " 00138nam a22000738a 4500\n" + " 11224466 \n" + " DLC\n" + " \n" + " Jack Collins\n" + " \n" + " \n" + " How to program a computer\n" + " \n" + "\n")); + + YAZ_CHECK(test_render("xml", 0, "", "")); + + YAZ_CHECK(test_render( + "xml; base64=/my/text()", 0, + "" + "MDAxMzhuYW0gIDIyMDAwNzM4YSA0NTAwMDAxMDAxMzAwMDAwMDAzMDAwNDAwMDEzMTAwMDAxNzAw" + "MDE3MjQ1MDAzMDAwMDM0HiAgIDExMjI0NDY2IB5ETEMeMTAfYUphY2sgQ29sbGlucx4xMB9hSG93" + "IHRvIHByb2dyYW0gYSBjb21wdXRlch4d" + "", + "\n" + "\n" + " 00138nam a22000738a 4500\n" + " 11224466 \n" + " DLC\n" + " \n" + " Jack Collins\n" + " \n" + " \n" + " How to program a computer\n" + " \n" + "\n")); + + YAZ_CHECK(test_render( + "xml; charset=utf-8; base64=/my/text()", 0, + "" + "MDAxMzhuYW0gIDIyMDAwNzM4YSA0NTAwMDAxMDAxMzAwMDAwMDAzMDAwNDAwMDEzMTAwMDAxNzAw" + "MDE3MjQ1MDAzMDAwMDM0HiAgIDExMjI0NDY2IB5ETEMeMTAfYUphY2sgQ29sbGlucx4xMB9hSG93" + "IHRvIHByb2dyYW0gYSBjb21wdXRlch4d" + "", + "\n" + "\n" + " 00138nam a22000738a 4500\n" + " 11224466 \n" + " DLC\n" + " \n" + " Jack Collins\n" + " \n" + " \n" + " How to program a computer\n" + " \n" + "\n")); + + YAZ_CHECK(test_render( + "xml; base64=/my/text();charset=utf-8", 0, + "" + "MDAxMzhuYW0gIDIyMDAwNzM4YSA0NTAwMDAxMDAxMzAwMDAwMDAzMDAwNDAwMDEzMTAwMDAxNzAw" + "MDE3MjQ1MDAzMDAwMDM0HiAgIDExMjI0NDY2IB5ETEMeMTAfYUphY2sgQ29sbGlucx4xMB9hSG93" + "IHRvIHByb2dyYW0gYSBjb21wdXRlch4d" + "", + "\n" + "\n" + " 00138nam a22000738a 4500\n" + " 11224466 \n" + " DLC\n" + " \n" + " Jack Collins\n" + " \n" + " \n" + " How to program a computer\n" + " \n" + "\n")); + + YAZ_CHECK(test_render( + "txml;base64=/my/text();charset=utf-8", 0, + "" + "MDAxMzhuYW0gIDIyMDAwNzM4YSA0NTAwMDAxMDAxMzAwMDAwMDAzMDAwNDAwMDEzMTAwMDAxNzAw" + "MDE3MjQ1MDAzMDAwMDM0HiAgIDExMjI0NDY2IB5ETEMeMTAfYUphY2sgQ29sbGlucx4xMB9hSG93" + "IHRvIHByb2dyYW0gYSBjb21wdXRlch4d" + "", + "\n" + "\n" + " 00138nam a22000738a 4500\n" + " 11224466 \n" + " DLC\n" + " \n" + " Jack Collins\n" + " \n" + " \n" + " How to program a computer\n" + " \n" + "\n")); + + YAZ_CHECK(test_render( + "xml; charset=utf-8; base64=/my/text()", 0, + "" +"MDA0OTJuYW0gYTIyMDAxNDU1YSA0NTAwMDAxMDAxMDAwMDAwMDA1MDAxNzAwMDEwMDA4MDA0MTAw" +"MDI3MTAwMDA1MjAwMDY4MjQ1MDEwNDAwMTIwMjUwMDAxNDAwMjI0MjYwMDAyMzAwMjM4MzAwMDAx" +"NjAwMjYxNjUwMDA1MTAwMjc3NjUwMDAxODAwMzI4HjAwMDI3NzQ4NR4yMDA1MTAyNjExMTQzNi4w" +"HjA1MDQxM3MxODk0ICAgIGdyICAgICAgICAgICAgMDAwIDAgZ3JlIGQeMSAfYc6czrHPgc6/z43O" +"tM63z4IsIM6az4nOvc+Dz4TOsc69z4TOr869zr/PgiDOmc+JHjEwH2HOlc67zrvOt869zrnOus+M" +"zr0gzrrPgc+Fz4DPhM6/zrPPgc6xz4bOuc66z4zOvSDOu861zr7Ouc66z4zOvSAvH2POms+Jzr3P" +"g8+ELiDOmS4gzpzOsc+Bzr/Pjc60zrfPgi4eICAyzrcgzrXOus60Lh4gIB9hzpHOuM6uzr3OsSwf" +"YzE4OTQuHiAgH2EyNDggz4POtc67Lh4gMB9hR3JlZWsgbGFuZ3VhZ2UsIE1vZGVybh94RGlhbGVj" +"dHMfdkRpY3Rpb25hcmllcx4gMB9hQ3J5cHRvZ3JhcGh5Lh4d" + "", +"\n" +"\n" +" 00492nam a22001455a 4500\n" +" 000277485\n" +" 20051026111436.0\n" +" 050413s1894 gr 000 0 gre d\n" +" \n" +" Μαρούδης, Κωνσταντίνος Ιω\n" +" \n" +" \n" +" Ελληνικόν κρυπτογραφικόν λεξικόν /\n" +" Κωνστ. Ι. Μαρούδης.\n" +" \n" +" \n" +" εκδ.\n" +" \n" +" \n" +" Αθήνα,\n" +" 1894.\n" +" \n" +" \n" +" 248 σελ.\n" +" \n" +" \n" +" Greek language, Modern\n" +" Dialects\n" +" Dictionaries\n" +" \n" +" \n" +" Cryptography.\n" +" \n" +"\n")); + + #endif YAZ_CHECK_TERM; }