*/
typedef struct cql_transform_t_ *cql_transform_t;
+/** \brief creates a CQL transform handle
+ \returns transform handle or NULL for failure
+*/
+YAZ_EXPORT
+cql_transform_t cql_transform_create(void);
+
/** \brief creates a CQL transform handle from am opened file handle
\param f file where transformation spec is read
\returns transform handle or NULL for failure
WRBUF w;
};
-cql_transform_t cql_transform_open_FILE(FILE *f)
+
+cql_transform_t cql_transform_create(void)
{
- char line[1024];
cql_transform_t ct = (cql_transform_t) xmalloc(sizeof(*ct));
- struct cql_prop_entry **pp = &ct->entry;
ct->tok_cfg = yaz_tok_cfg_create();
ct->w = wrbuf_alloc();
-
- yaz_tok_cfg_single_tokens(ct->tok_cfg, "=");
ct->error = 0;
ct->addinfo = 0;
+ ct->entry = 0;
+ return ct;
+}
+
+cql_transform_t cql_transform_open_FILE(FILE *f)
+{
+ cql_transform_t ct = cql_transform_create();
+ char line[1024];
+ struct cql_prop_entry **pp = &ct->entry;
+
+ yaz_tok_cfg_single_tokens(ct->tok_cfg, "=");
while (fgets(line, sizeof(line)-1, f))
{
check_PROGRAMS = tsticonv tstnmem tstmatchstr tstwrbuf tstodr tstccl tstlog \
tstsoap1 tstsoap2 tstodrstack tstlogthread tstxmlquery tstpquery \
tst_comstack tst_filepath tst_record_conv tst_retrieval tst_tpath \
- tst_timing tst_query_charset tst_oid tst_icu_I18N tst_match_glob
+ tst_timing tst_query_charset tst_oid tst_icu_I18N tst_match_glob tst_rpn2cql
check_SCRIPTS = tstmarc.sh tstmarccol.sh tstcql2xcql.sh tstcql2pqf.sh
TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
tst_query_charset_SOURCES = tst_query_charset.c
tst_icu_I18N_SOURCES = tst_icu_I18N.c
tst_match_glob_SOURCES = tst_match_glob.c
+tst_rpn2cql_SOURCES = tst_rpn2cql.c
--- /dev/null
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2008 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <yaz/test.h>
+#include <yaz/log.h>
+#include <yaz/rpn2cql.h>
+#include <yaz/wrbuf.h>
+#include <yaz/pquery.h>
+
+static int compare(cql_transform_t ct, const char *pqf, const char *cql)
+{
+ int ret = 0;
+ ODR odr = odr_createmem(ODR_ENCODE);
+ WRBUF w = wrbuf_alloc();
+ Z_RPNQuery *q = p_query_rpn(odr, pqf);
+
+ if (q)
+ {
+ int r = cql_transform_rpn2cql(ct, wrbuf_vputs, w, q);
+
+ if (r != 0)
+ {
+ /* transform error */
+ yaz_log(YLOG_LOG, "%s -> Error %d", pqf, r);
+ if (!cql) /* also expected error? */
+ ret = 1;
+ }
+ else if (r == 0)
+ {
+ yaz_log(YLOG_LOG, "%s -> %s", pqf, wrbuf_cstr(w));
+ if (cql && !strcmp(wrbuf_cstr(w), cql))
+ ret = 1;
+ }
+ }
+ wrbuf_destroy(w);
+ odr_destroy(odr);
+ return ret;
+}
+
+static void tst(void)
+{
+ cql_transform_t ct = cql_transform_create();
+ YAZ_CHECK(compare(ct, "abc", "abc"));
+ YAZ_CHECK(compare(ct, "@and a b", "a and b"));
+ cql_transform_close(ct);
+}
+
+int main (int argc, char **argv)
+{
+ YAZ_CHECK_INIT(argc, argv);
+ YAZ_CHECK_LOG();
+ tst();
+ YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+