1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
13 #include <yaz/wrbuf.h>
14 #include <yaz/querytowrbuf.h>
15 #include <yaz/pquery.h>
18 int expect_pqf(const char *pqf, const char *expect_pqf, int expect_error)
20 YAZ_PQF_Parser parser = yaz_pqf_create();
22 ODR odr = odr_createmem(ODR_ENCODE);
31 rpn = yaz_pqf_parse(parser, odr, pqf);
37 int got_error = yaz_pqf_error (parser, &msg, &offset);
39 if (expect_error == got_error)
42 else if (expect_error == YAZ_PQF_ERROR_NONE)
44 WRBUF wrbuf = wrbuf_alloc();
48 yaz_rpnquery_to_wrbuf(wrbuf, rpn);
50 if (!strcmp(wrbuf_cstr(wrbuf), expect_pqf))
57 yaz_pqf_destroy(parser);
64 YAZ_CHECK(expect_pqf("a", "@attrset Bib-1 a", YAZ_PQF_ERROR_NONE));
65 YAZ_CHECK(expect_pqf("@attr 1=4 a", "@attrset Bib-1 @attr 1=4 a", YAZ_PQF_ERROR_NONE));
66 YAZ_CHECK(expect_pqf("@attr 1=title a", "@attrset Bib-1 @attr 1=title a", YAZ_PQF_ERROR_NONE));
67 YAZ_CHECK(expect_pqf("a b", "", YAZ_PQF_ERROR_EXTRA));
68 YAZ_CHECK(expect_pqf("@and a", "", YAZ_PQF_ERROR_MISSING));
69 YAZ_CHECK(expect_pqf("@attr p=q a", "", YAZ_PQF_ERROR_BAD_INTEGER));
70 YAZ_CHECK(expect_pqf("@prox 0 0 0 0 k 0 a b",
71 "@attrset Bib-1 @prox 0 0 0 0 k 0 a b",
73 YAZ_CHECK(expect_pqf("@prox 0 0 0 0 3 0 a b", "",
74 YAZ_PQF_ERROR_PROXIMITY));
75 YAZ_CHECK(expect_pqf("@attr 1=12345678901 x", "@attrset Bib-1 @attr 1=12345678901 x", YAZ_PQF_ERROR_NONE));
76 YAZ_CHECK(expect_pqf("@attr 1=1234567890.1 x", "@attrset Bib-1 @attr 1=1234567890.1 x", YAZ_PQF_ERROR_NONE));
79 int main (int argc, char **argv)
81 YAZ_CHECK_INIT(argc, argv);
89 * c-file-style: "Stroustrup"
90 * indent-tabs-mode: nil
92 * vim: shiftwidth=4 tabstop=8 expandtab