Added scan test.
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 2 May 2005 09:05:22 +0000 (09:05 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 2 May 2005 09:05:22 +0000 (09:05 +0000)
test/api/Makefile.am
test/api/t11.c [new file with mode: 0644]
test/api/testlib.c
test/api/testlib.h

index c6d7891..0e6922c 100644 (file)
@@ -1,9 +1,9 @@
-# $Id: Makefile.am,v 1.27 2004-12-02 14:05:04 adam Exp $
+# $Id: Makefile.am,v 1.28 2005-05-02 09:05:22 adam Exp $
 
 noinst_PROGRAMS = testclient
 testclient_SOURCES = testclient.c 
 
-simpletests = t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 
+simpletests = t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11
 safaritests = safari1
 check_PROGRAMS = $(simpletests) $(safaritests)
 TESTS = $(check_PROGRAMS)
@@ -24,6 +24,7 @@ t7_SOURCES = t7.c
 t8_SOURCES = t8.c
 t9_SOURCES = t9.c rankingrecords.h
 t10_SOURCES = t10.c rankingrecords.h
+t11_SOURCES = t11.c
 
 safari1_SOURCES = safari1.c testlib.c
 
diff --git a/test/api/t11.c b/test/api/t11.c
new file mode 100644 (file)
index 0000000..0ce4e89
--- /dev/null
@@ -0,0 +1,115 @@
+/* $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);
+}
index a0b13d6..8a32b05 100644 (file)
@@ -1,4 +1,4 @@
-/* $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
 
@@ -203,6 +203,75 @@ int do_query(int lineno, ZebraHandle zh, char *query, int exphits)
     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 
index 6c2e3fa..304c60f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: testlib.h,v 1.12 2005-04-28 11:25:24 adam Exp $
+/* $Id: testlib.h,v 1.13 2005-05-02 09:05:22 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -85,6 +85,15 @@ int do_query(int lineno, ZebraHandle zh, char *query, int exphits);
 int do_query_x(int lineno, ZebraHandle zh, char *query, int exphits,
               int experror);
 
+/**
+ * do_scan is a utility for scan testing 
+ */
+void do_scan(int lineno, ZebraHandle zh, const char *query,
+            int pos, int num,  /* input params */
+            int exp_pos, int exp_num,  int exp_partial, /* expected result */
+            const char **exp_entries  /* expected entries (or NULL) */
+    );
+
 /** 
  * ranking_query makes a query, checks number of hits, and for 
  * the first hit, that it contains the given string, and that it