X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftstxmlquery.c;h=c79f285a2a4dbb9d0fa0a2682e06a699ba953816;hp=fb0fddba3fe282187a1815aa637d2f1d6d196c17;hb=ba1eb985bfd53a8cfbfd251e65688921dba56236;hpb=465343e3b3f2cd797e018b26df19c91a39cbeccf diff --git a/test/tstxmlquery.c b/test/tstxmlquery.c index fb0fddb..c79f285 100644 --- a/test/tstxmlquery.c +++ b/test/tstxmlquery.c @@ -2,18 +2,19 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: tstxmlquery.c,v 1.8 2006-02-02 15:00:58 adam Exp $ + * $Id: tstxmlquery.c,v 1.13 2006-10-04 16:59:34 mike Exp $ */ #include #include #include +#include #include #include #include -#if HAVE_XML2 +#if YAZ_HAVE_XML2 #include #include #endif @@ -26,7 +27,8 @@ enum pqf2xml_status { XML_NO_ERROR }; -enum pqf2xml_status pqf2xml_text(const char *pqf, const char *expect_xml) +enum pqf2xml_status pqf2xml_text(const char *pqf, const char *expect_xml, + const char *expect_pqf) { YAZ_PQF_Parser parser = yaz_pqf_create(); ODR odr = odr_createmem(ODR_ENCODE); @@ -45,7 +47,7 @@ enum pqf2xml_status pqf2xml_text(const char *pqf, const char *expect_xml) status = PQF_FAILED; else { -#if HAVE_XML2 +#if YAZ_HAVE_XML2 xmlDocPtr doc = 0; yaz_rpnquery2xml(rpn, &doc); @@ -62,7 +64,30 @@ enum pqf2xml_status pqf2xml_text(const char *pqf, const char *expect_xml) if (len_out == strlen(expect_xml) && memcmp(buf_out, expect_xml, len_out) == 0) { - status = XML_MATCH; + Z_Query *query2 = 0; + int error_code = 0; + const char *addinfo = 0; + const xmlNode *root_element = xmlDocGetRootElement(doc); + ODR odr2 = odr_createmem(ODR_ENCODE); + + yaz_xml2query(root_element, &query2, odr2, + &error_code, &addinfo); + if (error_code || !query2) + status = XML_NO_MATCH; + else + { + WRBUF w = wrbuf_alloc(); + yaz_query_to_wrbuf(w, query2); + if (!expect_pqf || strcmp(expect_pqf, wrbuf_buf(w)) == 0) + status = XML_MATCH; + else + { + status = XML_NO_MATCH; + printf("Result: %s\n", wrbuf_buf(w)); + } + wrbuf_free(w, 1); + } + odr_destroy(odr2); } else { @@ -79,101 +104,131 @@ enum pqf2xml_status pqf2xml_text(const char *pqf, const char *expect_xml) return status; } -void tst() +static void tst(void) { - YAZ_CHECK_EQ(pqf2xml_text("@attr 1=4 bad query", ""), PQF_FAILED); -#if HAVE_XML2 + YAZ_CHECK_EQ(pqf2xml_text("@attr 1=4 bad query", "", 0), PQF_FAILED); +#if YAZ_HAVE_XML2 YAZ_CHECK_EQ(pqf2xml_text( "@attr 1=4 computer", "\n" - "" + "" "" "computer" - "\n"), XML_MATCH); + "\n", + "RPN @attrset Bib-1 @attr 1=4 computer" + ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@attr 2=1 @attr 1=title computer", "\n" - "" + "" "" "" "computer" - "\n"), XML_MATCH); + "\n", + "RPN @attrset Bib-1 @attr \"1=title\" @attr 2=1 computer" + ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@attr 2=1 @attr exp1 1=1 computer", "\n" - "" + "" "" "" "computer" - "\n"), XML_MATCH); + "\n", + "RPN @attrset Bib-1 @attr Exp-1 1=1 @attr 2=1 computer" + ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@and a b", "\n" - "" - "" + "" + "" "a" "b" - "\n"), XML_MATCH); + "\n", + "RPN @attrset Bib-1 @and a b" + ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@or @and a b c", "\n" - "" - "" - "" + "" + "" + "" "a" - "b" + "b" "c" - "\n"), XML_MATCH); + "\n", + "RPN @attrset Bib-1 @or @and a b c" + ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@set abe", "\n" - "" - "abe\n"), XML_MATCH); + "" + "abe\n", + "RPN @attrset Bib-1 @set abe" + ), 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); + "\n", + "RPN @attrset Bib-1 @prox 0 3 1 2 k 2 a b" + ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@term numeric 32", "\n" - "" + "" "" "32" - "\n"), XML_MATCH); + "\n", + "RPN @attrset Bib-1 @term numeric 32" + ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@term string computer", "\n" - "" + "" "" "computer" - "\n"), XML_MATCH); + "\n", + "RPN @attrset Bib-1 @term string computer" + ), XML_MATCH); YAZ_CHECK_EQ(pqf2xml_text( "@term null void", "\n" - "" + "" "" "" - "\n"), XML_MATCH); - + "\n", + "RPN @attrset Bib-1 @term null x" + ), XML_MATCH); + + YAZ_CHECK_EQ(pqf2xml_text( + "@attrset gils @attr 4=2 x", + "\n" + "" + "" + "" + "x" + "\n", + "RPN @attrset GILS @attr 4=2 x" + ), XML_MATCH); #endif }