+static int srw_sortkeys(const char *arg, const char *expected_result)
+{
+ ODR odr = odr_createmem(ODR_ENCODE);
+ Z_SortKeySpecList *sort_spec = yaz_sort_spec(odr, arg);
+ int ret = 0;
+
+ if (!sort_spec)
+ {
+ yaz_log(YLOG_WARN, "yaz_sort_spec : parse error: %s", arg);
+ }
+ else
+ {
+ WRBUF w = wrbuf_alloc();
+ int r = yaz_sort_spec_to_srw_sortkeys(sort_spec, w);
+
+ if (!expected_result && r)
+ ret = 1;
+ else if (expected_result && r == 0)
+ {
+ if (strcmp(wrbuf_cstr(w), expected_result) == 0)
+ ret = 1;
+ else
+ {
+ yaz_log(YLOG_WARN, "sort: diff: %s", arg);
+ yaz_log(YLOG_WARN, " expected %s", expected_result);
+ yaz_log(YLOG_WARN, " got %s", wrbuf_cstr(w));
+ }
+ }
+ else if (r)
+ {
+ yaz_log(YLOG_WARN, "sort: diff %s", arg);
+ yaz_log(YLOG_WARN, " expected %s", expected_result);
+ yaz_log(YLOG_WARN, " got error %d", r);
+ }
+ else if (r == 0)
+ {
+ yaz_log(YLOG_WARN, "sort: diff %s", arg);
+ yaz_log(YLOG_WARN, " expected error");
+ yaz_log(YLOG_WARN, " got %s", wrbuf_cstr(w));
+ }
+ wrbuf_destroy(w);
+ }
+ odr_destroy(odr);
+ return ret;
+}
+