/* This file is part of the YAZ toolkit. * Copyright (C) Index Data * See the file LICENSE for details. */ #if HAVE_CONFIG_H #include #endif #include #include #include #include #include #if YAZ_HAVE_XSLT #include #include yaz_retrieval_t conv_configure(const char *xmlstring, WRBUF w) { xmlDocPtr doc = xmlParseMemory(xmlstring, strlen(xmlstring)); if (!doc) { wrbuf_printf(w, "xmlParseMemory"); return 0; } else { xmlNodePtr ptr = xmlDocGetRootElement(doc); yaz_retrieval_t p = yaz_retrieval_create(); if (p) { const char *srcdir = getenv("srcdir"); if (srcdir) yaz_retrieval_set_path(p, srcdir); } if (!ptr) { wrbuf_printf(w, "xmlDocGetRootElement"); yaz_retrieval_destroy(p); p = 0; } else if (!p) { wrbuf_printf(w, "yaz_retrieval_create"); } else { int r = yaz_retrieval_configure(p, ptr); if (r) { wrbuf_puts(w, yaz_retrieval_get_error(p)); yaz_retrieval_destroy(p); p = 0; } } xmlFreeDoc(doc); return p; } } int conv_configure_test(const char *xmlstring, const char *expect_error, yaz_retrieval_t *pt) { WRBUF w = wrbuf_alloc(); int ret; yaz_retrieval_t p = conv_configure(xmlstring, w); if (!p) { if (expect_error && !strcmp(wrbuf_cstr(w), expect_error)) ret = 1; else { ret = 0; printf("%s\n", wrbuf_cstr(w)); } } else { if (expect_error) { ret = 0; yaz_retrieval_destroy(p); } else { if (pt) *pt = p; else yaz_retrieval_destroy(p); ret = 1; } } wrbuf_destroy(w); return ret; } static void tst_configure(void) { YAZ_CHECK(conv_configure_test("", "Expected element ", 0)); YAZ_CHECK(conv_configure_test("", 0, 0)); YAZ_CHECK(conv_configure_test("", "Element :" " expected element , got ", 0)); YAZ_CHECK(conv_configure_test("" "", "Missing 'syntax' attribute", 0)); YAZ_CHECK(conv_configure_test("" "" "" "", "Element : expected attributes " "'syntax', identifier' or 'name', got " "'unknown'", 0)); YAZ_CHECK(conv_configure_test("" "" "" "", "Element : unknown attribute " "value syntax='unknown_synt'", 0)); YAZ_CHECK(conv_configure_test("" "" "", 0, 0)); YAZ_CHECK(conv_configure_test("" "" "", 0, 0)); YAZ_CHECK(conv_configure_test("" "" "", 0, 0)); YAZ_CHECK(conv_configure_test("" "" "" "" "", "Element : expected zero or one element " ", got ", 0)); YAZ_CHECK(conv_configure_test("" "" " " "" "", "Element : expected attributes 'syntax' or 'name," " got 'schema'", 0)); YAZ_CHECK(conv_configure_test("" "" " " "" "", 0, 0)); YAZ_CHECK(conv_configure_test("" "" " " "" "", "Element : " "attribute 'syntax' has invalid value " "'unknown'", 0)); YAZ_CHECK(conv_configure_test("" "" " " "" "", "Element : expected attributes " "'syntax' or 'name, got 'unknown'", 0)); YAZ_CHECK(conv_configure_test("" "" "" "" "" "" "" "", "Element : Unsupported character" " set mapping defined by attribute values", 0)); YAZ_CHECK(conv_configure_test("" "" "" "" "" "" "" "", "Element : Unsupported" " input format defined by attribute value", 0)); YAZ_CHECK(conv_configure_test("" "" "" "" "" "" "" "" "", "Element : " "only one allowed", 0)); YAZ_CHECK(conv_configure_test("" "" "" "" "" "" "" "", 0, 0)); YAZ_CHECK(conv_configure_test( "" "" "" "" "" " " " " " " "" "" " " " " " " "" "" " " " " " " " " "" "", 0, 0)); } #endif int main(int argc, char **argv) { YAZ_CHECK_INIT(argc, argv); yaz_log_xml_errors(0, 0 /* disable it */); #if YAZ_HAVE_XSLT tst_configure(); #endif YAZ_CHECK_TERM; } /* * Local variables: * c-basic-offset: 4 * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab */