--- /dev/null
+/* $Id: t11.c,v 1.1 2005-05-02 09:05:22 adam Exp $
+ Copyright (C) 1995-2005
+ Index Data ApS
+
+This file is part of the Zebra server.
+
+Zebra is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Zebra; see the file LICENSE.zebra. If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+*/
+
+/** testing of scan */
+#include "testlib.h"
+
+const char *myrec[] = {
+ "<gils>\n<title>a b</title>\n</gils>\n",
+ "<gils>\n<title>c d</title>\n</gils>\n",
+ "<gils>\n<title>e f</title>\n</gils>\n" ,
+ 0} ;
+
+int main(int argc, char **argv)
+{
+ ZebraService zs = start_up(0, argc, argv);
+ ZebraHandle zh = zebra_open(zs);
+
+ init_data(zh, myrec);
+
+ if (1)
+ {
+ /* scan before. nothing must be returned */
+ const char *ent[] = { "a", 0 };
+ do_scan(__LINE__, zh, "@attr 1=4 0", 1, 1, 1, 1, 0, ent);
+ }
+ if (1)
+ {
+ /* scan after. nothing must be returned */
+ do_scan(__LINE__, zh, "@attr 1=4 m", 1, 1, 1, 0, 1, 0);
+ }
+ if (1)
+ {
+ const char *ent[] = { "a", 0 };
+ do_scan(__LINE__, zh, "@attr 1=4 a", 1, 1, 1, 1, 0, ent);
+ }
+ if (1)
+ {
+ const char *ent[] = { "b", "c", 0 };
+ do_scan(__LINE__, zh, "@attr 1=4 aa", 1, 2, 1, 2, 0, ent);
+ }
+ if (1)
+ {
+ const char *ent[] = { "b", "c", 0 };
+ do_scan(__LINE__, zh, "@attr 1=4 aa", 1, 2, 1, 2, 0, ent);
+ }
+ if (1)
+ {
+ const char *ent[] = { "e", "f", 0 };
+ do_scan(__LINE__, zh, "@attr 1=4 e", 1, 3, 1, 2, 1, ent);
+ }
+ if (1)
+ {
+ const char *ent[] = { "c", "d", 0 };
+ do_scan(__LINE__, zh, "@attr 1=4 a", -1, 2, -1, 2, 0, ent);
+ }
+ if (1)
+ {
+ const char *ent[] = { "d", 0 };
+ do_scan(__LINE__, zh, "@attr 1=4 a", -2, 1, -2, 1, 0, ent);
+ }
+ if (1)
+ {
+ const char *ent[] = { "d", "e", "f", 0 };
+ do_scan(__LINE__, zh, "@attr 1=4 a", -2, 3, -2, 3, 0, ent);
+ }
+ if (1)
+ {
+ const char *ent[] = { "d", "e", "f", 0 };
+ do_scan(__LINE__, zh, "@attr 1=4 a", -2, 4, -2, 3, 1, ent);
+ }
+ if (1)
+ {
+ const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 };
+ do_scan(__LINE__, zh, "@attr 1=4 0", 2, 100, 1, 6, 1, ent);
+ }
+ if (1)
+ {
+ const char *ent[] = { "b", "c", "d", "e", "f", 0 };
+ do_scan(__LINE__, zh, "@attr 1=4 0", 0, 100, 0, 5, 1, ent);
+ }
+ if (1)
+ {
+ const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 };
+ do_scan(__LINE__, zh, "@attr 1=4 0", 10, 100, 1, 6, 1, ent);
+ }
+ if (1)
+ {
+ const char *ent[] = { "a", "b", "c", "d", "e", "f", 0 };
+ do_scan(__LINE__, zh, "@attr 1=4 0", 100, 10, 1, 6, 1, ent);
+ }
+ if (1)
+ {
+ do_scan(__LINE__, zh, "@attr 1=4 z", -100, 10, 1, 6, 1, 0);
+ }
+ return close_down(zh, zs, 0);
+}
-/* $Id: testlib.c,v 1.15 2005-05-01 07:17:47 adam Exp $
+/* $Id: testlib.c,v 1.16 2005-05-02 09:05:22 adam Exp $
Copyright (C) 1995-2005
Index Data ApS
return do_query_x(lineno, zh, query, exphits, 0);
}
+void do_scan(int lineno, ZebraHandle zh, const char *query,
+ int pos, int num,
+ int exp_pos, int exp_num, int exp_partial,
+ const char **exp_entries)
+{
+ ODR odr = odr_createmem(ODR_ENCODE);
+ ZebraScanEntry *entries = 0;
+ int partial = -123;
+ ZEBRA_RES res;
+
+ yaz_log(log_level, "======================================");
+ yaz_log(log_level, "scan[%d]: pos=%d num=%d %s", lineno, pos, num, query);
+
+ res = zebra_scan_PQF(zh, odr, query, &pos, &num, &entries, &partial);
+ if (res != ZEBRA_OK)
+ {
+ printf("Error: scan returned %d (FAIL), but no error was expected\n"
+ "%s\n", res, query);
+ exit(1);
+ }
+ else
+ {
+ int fails = 0;
+ if (partial == -123)
+ {
+ printf("Error: scan returned OK, but partial was not set\n"
+ "%s\n", query);
+ fails++;
+ }
+ if (partial != exp_partial)
+ {
+ printf("Error: scan returned OK, with partial/expected %d/%d\n"
+ "%s\n", partial, exp_partial, query);
+ fails++;
+ }
+ if (num != exp_num)
+ {
+ printf("Error: scan returned OK, with num/expected %d/%d\n"
+ "%s\n", num, exp_num, query);
+ fails++;
+ }
+ if (pos != exp_pos)
+ {
+ printf("Error: scan returned OK, with pos/expected %d/%d\n"
+ "%s\n", pos, exp_pos, query);
+ fails++;
+ }
+ if (fails)
+ exit(1);
+ fails = 0;
+ if (exp_entries)
+ {
+ int i;
+ for (i = 0; i<num; i++)
+ {
+ if (strcmp(exp_entries[i], entries[i].term))
+ {
+ printf("Error: scan OK, but entry %d term/exp %s/%s\n"
+ "%s\n",
+ i, entries[i].term, exp_entries[i], query);
+ fails++;
+ }
+ }
+ }
+ if (fails)
+ exit(0);
+ }
+ odr_destroy(odr);
+}
/**
* makes a query, checks number of hits, and for the first hit, that