2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tstpquery.c,v 1.3 2006-10-04 16:59:34 mike Exp $
11 #include <yaz/wrbuf.h>
12 #include <yaz/querytowrbuf.h>
13 #include <yaz/pquery.h>
16 int expect_pqf(const char *pqf, const char *expect_pqf, int expect_error)
18 YAZ_PQF_Parser parser = yaz_pqf_create();
20 ODR odr = odr_createmem(ODR_ENCODE);
29 rpn = yaz_pqf_parse(parser, odr, pqf);
35 int got_error = yaz_pqf_error (parser, &msg, &offset);
37 if (expect_error == got_error)
40 else if (expect_error == YAZ_PQF_ERROR_NONE)
42 WRBUF wrbuf = wrbuf_alloc();
46 yaz_rpnquery_to_wrbuf(wrbuf, rpn);
48 if (!strcmp(wrbuf_buf(wrbuf), expect_pqf))
53 yaz_pqf_destroy(parser);
60 YAZ_CHECK(expect_pqf("a", "@attrset Bib-1 a", YAZ_PQF_ERROR_NONE));
61 YAZ_CHECK(expect_pqf("@attr 1=4 a", "@attrset Bib-1 @attr 1=4 a", YAZ_PQF_ERROR_NONE));
62 YAZ_CHECK(expect_pqf("a b", "", YAZ_PQF_ERROR_EXTRA));
63 YAZ_CHECK(expect_pqf("@and a", "", YAZ_PQF_ERROR_MISSING));
64 YAZ_CHECK(expect_pqf("@attr p=q a", "", YAZ_PQF_ERROR_BAD_INTEGER));
65 YAZ_CHECK(expect_pqf("@prox 0 0 0 0 k 0 a b",
66 "@attrset Bib-1 @prox 0 0 0 0 k 0 a b",
68 YAZ_CHECK(expect_pqf("@prox 0 0 0 0 3 0 a b", "",
69 YAZ_PQF_ERROR_PROXIMITY));
72 int main (int argc, char **argv)
74 YAZ_CHECK_INIT(argc, argv);
82 * indent-tabs-mode: nil
84 * vim: shiftwidth=4 tabstop=8 expandtab