X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=test%2Ftstxmlquery.c;h=dd6729e2138ed8b8b101ecde7ccab71b032b8274;hb=ef37a4f4d009b879da200f74b6cf5a7a15ae0e53;hp=68a86b57c49b9c653381d5eadbb0e4d65bac6392;hpb=be1157fee3451c37508c9ec3b4b4b8603a646c0b;p=yaz-moved-to-github.git diff --git a/test/tstxmlquery.c b/test/tstxmlquery.c index 68a86b5..dd6729e 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.7 2006-01-31 11:01:26 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,16 +39,113 @@ 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; - + 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" + "" + "" + "ab" + "\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" + "" + "" + "ab" + "\n"), XML_MATCH); #endif } @@ -42,11 +153,8 @@ static void pqf2xml_text(const char *pqf) 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; } /*