From 9d74b82276b2e844ffe8b9f59763da62d877e3a7 Mon Sep 17 00:00:00 2001 From: Dennis Schafroth Date: Mon, 1 Oct 2012 14:38:53 +0200 Subject: [PATCH] Test for solr sort specs --- test/test_sortspec.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test/test_sortspec.c b/test/test_sortspec.c index 86f99d6..516c372 100644 --- a/test/test_sortspec.c +++ b/test/test_sortspec.c @@ -107,7 +107,7 @@ static int type7(const char *arg, const char *expected_result) return ret; } -static int srw_sortkeys(const char *arg, const char *expected_result) +static int strategy_sortkeys(const char *arg, const char *expected_result, int (*strategy) (Z_SortKeySpecList *, WRBUF)) { ODR odr = odr_createmem(ODR_ENCODE); Z_SortKeySpecList *sort_spec = yaz_sort_spec(odr, arg); @@ -120,7 +120,7 @@ static int srw_sortkeys(const char *arg, const char *expected_result) else { WRBUF w = wrbuf_alloc(); - int r = yaz_sort_spec_to_srw_sortkeys(sort_spec, w); + int r = (strategy)(sort_spec, w); if (!expected_result && r) ret = 1; @@ -153,6 +153,16 @@ static int srw_sortkeys(const char *arg, const char *expected_result) return ret; } +static int srw_sortkeys(const char *arg, const char *expected_result) { + return strategy_sortkeys(arg, expected_result, yaz_sort_spec_to_srw_sortkeys); +} + +static int solr_sortkeys(const char *arg, const char *expected_result) { + return strategy_sortkeys(arg, expected_result, yaz_sort_spec_to_solr_sortkeys); +} + + + static int check_srw_sortkeys_to_sort_spec(const char *arg, const char *expected_result) { @@ -222,6 +232,12 @@ static void tst(void) YAZ_CHECK(check_srw_sortkeys_to_sort_spec( "date,,1,0,1900", "date ai=1900")); + + YAZ_CHECK(solr_sortkeys("title a", + "title asc")); + YAZ_CHECK(solr_sortkeys("title a date ds", + "title asc, date desc")); + YAZ_CHECK(solr_sortkeys("1=4,2=3 a", 0)); } int main(int argc, char **argv) -- 1.7.10.4