X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftest_rpn2cql.c;h=0d05fabd6a133f7fa7c37381b25b2ea673e64b14;hp=9a717c1a1fc7041f7f7f086556950684304eac59;hb=f0df1959fda559c0d952810c338a9fde667b5a63;hpb=84e48bf312354bb4bc3c9a122f2c48346776a4fa diff --git a/test/test_rpn2cql.c b/test/test_rpn2cql.c index 9a717c1..0d05fab 100644 --- a/test/test_rpn2cql.c +++ b/test/test_rpn2cql.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2013 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ #if HAVE_CONFIG_H @@ -15,7 +15,8 @@ #include #include -static int compare(cql_transform_t ct, const char *pqf, const char *cql) +static int compare2(cql_transform_t ct, const char *pqf, const char *cql, + int expected_error) { int ret = 0; ODR odr = odr_createmem(ODR_ENCODE); @@ -28,15 +29,26 @@ static int compare(cql_transform_t ct, const char *pqf, const char *cql) if (r != 0) { + const char *addinfo = 0; + int err = cql_transform_error(ct, &addinfo); /* transform error */ yaz_log(YLOG_LOG, "%s -> Error %d", pqf, r); - if (!cql) /* also expected error? */ - ret = 1; + if (err == 0) + ; + else if (err == expected_error) + { + if (addinfo && cql && !strcmp(addinfo, cql)) + ret = 1; + else if (!addinfo && !cql) + ret = 1; + } } else if (r == 0) { yaz_log(YLOG_LOG, "%s -> %s", pqf, wrbuf_cstr(w)); - if (cql && !strcmp(wrbuf_cstr(w), cql)) + if (!expected_error) + ret = 1; + else if (cql && !strcmp(wrbuf_cstr(w), cql)) { ret = 1; } @@ -52,6 +64,11 @@ static int compare(cql_transform_t ct, const char *pqf, const char *cql) return ret; } +static int compare(cql_transform_t ct, const char *pqf, const char *cql) +{ + return compare2(ct, pqf, cql, 0); +} + static void tst1(void) { cql_transform_t ct = cql_transform_create(); @@ -65,7 +82,7 @@ static void tst1(void) YAZ_CHECK(compare(ct, "@and @and a b @and c d", "(a and b) and (c and d)")); YAZ_CHECK(compare(ct, "@attr 1=field abc", "field=abc")); - YAZ_CHECK(compare(ct, "@attr 1=4 abc", 0)); /* should fail */ + YAZ_CHECK(compare2(ct, "@attr 1=4 abc", 0, 114)); /* should fail */ cql_transform_define_pattern(ct, "index.title", "1=4"); YAZ_CHECK(compare(ct, "@attr 1=4 abc", "title=abc")); @@ -151,7 +168,8 @@ static void tst2(void) /* Other */ YAZ_CHECK(compare(ct, "@attr 2=103 @attr 1=_ALLRECORDS 1", "cql.allRecords=1")); - YAZ_CHECK(compare(ct, "@attr 1=500 abc", 0)); + YAZ_CHECK(compare2(ct, "@attr 1=500 abc", 0, 114)); + YAZ_CHECK(compare2(ct, "@attr 5=99 x", "99", 120)); cql_transform_close(ct); wrbuf_destroy(w); }