From f24d7d2fd56ec639ccd0d9c2f9628964ef72c078 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 2 May 2005 09:05:22 +0000 Subject: [PATCH] Added scan test. --- test/api/Makefile.am | 5 ++- test/api/t11.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/api/testlib.c | 71 ++++++++++++++++++++++++++++++- test/api/testlib.h | 11 ++++- 4 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 test/api/t11.c diff --git a/test/api/Makefile.am b/test/api/Makefile.am index c6d7891..0e6922c 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -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 index 0000000..0ce4e89 --- /dev/null +++ b/test/api/t11.c @@ -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[] = { + "\na b\n\n", + "\nc d\n\n", + "\ne f\n\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); +} diff --git a/test/api/testlib.c b/test/api/testlib.c index a0b13d6..8a32b05 100644 --- a/test/api/testlib.c +++ b/test/api/testlib.c @@ -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