X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=test%2Ftest_sortspec.c;h=7af40265c73fc93956e20ca5327cfc33d14ff0f4;hp=86f99d65b88ff69701b5867f5b8fcc1637e31bdd;hb=a6a0761adac3b5760765ee90c0146edf59f9f3ec;hpb=77c5a4fca8b516fd39b8ba213daed17a465a6b2a diff --git a/test/test_sortspec.c b/test/test_sortspec.c index 86f99d6..7af4026 100644 --- a/test/test_sortspec.c +++ b/test/test_sortspec.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2012 Index Data + * Copyright (C) 1995-2013 Index Data * See the file LICENSE for details. */ #if HAVE_CONFIG_H @@ -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,12 +153,22 @@ static int srw_sortkeys(const char *arg, const char *expected_result) return ret; } -static int check_srw_sortkeys_to_sort_spec(const char *arg, - const char *expected_result) +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_sortkeys_to_sort_spec(const char *arg, + const char *expected_result, int (*sort_strategy)(const char *, WRBUF)) { WRBUF w = wrbuf_alloc(); int ret = 0; - int r = yaz_srw_sortkeys_to_sort_spec(arg, w); + int r = sort_strategy(arg, w); if (!expected_result && r) ret = 1; @@ -189,6 +199,13 @@ static int check_srw_sortkeys_to_sort_spec(const char *arg, return ret; } +static int check_srw_sortkeys_to_sort_spec(const char *arg, const char *expected_result) { + return check_sortkeys_to_sort_spec(arg, expected_result, yaz_srw_sortkeys_to_sort_spec); +} + +static int check_solr_sortkeys_to_sort_spec(const char *arg, const char *expected_result) { + return check_sortkeys_to_sort_spec(arg, expected_result, yaz_solr_sortkeys_to_sort_spec); +} static void tst(void) { @@ -222,6 +239,18 @@ 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)); + + YAZ_CHECK(check_solr_sortkeys_to_sort_spec( + "date asc", + "date ai")); + } int main(int argc, char **argv)