Allow record subsystem to return system numbers (document ID) with a fake
[idzebra-moved-to-github.git] / test / api / testlib.c
index aee77dc..e5a7745 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: testlib.c,v 1.21 2005-05-31 07:22:20 adam Exp $
+/* $Id: testlib.c,v 1.25 2005-08-09 12:30:47 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -22,6 +22,16 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 /** testlib - utilities for the api tests */
 
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#if HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
 #include <assert.h>
 #include <yaz/log.h>
 #include <yaz/pquery.h>
@@ -59,6 +69,14 @@ void start_log(int argc, char **argv)
  */
 ZebraService start_up(char *cfgname, int argc, char **argv)
 {
+#if HAVE_SYS_RESOURCE_H
+#if HAVE_SYS_TIME_H
+    struct rlimit rlim;
+    rlim.rlim_cur = 20;
+    rlim.rlim_max = 20;
+    setrlimit(RLIMIT_CPU, &rlim);
+#endif
+#endif
     nmem_init();
     start_log(argc, argv);
     return start_service(cfgname);
@@ -220,7 +238,8 @@ void do_scan(int lineno, ZebraHandle zh, const char *query,
     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);
+    res = zebra_scan_PQF(zh, odr, query, &pos, &num, &entries, &partial, 
+                        0 /* setname */);
     if (res != ZEBRA_OK)
     {
        printf("Error: scan returned %d (FAIL), but no error was expected\n"
@@ -359,6 +378,51 @@ void meta_query(int lineno, ZebraHandle zh, char *query, int exphits,
     free(positions);
 }
 
+void do_sort(ZebraHandle zh, const char *query, zint hits, zint *exp)
+{
+    ZebraMetaRecord *recs;
+    zint i;
+    int errs = 0;
+    zint min_val_recs = 0;
+    zint min_val_exp = 0;
+
+    assert(query);
+    do_query(__LINE__, zh, query, hits);
+
+    recs = zebra_meta_records_create_range (zh, "rsetname", 1, 4);
+    if (!recs)
+    {
+       fprintf(stderr, "recs==0\n");
+       exit(1);
+    }
+    /* find min for each sequence to get proper base offset */
+    for (i = 0; i<hits; i++)
+    {
+       if (min_val_recs == 0 || recs[i].sysno < min_val_recs)
+           min_val_recs = recs[i].sysno;
+       if (min_val_exp == 0 || exp[i] < min_val_exp)
+           min_val_exp = exp[i];
+    }
+           
+    /* compare sequences using base offset */
+    for (i = 0; i<hits; i++)
+       if ((recs[i].sysno-min_val_recs) != (exp[i]-min_val_exp))
+           errs++;
+    if (errs)
+    {
+       printf("Sequence not in right order for query\n%s\ngot exp\n",
+              query);
+       for (i = 0; i<hits; i++)
+           printf(" " ZINT_FORMAT "   " ZINT_FORMAT "\n",
+                  recs[i].sysno, exp[i]);
+    }
+    zebra_meta_records_destroy (zh, recs, 4);
+
+    if (errs)
+       exit(1);
+}
+
+
 struct finfo {
     const char *name;
     int occurred;