From 2dbb55981b7169e8e3957e2ea2ea3f7fd5aea530 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 24 Nov 2011 14:17:07 +0100 Subject: [PATCH] Add tests of CQL to CCL+sortkeys conversion --- test/test_cql2ccl.c | 96 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 86 insertions(+), 10 deletions(-) diff --git a/test/test_cql2ccl.c b/test/test_cql2ccl.c index c2bb9e3..e2f9b5f 100644 --- a/test/test_cql2ccl.c +++ b/test/test_cql2ccl.c @@ -12,16 +12,17 @@ #include #include - -static int tst_query(const char *cql, const char *expected_ccl) +static int tst_query_s(const char *cql, const char *expected_ccl, + const char *expected_keys) { - int ret = 0; + int ret = 1; CQL_parser cp = cql_parser_create(); int r = cql_parser_string(cp, cql); if (r) { yaz_log(YLOG_WARN, "cql: parse error: %s", cql); + ret = 0; } else { /* cql parse OK */ @@ -29,21 +30,51 @@ static int tst_query(const char *cql, const char *expected_ccl) r = cql_to_ccl(cql_parser_result(cp), wrbuf_vp_puts, w); if (expected_ccl && r == 0 && strcmp(wrbuf_cstr(w), expected_ccl) == 0) + ; + else if (!expected_ccl) { - ret = 1; + if (!r) + { + ret = 0; + yaz_log(YLOG_WARN, "cql: diff %s", cql); + yaz_log(YLOG_WARN, " exp error"); + yaz_log(YLOG_WARN, " got ccl %s", wrbuf_cstr(w)); + } } - else if (!expected_ccl) + else { - if (r) - ret = 1; /* expected conversion error, OK */ + ret = 0; + yaz_log(YLOG_WARN, "cql: diff: %s", cql); + yaz_log(YLOG_WARN, " exp ccl %s", expected_ccl); + if (!r) + yaz_log(YLOG_WARN, " got ccl %s", wrbuf_cstr(w)); else - yaz_log(YLOG_WARN, "cql: expected conversion error: %s", cql); + yaz_log(YLOG_WARN, " got error"); + } + wrbuf_rewind(w); + r = cql_sortby_to_sortkeys(cql_parser_result(cp), + wrbuf_vp_puts, w); + if (expected_keys && !r && !strcmp(wrbuf_cstr(w), expected_keys)) + ; + else if (!expected_keys) + { + if (!r) + { + ret = 0; + yaz_log(YLOG_WARN, "cql: diff: %s", cql); + yaz_log(YLOG_WARN, " exp error"); + yaz_log(YLOG_WARN, " got sortkeys %s", wrbuf_cstr(w)); + } } else { + ret = 0; yaz_log(YLOG_WARN, "cql: diff: %s", cql); - yaz_log(YLOG_WARN, " expected %s", expected_ccl); - yaz_log(YLOG_WARN, " got %s", wrbuf_cstr(w)); + yaz_log(YLOG_WARN, " exp sortkeys %s", expected_keys); + if (!r) + yaz_log(YLOG_WARN, " got sortkeys %s", wrbuf_cstr(w)); + else + yaz_log(YLOG_WARN, " got error"); } wrbuf_destroy(w); } @@ -51,6 +82,11 @@ static int tst_query(const char *cql, const char *expected_ccl) return ret; } +static int tst_query(const char *cql, const char *expected_ccl) +{ + return tst_query_s(cql, expected_ccl, ""); +} + static void tst(void) { YAZ_CHECK(tst_query("\"\"", "\"\"")); @@ -103,6 +139,46 @@ static void tst(void) YAZ_CHECK(tst_query("title any \"x y\"", "title=\"x\" or title=\"y\"")); YAZ_CHECK(tst_query("dc.title=encyclopedia prox dinosaurs", "(dc.title=\"encyclopedia\") % (\"dinosaurs\")")); + YAZ_CHECK(tst_query("dc.title=encyclopedia prox/distance<=3 dinosaurs", + "(dc.title=\"encyclopedia\") %3 (\"dinosaurs\")")); + YAZ_CHECK(tst_query("dc.title=encyclopedia prox/distance<=3/unit=word " + "dinosaurs", + "(dc.title=\"encyclopedia\") %3 (\"dinosaurs\")")); + YAZ_CHECK(tst_query("dc.title=encyclopedia prox/distance<=3/unit=phrase " + "dinosaurs", 0)); + YAZ_CHECK(tst_query("dc.title=encyclopedia prox/distance<=3/a=b " + "dinosaurs", 0)); + YAZ_CHECK(tst_query("dc.title=encyclopedia prox/a=b dinosaurs", 0)); + YAZ_CHECK(tst_query("dc.title=encyclopedia prox/distance<3 dinosaurs", + "(dc.title=\"encyclopedia\") %2 (\"dinosaurs\")")); + YAZ_CHECK(tst_query("dc.title=encyclopedia prox/distance=3 dinosaurs", 0)); + YAZ_CHECK(tst_query("dc.title=encyclopedia prox/distance>3 dinosaurs", 0)); + YAZ_CHECK(tst_query("dc.title=encyclopedia prox/distance>=3 dinosaurs", 0)); + YAZ_CHECK(tst_query_s("a sortby title", "\"a\"", + "title,,1,0,highValue")); + YAZ_CHECK(tst_query_s("a sortby dc.title", "\"a\"", + "title,dc,1,0,highValue")); + YAZ_CHECK(tst_query_s("a sortby title/ascending", "\"a\"", + "title,,1,0,highValue")); + YAZ_CHECK(tst_query_s("a sortby title/descending", "\"a\"", + "title,,0,0,highValue")); + YAZ_CHECK(tst_query_s("a sortby title/ignoreCase", "\"a\"", + "title,,1,0,highValue")); + YAZ_CHECK(tst_query_s("a sortby title/respectCase", "\"a\"", + "title,,1,1,highValue")); + YAZ_CHECK(tst_query_s("a sortby title/missingOmit", "\"a\"", + "title,,1,0,omit")); + YAZ_CHECK(tst_query_s("a sortby title/missingFail", "\"a\"", + "title,,1,0,abort")); + YAZ_CHECK(tst_query_s("a sortby title/missingLow", "\"a\"", + "title,,1,0,lowValue")); + YAZ_CHECK(tst_query_s("a sortby title/missingHigh", "\"a\"", + "title,,1,0,highValue")); + YAZ_CHECK(tst_query_s("a sortby title/bogus", "\"a\"", 0)); + + YAZ_CHECK(tst_query_s("a sortby dc.year dc.author", "\"a\"", + "year,dc,1,0,highValue author,dc,1,0,highValue")); + } int main(int argc, char **argv) -- 1.7.10.4