Move X-Path tests to xpath subdirectory.
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 2 Dec 2004 14:05:01 +0000 (14:05 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 2 Dec 2004 14:05:01 +0000 (14:05 +0000)
21 files changed:
configure.in
index/extract.c
test/Makefile.am
test/api/Makefile.am
test/api/testlib.c
test/api/xpath1.c [deleted file]
test/api/xpath2.c [deleted file]
test/api/xpath3.c [deleted file]
test/api/xpath4.c [deleted file]
test/api/xpath5.c [deleted file]
test/api/zebraxpath.cfg [deleted file]
test/marcxml/t1.c
test/marcxml/t2.c
test/xpath/Makefile.am
test/xpath/dummy.sh [deleted file]
test/xpath/xpath1.c [new file with mode: 0644]
test/xpath/xpath2.c [new file with mode: 0644]
test/xpath/xpath3.c [new file with mode: 0644]
test/xpath/xpath4.c [new file with mode: 0644]
test/xpath/xpath5.c [new file with mode: 0644]
test/xpath/zebraxpath.cfg [new file with mode: 0644]

index 2c2dae6..cb252ad 100644 (file)
@@ -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
index dcc1246..094764b 100644 (file)
@@ -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);
index 7c53244..fadcf24 100644 (file)
@@ -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 
 
index d79b4f5..c6d7891 100644 (file)
@@ -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)
index b9c1b1e..3cc35df 100644 (file)
@@ -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 (file)
index 70fe3d4..0000000
+++ /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 <stdlib.h>
-#include <idzebra/api.h>
-#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[] = {
-        "<sgml> \n"
-        "  before \n"
-        "  <tag> \n"
-        "    inside \n"
-        "  </tag> \n"
-        "  after \n"
-        "</sgml> \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 (file)
index 2bcde1e..0000000
+++ /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[] = {
-    "<Zthes> \n"
-    " <termId>10</termId> \n"
-    " <termName>Sauropoda</termName> \n"
-    " <termType>PT</termType> \n"
-    " <relation> \n"
-    "  <relationType>BT</relationType> \n"
-    "  <termId>5</termId> \n"
-    "  <termName>Brontosauria</termName> \n"
-    "  <termType>PT</termType> \n"
-    " </relation> \n"
-    " <relation> \n"
-    "  <relationType>NT</relationType> \n"
-    "  <termId>11</termId> \n"
-    "  <termName>Eusauropoda</termName> \n"
-    "  <termType>PT</termType> \n"
-    " </relation> \n"
-    "</Zthes> \n",
-
-    "<Zthes> \n"
-    " <termId>5</termId> \n"
-    " <termName>Brontosauria</termName> \n"
-    " <termType>PT</termType> \n"
-    " <relation> \n"
-    "  <relationType>BT</relationType> \n"
-    "  <termId>4</termId> \n"
-    "  <termName>Sauropodomorpha</termName> \n"
-    "  <termType>PT</termType> \n"
-    " </relation> \n"
-    " <relation> \n"
-    "  <relationType>NT</relationType> \n"
-    "  <termId>6</termId> \n"
-    "  <termName>Plateosauria</termName> \n"
-    "  <termType>PT</termType> \n"
-    " </relation> \n"
-    " <relation> \n"
-    "  <relationType>NT</relationType> \n"
-    "  <termId>10</termId> \n"
-    "  <termName>Sauropoda</termName> \n"
-    "  <termType>PT</termType> \n"
-    " </relation> \n"
-    "</Zthes> \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 (file)
index 68a9020..0000000
+++ /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[] = {
-    "<root> \n"
-    "  <!-- Space in attribute --> \n"
-    "  <first attr=\"danish\">content</first> \n"
-    "  <second attr=\"danish lake\">content</second> \n"
-    "  <!-- Oslash in Latin-1 encoded below.. --> \n"
-    "  <third attr=\"dansk sø\">content<third> \n"
-    "</root> \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 (file)
index 7983391..0000000
+++ /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[] = {
-    "<record> \n"
-    "  <title>foo</title> \n"
-    "  <title>bar</title> \n"
-    "  <author>gryf</author> \n"
-    "</record> \n",
-    
-    "<record> \n"
-    "  <title>foo bar</title> \n"
-    "  <author>gryf</author> \n"
-    "</record> \n",
-   
-    "<record> \n"
-    "  <title lang=en>foo gryf</title> \n"
-    "  <author>grunt</author> \n"
-    "</record> \n",
-  
-    "<record> \n"
-    "  <title lang=da>foo grunt</title> \n"
-    "  <value>bar</value> \n"
-    "</record> \n",
-    "<record> \n"
-    "  <title lang=en>double english</title> \n"
-    "  <title lang=da>double danish</title> \n"
-    "  <author>grunt</author> \n"
-    "</record> \n",
-
-    "<record> \n"
-    "  <title>hamlet</title> \n"
-    "  <author>foo bar grunt grunt grunt</author> \n"
-    "</record> \n",
-
-    "<record> \n"
-    "  before \n"
-    "  <nested> \n"
-    "     early \n"
-    "     <nested> \n"
-    "        middle \n"
-    "     </nested> \n"
-    "     late \n"
-    "  </nested> \n"
-    "  after \n"
-    "</record> \n",
-
-    "<record> \n"
-    "  before \n"
-    "  <nestattr level=outer> \n"
-    "     early \n"
-    "     <nestattr level=inner> \n"
-    "        middle \n"
-    "     </nestattr> \n"
-    "     late \n"
-    "  </nestattr> \n"
-    "  after \n"
-    "</record> \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 <title>foo</title><title>bar</title>
-    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 (file)
index aa20a3d..0000000
+++ /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[] = {
-        "<record>\n"
-        "  <title>The first title</title>\n"
-        "  <abstract> \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"
-        "  </abstract>\n"
-        "</record>\n",
-
-        "<record>\n"
-        "  <title>The second title</title>\n"
-        "  <abstract> \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"
-        "  </abstract>\n"
-        "</record>\n",
-
-        "<record>\n"
-        "  <title>The third title</title>\n"
-        "  <abstract> \n"
-        "    The first common word is the: the \n"
-        "    The third common word is bar: bar \n"
-        "    but all have the foo bar \n"
-        "  </abstract>\n"
-        "</record>\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 (file)
index 53ab90f..0000000
+++ /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
-
-
-
-
index 75c7205..6bc76af 100644 (file)
@@ -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);
 }
index b282708..5e98f33 100644 (file)
@@ -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);
 
index 8bdf1ee..79ce127 100644 (file)
@@ -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 (executable)
index b77c605..0000000
+++ /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 (file)
index 0000000..434d715
--- /dev/null
@@ -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[] = {
+        "<sgml> \n"
+        "  before \n"
+        "  <tag> \n"
+        "    inside \n"
+        "  </tag> \n"
+        "  after \n"
+        "</sgml> \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 (file)
index 0000000..394c117
--- /dev/null
@@ -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[] = {
+    "<Zthes> \n"
+    " <termId>10</termId> \n"
+    " <termName>Sauropoda</termName> \n"
+    " <termType>PT</termType> \n"
+    " <relation> \n"
+    "  <relationType>BT</relationType> \n"
+    "  <termId>5</termId> \n"
+    "  <termName>Brontosauria</termName> \n"
+    "  <termType>PT</termType> \n"
+    " </relation> \n"
+    " <relation> \n"
+    "  <relationType>NT</relationType> \n"
+    "  <termId>11</termId> \n"
+    "  <termName>Eusauropoda</termName> \n"
+    "  <termType>PT</termType> \n"
+    " </relation> \n"
+    "</Zthes> \n",
+
+    "<Zthes> \n"
+    " <termId>5</termId> \n"
+    " <termName>Brontosauria</termName> \n"
+    " <termType>PT</termType> \n"
+    " <relation> \n"
+    "  <relationType>BT</relationType> \n"
+    "  <termId>4</termId> \n"
+    "  <termName>Sauropodomorpha</termName> \n"
+    "  <termType>PT</termType> \n"
+    " </relation> \n"
+    " <relation> \n"
+    "  <relationType>NT</relationType> \n"
+    "  <termId>6</termId> \n"
+    "  <termName>Plateosauria</termName> \n"
+    "  <termType>PT</termType> \n"
+    " </relation> \n"
+    " <relation> \n"
+    "  <relationType>NT</relationType> \n"
+    "  <termId>10</termId> \n"
+    "  <termName>Sauropoda</termName> \n"
+    "  <termType>PT</termType> \n"
+    " </relation> \n"
+    "</Zthes> \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 (file)
index 0000000..8f191b0
--- /dev/null
@@ -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[] = {
+    "<root> \n"
+    "  <!-- Space in attribute --> \n"
+    "  <first attr=\"danish\">content</first> \n"
+    "  <second attr=\"danish lake\">content</second> \n"
+    "  <!-- Oslash in Latin-1 encoded below.. --> \n"
+    "  <third attr=\"dansk sø\">content<third> \n"
+    "</root> \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 (file)
index 0000000..2ffefad
--- /dev/null
@@ -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[] = {
+    "<record> \n"
+    "  <title>foo</title> \n"
+    "  <title>bar</title> \n"
+    "  <author>gryf</author> \n"
+    "</record> \n",
+    
+    "<record> \n"
+    "  <title>foo bar</title> \n"
+    "  <author>gryf</author> \n"
+    "</record> \n",
+   
+    "<record> \n"
+    "  <title lang=en>foo gryf</title> \n"
+    "  <author>grunt</author> \n"
+    "</record> \n",
+  
+    "<record> \n"
+    "  <title lang=da>foo grunt</title> \n"
+    "  <value>bar</value> \n"
+    "</record> \n",
+    "<record> \n"
+    "  <title lang=en>double english</title> \n"
+    "  <title lang=da>double danish</title> \n"
+    "  <author>grunt</author> \n"
+    "</record> \n",
+
+    "<record> \n"
+    "  <title>hamlet</title> \n"
+    "  <author>foo bar grunt grunt grunt</author> \n"
+    "</record> \n",
+
+    "<record> \n"
+    "  before \n"
+    "  <nested> \n"
+    "     early \n"
+    "     <nested> \n"
+    "        middle \n"
+    "     </nested> \n"
+    "     late \n"
+    "  </nested> \n"
+    "  after \n"
+    "</record> \n",
+
+    "<record> \n"
+    "  before \n"
+    "  <nestattr level=outer> \n"
+    "     early \n"
+    "     <nestattr level=inner> \n"
+    "        middle \n"
+    "     </nestattr> \n"
+    "     late \n"
+    "  </nestattr> \n"
+    "  after \n"
+    "</record> \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 <title>foo</title><title>bar</title>
+    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 (file)
index 0000000..34f12c0
--- /dev/null
@@ -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[] = {
+        "<record>\n"
+        "  <title>The first title</title>\n"
+        "  <abstract> \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"
+        "  </abstract>\n"
+        "</record>\n",
+
+        "<record>\n"
+        "  <title>The second title</title>\n"
+        "  <abstract> \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"
+        "  </abstract>\n"
+        "</record>\n",
+
+        "<record>\n"
+        "  <title>The third title</title>\n"
+        "  <abstract> \n"
+        "    The first common word is the: the \n"
+        "    The third common word is bar: bar \n"
+        "    but all have the foo bar \n"
+        "  </abstract>\n"
+        "</record>\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 (file)
index 0000000..1f6524d
--- /dev/null
@@ -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
+
+
+
+