X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=test%2Ftstxmlquery.c;h=fb0fddba3fe282187a1815aa637d2f1d6d196c17;hb=7e156f9a105b894b600c78d0b0a55224ae9b9793;hp=68a86b57c49b9c653381d5eadbb0e4d65bac6392;hpb=be1157fee3451c37508c9ec3b4b4b8603a646c0b;p=yaz-moved-to-github.git diff --git a/test/tstxmlquery.c b/test/tstxmlquery.c index 68a86b5..fb0fddb 100644 --- a/test/tstxmlquery.c +++ b/test/tstxmlquery.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: tstxmlquery.c,v 1.3 2006-01-27 19:04:15 adam Exp $ + * $Id: tstxmlquery.c,v 1.8 2006-02-02 15:00:58 adam Exp $ */ #include @@ -13,11 +13,25 @@ #include #include -static void pqf2xml_text(const char *pqf) +#if HAVE_XML2 +#include +#include +#endif + +enum pqf2xml_status { + PQF_FAILED, + QUERY2XML_FAILED, + XML_NO_MATCH, + XML_MATCH, + XML_NO_ERROR +}; + +enum pqf2xml_status pqf2xml_text(const char *pqf, const char *expect_xml) { YAZ_PQF_Parser parser = yaz_pqf_create(); ODR odr = odr_createmem(ODR_ENCODE); Z_RPNQuery *rpn; + enum pqf2xml_status status = XML_NO_ERROR; YAZ_CHECK(parser); @@ -25,28 +39,149 @@ static void pqf2xml_text(const char *pqf) rpn = yaz_pqf_parse(parser, odr, pqf); - YAZ_CHECK(rpn); - yaz_pqf_destroy(parser); - Z_Query *query = odr_malloc(odr, sizeof(*query)); - query->which = Z_Query_type_1; - query->u.type_1 = rpn; - - odr_destroy(odr); + if (!rpn) + status = PQF_FAILED; + else + { #if HAVE_XML2 + xmlDocPtr doc = 0; + + yaz_rpnquery2xml(rpn, &doc); + + if (!doc) + status = QUERY2XML_FAILED; + else + { + char *buf_out; + int len_out; + + xmlDocDumpMemory(doc, (xmlChar **) &buf_out, &len_out); + + if (len_out == strlen(expect_xml) + && memcmp(buf_out, expect_xml, len_out) == 0) + { + status = XML_MATCH; + } + else + { + printf("%.*s\n", len_out, buf_out); + status = XML_NO_MATCH; + } + xmlFreeDoc(doc); + } +#else + status = QUERY2XML_FAILED; +#endif + } + odr_destroy(odr); + return status; +} +void tst() +{ + YAZ_CHECK_EQ(pqf2xml_text("@attr 1=4 bad query", ""), PQF_FAILED); +#if HAVE_XML2 + YAZ_CHECK_EQ(pqf2xml_text( + "@attr 1=4 computer", + "\n" + "" + "" + "computer" + "\n"), XML_MATCH); + + YAZ_CHECK_EQ(pqf2xml_text( + "@attr 2=1 @attr 1=title computer", + "\n" + "" + "" + "" + "computer" + "\n"), XML_MATCH); + + YAZ_CHECK_EQ(pqf2xml_text( + "@attr 2=1 @attr exp1 1=1 computer", + "\n" + "" + "" + "" + "computer" + "\n"), XML_MATCH); + + YAZ_CHECK_EQ(pqf2xml_text( + "@and a b", + "\n" + "" + "" + "a" + "b" + "\n"), XML_MATCH); + + YAZ_CHECK_EQ(pqf2xml_text( + "@or @and a b c", + "\n" + "" + "" + "" + "a" + "b" + "c" + "\n"), XML_MATCH); + + YAZ_CHECK_EQ(pqf2xml_text( + "@set abe", + "\n" + "" + "abe\n"), XML_MATCH); + + YAZ_CHECK_EQ(pqf2xml_text( + /* exclusion, distance, ordered, relationtype, + knownunit, proxunit */ + "@prox 0 3 1 2 k 2 a b", + "\n" + "" + "" + "a" + "b" + "\n"), XML_MATCH); + + YAZ_CHECK_EQ(pqf2xml_text( + "@term numeric 32", + "\n" + "" + "" + "32" + "\n"), XML_MATCH); + + YAZ_CHECK_EQ(pqf2xml_text( + "@term string computer", + "\n" + "" + "" + "computer" + "\n"), XML_MATCH); + + YAZ_CHECK_EQ(pqf2xml_text( + "@term null void", + "\n" + "" + "" + "" + "\n"), XML_MATCH); + #endif } int main (int argc, char **argv) { YAZ_CHECK_INIT(argc, argv); - - pqf2xml_text("@attr 1=4 computer"); - - exit(0); - return 0; + tst(); + YAZ_CHECK_TERM; } /*