1 /* $Id: t8.c,v 1.3 2004-10-24 13:34:45 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* t8: test numeric attributes */
27 #include <yaz/pquery.h>
28 #include <idzebra/api.h>
30 #define LOGLEVEL LOG_ALL
33 /* read zebra.cfg from env var srcdir if it exists; otherwise current dir */
34 static ZebraService start_service()
37 char *srcdir = getenv("srcdir");
38 sprintf(cfg, "%.200s%szebra8.cfg",
39 srcdir ? srcdir : "", srcdir ? "/" : "");
40 return zebra_start(cfg);
43 static void insertdata(ZebraHandle zh)
47 " <title>My title</title>\n"
48 " <abstract>test record with single coordset, negatives</abstract>\n"
49 " <Spatial-Domain><Bounding-Coordinates>\n"
50 " <West-Bounding-Coordinate> -120 </West-Bounding-Coordinate>\n"
51 " <East-Bounding-Coordinate> -102 </East-Bounding-Coordinate>\n"
52 " <North-Bounding-Coordinate> 49 </North-Bounding-Coordinate>\n"
53 " <South-Bounding-Coordinate> 31 </South-Bounding-Coordinate>\n"
54 " </Bounding-Coordinates></Spatial-Domain>"
58 " <title>Another title</title>\n"
59 " <abstract>second test with two coord sets</abstract>\n"
60 " <Spatial-Domain><Bounding-Coordinates>\n"
61 " <West-Bounding-Coordinate> -120 </West-Bounding-Coordinate>\n"
62 " <East-Bounding-Coordinate> -102 </East-Bounding-Coordinate>\n"
63 " <North-Bounding-Coordinate> 49 </North-Bounding-Coordinate>\n"
64 " <South-Bounding-Coordinate> 31 </South-Bounding-Coordinate>\n"
65 " </Bounding-Coordinates>"
66 " <Bounding-Coordinates>\n"
67 " <West-Bounding-Coordinate> -125 </West-Bounding-Coordinate>\n"
68 " <East-Bounding-Coordinate> -108 </East-Bounding-Coordinate>\n"
69 " <North-Bounding-Coordinate> 41 </North-Bounding-Coordinate>\n"
70 " <South-Bounding-Coordinate> 25 </South-Bounding-Coordinate>\n"
71 " </Bounding-Coordinates></Spatial-Domain>"
74 zebra_select_database(zh, "Default");
76 zebra_begin_trans (zh, 1);
77 zebra_add_record (zh, rec1, strlen(rec1));
78 zebra_add_record (zh, rec2, strlen(rec2));
83 static void query( ZebraHandle zh, int lineno, char *qry, int expectedhits)
85 ODR odr_input = odr_createmem (ODR_DECODE);
86 YAZ_PQF_Parser parser = yaz_pqf_create();
90 int thistest=testno++;
93 logf(LOG_LOG,"Test %d (line %d): expecting %d",
94 thistest, lineno,expectedhits);
95 logf(LOG_LOG,"%s", qry);
97 query = yaz_pqf_parse(parser, odr_input, qry);
99 zebra_begin_trans (zh, 0);
102 logf(LOG_DEBUG,"calling search");
103 rc=zebra_search_RPN (zh, odr_input, query, "nameless", &hits);
104 logf(LOG_DEBUG,"search returned %d",rc);
106 printf("search returned %d",rc);
107 if (hits != expectedhits)
109 printf( "FAIL: Test %d (line %d):\n"
110 "got %d hits, expected %d\n"
112 thistest, lineno,hits, expectedhits, qry);
113 logf( LOG_FATAL, "FAIL: Test %d (line %d): got %d hits, expected %d\n",
114 thistest, lineno, hits,expectedhits);
118 zebra_end_trans (zh);
119 yaz_pqf_destroy(parser);
120 odr_destroy (odr_input);
121 logf(LOG_LOG,"Test %d ok",thistest);
125 int main(int argc, char **argv)
129 yaz_log_init_file("t8.log");
131 yaz_log_init_level(LOGLEVEL);
136 zs = start_service();
137 zh = zebra_open (zs);
141 #define Q(q,n) query(zh,__LINE__,q,n)
142 /* couple of simple queries just to see that we have indexed the stuff */
143 Q( "@attr 1=4 title",2 );
146 /* 1=2038: West-Bounding-Coordinate 2039: East: 2040: North: 2041 South*/
147 /* 4=109: numeric string */
148 /* 2=3: equal 2=1: less, 2=4: greater or equal 2=5 greater */
150 /* N>25, search attributes work */
151 Q( "@attr 2=4 @attr gils 1=2040 @attr 4=109 25",2);
153 /* N=41, get rec1 only */
154 Q( "@attr 2=3 @attr gils 1=2040 @attr 4=109 41",1);
156 /* N=49, get both records */
157 Q( "@attr 2=3 @attr gils 1=2040 @attr 4=109 49",2);
159 /* W=-120 get both records */
160 Q( "@attr 2=3 @attr gils 1=2038 @attr 4=109 -120",2);
162 /* W<-122 get only rec1 */
163 Q( "@attr 2=1 @attr gils 1=2038 @attr 4=109 '-120' ",1);
165 /* N=41 and N=49 get only rec2 */
166 Q( "@attr 2=3 @attr gils 1=2040 @attr 4=109 \"41 49\" ",1);
174 logf(LOG_LOG,"All tests OK");