+int tl_scan(ZebraHandle zh, const char *query,
+ int pos, int num,
+ int exp_pos, int exp_num, int exp_partial,
+ const char **exp_entries)
+{
+ int ret = 1;
+ ODR odr = odr_createmem(ODR_ENCODE);
+ ZebraScanEntry *entries = 0;
+ int partial = -123;
+ ZEBRA_RES res;
+
+ yaz_log(log_level, "======================================");
+ yaz_log(log_level, "scan: pos=%d num=%d %s", pos, num, query);
+
+ res = zebra_scan_PQF(zh, odr, query, &pos, &num, &entries, &partial,
+ 0 /* setname */);
+
+ if (partial == -123)
+ {
+ printf("Error: scan returned OK, but partial was not set\n"
+ "%s\n", query);
+ ret = 0;
+ }
+ if (partial != exp_partial)
+ {
+ printf("Error: scan OK, with partial/expected %d/%d\n",
+ partial, exp_partial);
+ ret = 0;
+ }
+ if (res != ZEBRA_OK) /* failure */
+ {
+ if (exp_entries)
+ {
+ printf("Error: scan failed, but no error was expected\n");
+ ret = 0;
+ }
+ }
+ else
+ {
+ if (!exp_entries)
+ {
+ printf("Error: scan OK, but error was expected\n");
+ ret = 0;
+ }
+ else
+ {
+ int fails = 0;
+ if (num != exp_num)
+ {
+ printf("Error: scan OK, with num/expected %d/%d\n",
+ num, exp_num);
+ fails++;
+ }
+ if (pos != exp_pos)
+ {
+ printf("Error: scan OK, with pos/expected %d/%d\n",
+ pos, exp_pos);
+ fails++;
+ }
+ if (!fails)
+ {
+ if (exp_entries)
+ {
+ int i;
+ for (i = 0; i<num; i++)
+ {
+ if (strcmp(exp_entries[i], entries[i].term))
+ {
+ printf("Error: scan OK of %s, no %d got=%s exp=%s\n",
+ query, i, entries[i].term, exp_entries[i]);
+ fails++;
+ }
+ }
+ }
+ }
+ if (fails)
+ ret = 0;
+ }
+ }
+ odr_destroy(odr);
+ return ret;
+}