From a34c87ac6c08ec62534e4068a5bd1fac93df8abe Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 2 Dec 2004 14:05:01 +0000 Subject: [PATCH] Move X-Path tests to xpath subdirectory. --- configure.in | 3 +- index/extract.c | 8 ++- test/Makefile.am | 2 +- test/api/Makefile.am | 14 +---- test/api/testlib.c | 19 ++++-- test/api/xpath1.c | 59 ----------------- test/api/xpath2.c | 83 ------------------------ test/api/xpath3.c | 56 ----------------- test/api/xpath4.c | 153 --------------------------------------------- test/api/xpath5.c | 83 ------------------------ test/api/zebraxpath.cfg | 10 --- test/marcxml/t1.c | 16 +++-- test/marcxml/t2.c | 7 ++- test/xpath/Makefile.am | 30 ++++++++- test/xpath/dummy.sh | 1 - test/xpath/xpath1.c | 57 +++++++++++++++++ test/xpath/xpath2.c | 82 ++++++++++++++++++++++++ test/xpath/xpath3.c | 55 ++++++++++++++++ test/xpath/xpath4.c | 152 ++++++++++++++++++++++++++++++++++++++++++++ test/xpath/xpath5.c | 81 ++++++++++++++++++++++++ test/xpath/zebraxpath.cfg | 10 +++ 21 files changed, 505 insertions(+), 476 deletions(-) delete mode 100644 test/api/xpath1.c delete mode 100644 test/api/xpath2.c delete mode 100644 test/api/xpath3.c delete mode 100644 test/api/xpath4.c delete mode 100644 test/api/xpath5.c delete mode 100644 test/api/zebraxpath.cfg delete mode 100755 test/xpath/dummy.sh create mode 100644 test/xpath/xpath1.c create mode 100644 test/xpath/xpath2.c create mode 100644 test/xpath/xpath3.c create mode 100644 test/xpath/xpath4.c create mode 100644 test/xpath/xpath5.c create mode 100644 test/xpath/zebraxpath.cfg diff --git a/configure.in b/configure.in index 2c2dae6..cb252ad 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ dnl Zebra, Index Data Aps, 1995-2004 -dnl $Id: configure.in,v 1.107 2004-11-29 21:55:25 adam Exp $ +dnl $Id: configure.in,v 1.108 2004-12-02 14:05:01 adam Exp $ dnl AC_INIT(include/idzebra/version.h) AM_INIT_AUTOMAKE(idzebra,1.4.0) @@ -292,6 +292,7 @@ AC_OUTPUT([ doc/zebraphp.dsl doc/tkl.xsl test/Makefile test/gils/Makefile test/usmarc/Makefile test/api/Makefile + test/xpath/Makefile test/rusmarc/Makefile test/cddb/Makefile test/malxml/Makefile test/config/Makefile test/sort2/Makefile test/xelm/Makefile diff --git a/index/extract.c b/index/extract.c index dcc1246..094764b 100644 --- a/index/extract.c +++ b/index/extract.c @@ -1,4 +1,4 @@ -/* $Id: extract.c,v 1.168 2004-12-01 11:37:45 adam Exp $ +/* $Id: extract.c,v 1.169 2004-12-02 14:05:03 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -1454,7 +1454,7 @@ void extract_add_index_string (RecWord *p, const char *str, int length) key.mem[2] = p->section_id; key.mem[3] = p->seqno; -#if 0 +#if 1 /* just for debugging .. */ yaz_log(YLOG_LOG, "add: set=%d use=%d " "record_id=%lld section_id=%lld seqno=%lld", @@ -1516,6 +1516,8 @@ static void extract_add_incomplete_field (RecWord *p) const char *b = p->string; int remain = p->length; const char **map = 0; + + yaz_log(YLOG_DEBUG, "Incomplete field, w='%.*s'", p->length, p->string); if (remain > 0) map = zebra_maps_input(p->zebra_maps, p->reg_type, &b, remain, 0); @@ -1564,7 +1566,7 @@ static void extract_add_complete_field (RecWord *p) int i = 0, remain = p->length; int first; /* first position */ -yaz_log(YLOG_DEBUG, "Complete field, w='%.*s'", p->length, p->string); + yaz_log(YLOG_DEBUG, "Complete field, w='%.*s'", p->length, p->string); if (remain > 0) map = zebra_maps_input (p->zebra_maps, p->reg_type, &b, remain, 1); diff --git a/test/Makefile.am b/test/Makefile.am index 7c53244..fadcf24 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS=codec api gils malxml config usmarc dmoz sort sort2 xelm cddb \ +SUBDIRS=codec api xpath gils malxml config usmarc dmoz sort sort2 xelm cddb \ rusmarc zsh marcxml charmap diff --git a/test/api/Makefile.am b/test/api/Makefile.am index d79b4f5..c6d7891 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -1,16 +1,14 @@ -# $Id: Makefile.am,v 1.26 2004-11-29 21:55:28 adam Exp $ +# $Id: Makefile.am,v 1.27 2004-12-02 14:05:04 adam Exp $ noinst_PROGRAMS = testclient testclient_SOURCES = testclient.c simpletests = t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 -xpathtests= xpath1 xpath2 xpath3 xpath4 xpath5 safaritests = safari1 -check_PROGRAMS = $(simpletests) $(xpathtests) $(safaritests) +check_PROGRAMS = $(simpletests) $(safaritests) TESTS = $(check_PROGRAMS) -EXTRA_DIST=zebra.cfg zebra6.cfg zebra8.cfg zebrazv.cfg \ - zebraxpath.cfg safari.cfg +EXTRA_DIST=zebra.cfg zebra6.cfg zebra8.cfg zebrazv.cfg safari.cfg noinst_LIBRARIES = libtestlib.a @@ -27,12 +25,6 @@ t8_SOURCES = t8.c t9_SOURCES = t9.c rankingrecords.h t10_SOURCES = t10.c rankingrecords.h -xpath1_SOURCES = xpath1.c -xpath2_SOURCES = xpath2.c -xpath3_SOURCES = xpath3.c -xpath4_SOURCES = xpath4.c -xpath5_SOURCES = xpath5.c - safari1_SOURCES = safari1.c testlib.c AM_CPPFLAGS = -I$(top_srcdir)/include $(YAZINC) diff --git a/test/api/testlib.c b/test/api/testlib.c index b9c1b1e..3cc35df 100644 --- a/test/api/testlib.c +++ b/test/api/testlib.c @@ -1,4 +1,4 @@ -/* $Id: testlib.c,v 1.6 2004-11-29 21:55:28 adam Exp $ +/* $Id: testlib.c,v 1.7 2004-12-02 14:05:04 adam Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -60,18 +60,27 @@ ZebraService start_up(char *cfgname, int argc, char **argv) return start_service(cfgname); } +/** + * get_srcdir: return env srcdir or . (if does does not exist) + */ +const char *get_srcdir() +{ + const char *srcdir = getenv("srcdir"); + if (!srcdir || ! *srcdir) + srcdir="."; + return srcdir; + +} /** start_service - do a zebra_start with a decent config name */ ZebraService start_service(char *cfgname) { char cfg[256]; - char *srcdir = getenv("srcdir"); + const char *srcdir = get_srcdir(); ZebraService zs; - if (!srcdir || ! *srcdir) - srcdir="."; if (!cfgname || ! *cfgname ) cfgname="zebra.cfg"; - sprintf(cfg, "%.200s/%s",srcdir, cfgname); + sprintf(cfg, "%.200s/%.50s", srcdir, cfgname); zs=zebra_start(cfg); if (!zs) { diff --git a/test/api/xpath1.c b/test/api/xpath1.c deleted file mode 100644 index 70fe3d4..0000000 --- a/test/api/xpath1.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $Id: xpath1.c,v 1.3 2004-12-02 11:28:20 adam Exp $ - Copyright (C) 2003,2004 - 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. -*/ - -#include -#include -#include "testlib.h" - -/** xpath1.c - index a simple sgml record and search in it */ - -int main(int argc, char **argv) -{ - ZebraService zs; - ZebraHandle zh; - const char *myrec[] = { - " \n" - " before \n" - " \n" - " inside \n" - " \n" - " after \n" - " \n", - 0}; - - zs = start_up("zebraxpath.cfg", argc, argv); - zh = zebra_open(zs); - init_data(zh, myrec); - - do_query(__LINE__,zh, "@attr 1=/sgml/tag before", 0); - do_query(__LINE__,zh, "@attr 1=/sgml/tag inside", 1); - do_query(__LINE__,zh, "@attr 1=/sgml/tag after", 0); - - do_query(__LINE__,zh, "@attr 1=/sgml/none after", 0); - do_query(__LINE__,zh, "@attr 1=/sgml/none inside", 0); - - do_query(__LINE__,zh, "@attr 1=/sgml before", 1); - do_query(__LINE__,zh, "@attr 1=/sgml inside", 1); - do_query(__LINE__,zh, "@attr 1=/sgml after", 1); - - return close_down(zh, zs, 0); -} diff --git a/test/api/xpath2.c b/test/api/xpath2.c deleted file mode 100644 index 2bcde1e..0000000 --- a/test/api/xpath2.c +++ /dev/null @@ -1,83 +0,0 @@ -/* $Id: xpath2.c,v 1.2 2004-12-02 11:28:20 adam Exp $ - Copyright (C) 2003,2004 - 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. -*/ - -#include "testlib.h" - - -/** xpath2.c - index a a bit more complex sgml record and search in it */ - -const char *myrec[] = { - " \n" - " 10 \n" - " Sauropoda \n" - " PT \n" - " \n" - " BT \n" - " 5 \n" - " Brontosauria \n" - " PT \n" - " \n" - " \n" - " NT \n" - " 11 \n" - " Eusauropoda \n" - " PT \n" - " \n" - " \n", - - " \n" - " 5 \n" - " Brontosauria \n" - " PT \n" - " \n" - " BT \n" - " 4 \n" - " Sauropodomorpha \n" - " PT \n" - " \n" - " \n" - " NT \n" - " 6 \n" - " Plateosauria \n" - " PT \n" - " \n" - " \n" - " NT \n" - " 10 \n" - " Sauropoda \n" - " PT \n" - " \n" - " \n", - 0}; - - -int main(int argc, char **argv) -{ - ZebraService zs = start_up("zebraxpath.cfg", argc, argv); - ZebraHandle zh = zebra_open (zs); - init_data(zh, myrec); - - do_query(__LINE__,zh, "@attr 1=/Zthes/termName Sauropoda", 1); - do_query(__LINE__,zh, "@attr 1=/Zthes/relation/termName Sauropoda",1); - - return close_down(zh, zs, 0); -} diff --git a/test/api/xpath3.c b/test/api/xpath3.c deleted file mode 100644 index 68a9020..0000000 --- a/test/api/xpath3.c +++ /dev/null @@ -1,56 +0,0 @@ - -/* $Id: xpath3.c,v 1.2 2004-12-02 11:28:20 adam Exp $ - Copyright (C) 2003,2004 - 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. -*/ - -#include "testlib.h" - - -/** xpath3.c - attributes, with Danish characters */ - -const char *myrec[] = { - " \n" - " \n" - " content \n" - " content \n" - " \n" - " content \n" - " \n", - 0}; - - -int main(int argc, char **argv) -{ - ZebraService zs = start_up("zebraxpath.cfg", argc, argv); - ZebraHandle zh = zebra_open(zs); - init_data(zh, myrec); - -#define q(qry,hits) do_query(__LINE__,zh,qry,hits) - - q("@attr 1=/root content",1); - q("@attr 1=/root/first content",1); - q("@attr {1=/root/first[@attr='danish']} content",1); - q("@attr {1=/root/second[@attr='danish lake']} content",1); - /*q("@attr {1=/root/third[@attr='dansk sø']} content",1); */ - /* FIXME - This triggers bug200 */ - - return close_down(zh, zs, 0); -} diff --git a/test/api/xpath4.c b/test/api/xpath4.c deleted file mode 100644 index 7983391..0000000 --- a/test/api/xpath4.c +++ /dev/null @@ -1,153 +0,0 @@ -/* $Id: xpath4.c,v 1.5 2004-12-02 11:28:20 adam Exp $ - Copyright (C) 2003,2004 - 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. -*/ - -#include "testlib.h" - - -/** xpath4.c - Attributes */ - -const char *myrec[] = { - " \n" - " foo \n" - " bar \n" - " gryf \n" - " \n", - - " \n" - " foo bar \n" - " gryf \n" - " \n", - - " \n" - " foo gryf \n" - " grunt \n" - " \n", - - " \n" - " foo grunt \n" - " bar \n" - " \n", - - " \n" - " double english \n" - " double danish \n" - " grunt \n" - " \n", - - " \n" - " hamlet \n" - " foo bar grunt grunt grunt \n" - " \n", - - " \n" - " before \n" - " \n" - " early \n" - " \n" - " middle \n" - " \n" - " late \n" - " \n" - " after \n" - " \n", - - " \n" - " before \n" - " \n" - " early \n" - " \n" - " middle \n" - " \n" - " late \n" - " \n" - " after \n" - " \n", - 0}; - - -int main(int argc, char **argv) -{ - ZebraService zs = start_up("zebraxpath.cfg", argc, argv); - ZebraHandle zh = zebra_open(zs); - -#if 0 - yaz_log_init_level( yaz_log_mask_str_x("xpath4,rsbetween", LOG_DEFAULT_LEVEL)); -#endif - - init_data(zh, myrec); - -#define q(qry,hits) do_query(__LINE__,zh,qry,hits) - - q("@attr 1=/record/title foo",4); - q("@attr 1=/record/title bar",2); - q("@attr 1=/record/title[@lang='da'] foo",1); - q("@attr 1=/record/title[@lang='en'] foo",1); - - q("@attr 1=/record/title[@lang='en'] english",1); - q("@attr 1=/record/title[@lang='da'] english",0); - q("@attr 1=/record/title[@lang='da'] danish",1); - q("@attr 1=/record/title[@lang='en'] danish",0); - - q("@attr 1=/record/title @and foo bar",2); - /* The previous one returns two hits, as the and applies to the whole - record, so it matches foobar - This might not have to be like that, but currently that is what - zebra does. */ - q("@and @attr 1=/record/title foo @attr 1=/record/title bar ",2); - - /* check we get all the occureences for 'grunt' */ - /* this can only be seen in the log, with debugs on. bug #202 */ - q("@attr 1=/record/author grunt",3); - - /* check nested tags */ - q("@attr 1=/record/nested before",0); - q("@attr 1=/record/nested early",1); - q("@attr 1=/record/nested middle",1); - q("@attr 1=/record/nested late",1); - q("@attr 1=/record/nested after",0); - - q("@attr 1=/record/nested/nested before",0); - q("@attr 1=/record/nested/nested early",0); - q("@attr 1=/record/nested/nested middle",1); - q("@attr 1=/record/nested/nested late",0); - q("@attr 1=/record/nested/nested after",0); - - q("@attr 1=/record/nestattr[@level='outer'] before",0); - q("@attr 1=/record/nestattr[@level='outer'] early",1); - q("@attr 1=/record/nestattr[@level='outer'] middle",1); - q("@attr 1=/record/nestattr[@level='outer'] late",1); - q("@attr 1=/record/nestattr[@level='outer'] after",0); - - q("@attr 1=/record/nestattr[@level='inner'] before",0); - q("@attr 1=/record/nestattr[@level='inner'] early",0); - q("@attr 1=/record/nestattr[@level='inner'] middle",0); - q("@attr 1=/record/nestattr[@level='inner'] late",0); - q("@attr 1=/record/nestattr[@level='inner'] after",0); - - q("@attr 1=/record/nestattr/nestattr[@level='inner'] before",0); - q("@attr 1=/record/nestattr/nestattr[@level='inner'] early",0); - q("@attr 1=/record/nestattr/nestattr[@level='inner'] middle",1); - q("@attr 1=/record/nestattr/nestattr[@level='inner'] late",0); - q("@attr 1=/record/nestattr/nestattr[@level='inner'] after",0); - - return close_down(zh, zs, 0); -} diff --git a/test/api/xpath5.c b/test/api/xpath5.c deleted file mode 100644 index aa20a3d..0000000 --- a/test/api/xpath5.c +++ /dev/null @@ -1,83 +0,0 @@ -/* $Id: xpath5.c,v 1.4 2004-12-02 11:28:20 adam Exp $ - Copyright (C) 2003,2004 - 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. -*/ - -#include "testlib.h" - - -/** xpath4.c - Ranking in xpath */ - - -const char *recs[] = { - "\n" - " The first title\n" - " \n" - " The first common word is the: the the the \n" - " The second common word is word \n" - " but all have the foo bar \n" - " \n" - "\n", - - "\n" - " The second title\n" - " \n" - " The first common word is the: the \n" - " The second common word is foo: foo foo \n" - " but all have the foo bar \n" - " \n" - "\n", - - "\n" - " The third title\n" - " \n" - " The first common word is the: the \n" - " The third common word is bar: bar \n" - " but all have the foo bar \n" - " \n" - "\n", - - 0 }; - - -int main(int argc, char **argv) -{ - ZebraService zs = start_up("zebraxpath.cfg", argc, argv); - ZebraHandle zh = zebra_open(zs); - init_data(zh, recs); - -// yaz_log_init_level(LOG_ALL); - -#define q(qry,hits,string,score) \ - ranking_query(__LINE__,zh,qry,hits,string,score) - - q("@attr 1=/record/title @attr 2=102 the", - 3,"first title",952); - q("@attr 1=/ @attr 2=102 @or third foo", - 3,"third title",802); - - q("@attr 1=/ @attr 2=102 foo", - 3,"second title",850); - - q("@attr 1=/record/ @attr 2=102 foo", - 3,"second title",927); - - return close_down(zh, zs, 0); -} diff --git a/test/api/zebraxpath.cfg b/test/api/zebraxpath.cfg deleted file mode 100644 index 53ab90f..0000000 --- a/test/api/zebraxpath.cfg +++ /dev/null @@ -1,10 +0,0 @@ -# $Id: zebraxpath.cfg,v 1.1 2004-10-29 14:16:22 heikki Exp $ -profilePath: ${srcdir:-.}/../../tab -recordType: grs.sgml -attset: bib1.att - -isam:b - - - - diff --git a/test/marcxml/t1.c b/test/marcxml/t1.c index 75c7205..6bc76af 100644 --- a/test/marcxml/t1.c +++ b/test/marcxml/t1.c @@ -1,4 +1,4 @@ -/* $Id: t1.c,v 1.1 2004-12-02 12:04:49 adam Exp $ +/* $Id: t1.c,v 1.2 2004-12-02 14:05:04 adam Exp $ Copyright (C) 2003,2004 Index Data Aps @@ -26,19 +26,25 @@ int main(int argc, char **argv) { ZebraService zs = start_up(0, argc, argv); ZebraHandle zh = zebra_open(zs); + char path[256]; zebra_select_database(zh, "Default"); zebra_init(zh); zebra_begin_trans(zh, 1); - zebra_repository_update(zh, "m1.xml"); - zebra_repository_update(zh, "m2.xml"); - zebra_repository_update(zh, "m3.xml"); + sprintf(path, "%.200s/m1.xml", get_srcdir()); + zebra_repository_update(zh, path); + sprintf(path, "%.200s/m2.xml", get_srcdir()); + zebra_repository_update(zh, path); + sprintf(path, "%.200s/m3.xml", get_srcdir()); + zebra_repository_update(zh, path); zebra_end_trans(zh); zebra_commit(zh); - do_query(__LINE__,zh, "@and @attr 1=54 eng @and @attr 1=1003 jack @attr 1=4 computer", 2); + do_query(__LINE__,zh, "@and " + "@attr 1=54 eng " + "@and @attr 1=1003 jack @attr 1=4 computer", 2); return close_down(zh, zs, 0); } diff --git a/test/marcxml/t2.c b/test/marcxml/t2.c index b282708..5e98f33 100644 --- a/test/marcxml/t2.c +++ b/test/marcxml/t2.c @@ -1,4 +1,4 @@ -/* $Id: t2.c,v 1.1 2004-12-02 12:04:49 adam Exp $ +/* $Id: t2.c,v 1.2 2004-12-02 14:05:04 adam Exp $ Copyright (C) 2003,2004 Index Data Aps @@ -26,6 +26,7 @@ int main(int argc, char **argv) { ZebraService zs = start_up(0, argc, argv); ZebraHandle zh = zebra_open(zs); + char path[256]; zebra_select_database(zh, "Default"); @@ -34,7 +35,9 @@ int main(int argc, char **argv) zebra_set_resource(zh, "recordType", "grs.marcxml.record"); zebra_begin_trans(zh, 1); - zebra_repository_update(zh, "sample-marc"); + + sprintf(path, "%.200s/sample-marc", get_srcdir()); + zebra_repository_update(zh, path); zebra_end_trans(zh); zebra_commit(zh); diff --git a/test/xpath/Makefile.am b/test/xpath/Makefile.am index 8bdf1ee..79ce127 100644 --- a/test/xpath/Makefile.am +++ b/test/xpath/Makefile.am @@ -1,7 +1,31 @@ -# $Id: Makefile.am,v 1.9 2004-12-02 12:08:39 adam Exp $ +# $Id: Makefile.am,v 1.10 2004-12-02 14:05:04 adam Exp $ -check_SCRIPTS = dummy.sh +check_PROGRAMS = xpath1 xpath2 xpath3 xpath4 xpath5 -TESTS = $(check_SCRIPTS) +TESTS = $(check_PROGRAMS) +EXTRA_DIST=zebraxpath.cfg + +xpath1_SOURCES = xpath1.c +xpath2_SOURCES = xpath2.c +xpath3_SOURCES = xpath3.c +xpath4_SOURCES = xpath4.c +xpath5_SOURCES = xpath5.c + +AM_CPPFLAGS = -I$(top_srcdir)/include $(YAZINC) + +zebralibs = \ + ../../index/libidzebra-api.la \ + ../../rset/libidzebra-rset.la \ + ../../recctrl/libidzebra-recctrl.la \ + ../../dict/libidzebra-dict.la \ + ../../isams/libidzebra-isams.la \ + ../../isamc/libidzebra-isamc.la \ + ../../isamb/libidzebra-isamb.la \ + ../../data1/libidzebra-data1.la \ + ../../bfile/libidzebra-bfile.la \ + ../../dfa/libidzebra-dfa.la \ + ../../util/libidzebra-util.la + +LDADD = ../api/libtestlib.a $(zebralibs) $(YAZLALIB) diff --git a/test/xpath/dummy.sh b/test/xpath/dummy.sh deleted file mode 100755 index b77c605..0000000 --- a/test/xpath/dummy.sh +++ /dev/null @@ -1 +0,0 @@ -echo "xpath tests moved away" diff --git a/test/xpath/xpath1.c b/test/xpath/xpath1.c new file mode 100644 index 0000000..434d715 --- /dev/null +++ b/test/xpath/xpath1.c @@ -0,0 +1,57 @@ +/* $Id: xpath1.c,v 1.1 2004-12-02 14:05:04 adam Exp $ + Copyright (C) 2003,2004 + 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. +*/ + +#include "../api/testlib.h" + +/** xpath1.c - index a simple sgml record and search in it */ + +int main(int argc, char **argv) +{ + ZebraService zs; + ZebraHandle zh; + const char *myrec[] = { + " \n" + " before \n" + " \n" + " inside \n" + " \n" + " after \n" + " \n", + 0}; + + zs = start_up("zebraxpath.cfg", argc, argv); + zh = zebra_open(zs); + init_data(zh, myrec); + + do_query(__LINE__,zh, "@attr 1=/sgml/tag before", 0); + do_query(__LINE__,zh, "@attr 1=/sgml/tag inside", 1); + do_query(__LINE__,zh, "@attr 1=/sgml/tag after", 0); + + do_query(__LINE__,zh, "@attr 1=/sgml/none after", 0); + do_query(__LINE__,zh, "@attr 1=/sgml/none inside", 0); + + do_query(__LINE__,zh, "@attr 1=/sgml before", 1); + do_query(__LINE__,zh, "@attr 1=/sgml inside", 1); + do_query(__LINE__,zh, "@attr 1=/sgml after", 1); + + return close_down(zh, zs, 0); +} diff --git a/test/xpath/xpath2.c b/test/xpath/xpath2.c new file mode 100644 index 0000000..394c117 --- /dev/null +++ b/test/xpath/xpath2.c @@ -0,0 +1,82 @@ +/* $Id: xpath2.c,v 1.1 2004-12-02 14:05:04 adam Exp $ + Copyright (C) 2003,2004 + 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. +*/ + +#include "../api/testlib.h" + +/** xpath2.c - index a a bit more complex sgml record and search in it */ + +const char *myrec[] = { + " \n" + " 10 \n" + " Sauropoda \n" + " PT \n" + " \n" + " BT \n" + " 5 \n" + " Brontosauria \n" + " PT \n" + " \n" + " \n" + " NT \n" + " 11 \n" + " Eusauropoda \n" + " PT \n" + " \n" + " \n", + + " \n" + " 5 \n" + " Brontosauria \n" + " PT \n" + " \n" + " BT \n" + " 4 \n" + " Sauropodomorpha \n" + " PT \n" + " \n" + " \n" + " NT \n" + " 6 \n" + " Plateosauria \n" + " PT \n" + " \n" + " \n" + " NT \n" + " 10 \n" + " Sauropoda \n" + " PT \n" + " \n" + " \n", + 0}; + + +int main(int argc, char **argv) +{ + ZebraService zs = start_up("zebraxpath.cfg", argc, argv); + ZebraHandle zh = zebra_open (zs); + init_data(zh, myrec); + + do_query(__LINE__,zh, "@attr 1=/Zthes/termName Sauropoda", 1); + do_query(__LINE__,zh, "@attr 1=/Zthes/relation/termName Sauropoda",1); + + return close_down(zh, zs, 0); +} diff --git a/test/xpath/xpath3.c b/test/xpath/xpath3.c new file mode 100644 index 0000000..8f191b0 --- /dev/null +++ b/test/xpath/xpath3.c @@ -0,0 +1,55 @@ + +/* $Id: xpath3.c,v 1.1 2004-12-02 14:05:04 adam Exp $ + Copyright (C) 2003,2004 + 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. +*/ + +#include "../api/testlib.h" + +/** xpath3.c - attributes, with Danish characters */ + +const char *myrec[] = { + " \n" + " \n" + " content \n" + " content \n" + " \n" + " content \n" + " \n", + 0}; + + +int main(int argc, char **argv) +{ + ZebraService zs = start_up("zebraxpath.cfg", argc, argv); + ZebraHandle zh = zebra_open(zs); + init_data(zh, myrec); + +#define q(qry,hits) do_query(__LINE__,zh,qry,hits) + + q("@attr 1=/root content",1); + q("@attr 1=/root/first content",1); + q("@attr {1=/root/first[@attr='danish']} content",1); + q("@attr {1=/root/second[@attr='danish lake']} content",1); + /*q("@attr {1=/root/third[@attr='dansk sø']} content",1); */ + /* FIXME - This triggers bug200 */ + + return close_down(zh, zs, 0); +} diff --git a/test/xpath/xpath4.c b/test/xpath/xpath4.c new file mode 100644 index 0000000..2ffefad --- /dev/null +++ b/test/xpath/xpath4.c @@ -0,0 +1,152 @@ +/* $Id: xpath4.c,v 1.1 2004-12-02 14:05:04 adam Exp $ + Copyright (C) 2003,2004 + 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. +*/ + +#include "../api/testlib.h" + +/** xpath4.c - Attributes */ + +const char *myrec[] = { + " \n" + " foo \n" + " bar \n" + " gryf \n" + " \n", + + " \n" + " foo bar \n" + " gryf \n" + " \n", + + " \n" + " foo gryf \n" + " grunt \n" + " \n", + + " \n" + " foo grunt \n" + " bar \n" + " \n", + + " \n" + " double english \n" + " double danish \n" + " grunt \n" + " \n", + + " \n" + " hamlet \n" + " foo bar grunt grunt grunt \n" + " \n", + + " \n" + " before \n" + " \n" + " early \n" + " \n" + " middle \n" + " \n" + " late \n" + " \n" + " after \n" + " \n", + + " \n" + " before \n" + " \n" + " early \n" + " \n" + " middle \n" + " \n" + " late \n" + " \n" + " after \n" + " \n", + 0}; + + +int main(int argc, char **argv) +{ + ZebraService zs = start_up("zebraxpath.cfg", argc, argv); + ZebraHandle zh = zebra_open(zs); + +#if 0 + yaz_log_init_level( yaz_log_mask_str_x("xpath4,rsbetween", LOG_DEFAULT_LEVEL)); +#endif + + init_data(zh, myrec); + +#define q(qry,hits) do_query(__LINE__,zh,qry,hits) + + q("@attr 1=/record/title foo",4); + q("@attr 1=/record/title bar",2); + q("@attr 1=/record/title[@lang='da'] foo",1); + q("@attr 1=/record/title[@lang='en'] foo",1); + + q("@attr 1=/record/title[@lang='en'] english",1); + q("@attr 1=/record/title[@lang='da'] english",0); + q("@attr 1=/record/title[@lang='da'] danish",1); + q("@attr 1=/record/title[@lang='en'] danish",0); + + q("@attr 1=/record/title @and foo bar",2); + /* The previous one returns two hits, as the and applies to the whole + record, so it matches foobar + This might not have to be like that, but currently that is what + zebra does. */ + q("@and @attr 1=/record/title foo @attr 1=/record/title bar ",2); + + /* check we get all the occureences for 'grunt' */ + /* this can only be seen in the log, with debugs on. bug #202 */ + q("@attr 1=/record/author grunt",3); + + /* check nested tags */ + q("@attr 1=/record/nested before",0); + q("@attr 1=/record/nested early",1); + q("@attr 1=/record/nested middle",1); + q("@attr 1=/record/nested late",1); + q("@attr 1=/record/nested after",0); + + q("@attr 1=/record/nested/nested before",0); + q("@attr 1=/record/nested/nested early",0); + q("@attr 1=/record/nested/nested middle",1); + q("@attr 1=/record/nested/nested late",0); + q("@attr 1=/record/nested/nested after",0); + + q("@attr 1=/record/nestattr[@level='outer'] before",0); + q("@attr 1=/record/nestattr[@level='outer'] early",1); + q("@attr 1=/record/nestattr[@level='outer'] middle",1); + q("@attr 1=/record/nestattr[@level='outer'] late",1); + q("@attr 1=/record/nestattr[@level='outer'] after",0); + + q("@attr 1=/record/nestattr[@level='inner'] before",0); + q("@attr 1=/record/nestattr[@level='inner'] early",0); + q("@attr 1=/record/nestattr[@level='inner'] middle",0); + q("@attr 1=/record/nestattr[@level='inner'] late",0); + q("@attr 1=/record/nestattr[@level='inner'] after",0); + + q("@attr 1=/record/nestattr/nestattr[@level='inner'] before",0); + q("@attr 1=/record/nestattr/nestattr[@level='inner'] early",0); + q("@attr 1=/record/nestattr/nestattr[@level='inner'] middle",1); + q("@attr 1=/record/nestattr/nestattr[@level='inner'] late",0); + q("@attr 1=/record/nestattr/nestattr[@level='inner'] after",0); + + return close_down(zh, zs, 0); +} diff --git a/test/xpath/xpath5.c b/test/xpath/xpath5.c new file mode 100644 index 0000000..34f12c0 --- /dev/null +++ b/test/xpath/xpath5.c @@ -0,0 +1,81 @@ +/* $Id: xpath5.c,v 1.1 2004-12-02 14:05:04 adam Exp $ + Copyright (C) 2003,2004 + 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. +*/ + +#include "../api/testlib.h" + +/** xpath4.c - Ranking in xpath */ + +const char *recs[] = { + "\n" + " The first title\n" + " \n" + " The first common word is the: the the the \n" + " The second common word is word \n" + " but all have the foo bar \n" + " \n" + "\n", + + "\n" + " The second title\n" + " \n" + " The first common word is the: the \n" + " The second common word is foo: foo foo \n" + " but all have the foo bar \n" + " \n" + "\n", + + "\n" + " The third title\n" + " \n" + " The first common word is the: the \n" + " The third common word is bar: bar \n" + " but all have the foo bar \n" + " \n" + "\n", + + 0 }; + + +int main(int argc, char **argv) +{ + ZebraService zs = start_up("zebraxpath.cfg", argc, argv); + ZebraHandle zh = zebra_open(zs); + init_data(zh, recs); + +// yaz_log_init_level(LOG_ALL); + +#define q(qry,hits,string,score) \ + ranking_query(__LINE__,zh,qry,hits,string,score) + + q("@attr 1=/record/title @attr 2=102 the", + 3,"first title",952); + q("@attr 1=/ @attr 2=102 @or third foo", + 3,"third title",802); + + q("@attr 1=/ @attr 2=102 foo", + 3,"second title",850); + + q("@attr 1=/record/ @attr 2=102 foo", + 3,"second title",927); + + return close_down(zh, zs, 0); +} diff --git a/test/xpath/zebraxpath.cfg b/test/xpath/zebraxpath.cfg new file mode 100644 index 0000000..1f6524d --- /dev/null +++ b/test/xpath/zebraxpath.cfg @@ -0,0 +1,10 @@ +# $Id: zebraxpath.cfg,v 1.1 2004-12-02 14:05:04 adam Exp $ +profilePath: ${srcdir:-.}/../../tab +recordType: grs.sgml +attset: bib1.att + +isam:b + + + + -- 1.7.10.4