Cleaned the test programs a bit, used routines in testlib
[idzebra-moved-to-github.git] / test / api / t8.c
1 /* $Id: t8.c,v 1.4 2004-10-28 15:24:36 heikki Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
3    Index Data Aps
4
5 This file is part of the Zebra server.
6
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
10 version.
11
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
15 for more details.
16
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
20 02111-1307, USA.
21 */
22
23 /* t8: test numeric attributes */
24
25 #include <assert.h>
26 #include <yaz/log.h>
27 #include <yaz/pquery.h>
28 #include <idzebra/api.h>
29 #include "testlib.h"
30
31 #define LOGLEVEL LOG_ALL 
32
33         
34 const char *recs[] = {
35         "<gils>\n"
36         "  <title>My title</title>\n"
37         "  <abstract>test record with single coordset, negatives</abstract>\n"
38         "  <Spatial-Domain><Bounding-Coordinates>\n"
39         "    <West-Bounding-Coordinate> -120 </West-Bounding-Coordinate>\n"
40         "    <East-Bounding-Coordinate> -102 </East-Bounding-Coordinate>\n"
41         "    <North-Bounding-Coordinate>  49 </North-Bounding-Coordinate>\n"
42         "    <South-Bounding-Coordinate>  31 </South-Bounding-Coordinate>\n"
43         "  </Bounding-Coordinates></Spatial-Domain>"
44         "</gils>\n",
45
46         "<gils>\n"
47         "  <title>Another title</title>\n"
48         "  <abstract>second test with two coord sets</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>"
55         "  <Bounding-Coordinates>\n"
56         "    <West-Bounding-Coordinate> -125 </West-Bounding-Coordinate>\n"
57         "    <East-Bounding-Coordinate> -108 </East-Bounding-Coordinate>\n"
58         "    <North-Bounding-Coordinate>  41 </North-Bounding-Coordinate>\n"
59         "    <South-Bounding-Coordinate>  25 </South-Bounding-Coordinate>\n"
60         "  </Bounding-Coordinates></Spatial-Domain>"
61         "</gils>\n",
62         0};
63         
64
65
66
67 int main(int argc, char **argv)
68 {
69     ZebraService zs;
70     ZebraHandle zh;
71     yaz_log_init_file("t8.log");
72 #ifdef LOGLEVEL
73     yaz_log_init_level(LOGLEVEL); 
74 #endif
75
76     nmem_init ();
77     
78     zs = start_service("zebra8.cfg");
79     zh = zebra_open (zs);
80
81     init_data(zh, recs);
82
83 #define Q(q,n) Query(__LINE__,zh,q,n)
84     /* couple of simple queries just to see that we have indexed the stuff */
85     Q( "@attr 1=4 title",2 );
86     Q( "title",2 );
87     
88     /* 1=2038: West-Bounding-Coordinate 2039: East: 2040: North: 2041 South*/
89     /* 4=109: numeric string */
90     /* 2=3: equal  2=1: less, 2=4: greater or equal 2=5 greater */
91
92     /* N>25, search attributes work */
93     Q( "@attr 2=4 @attr gils 1=2040 @attr 4=109 25",2);
94
95     /* N=41, get rec1 only */
96     Q( "@attr 2=3 @attr gils 1=2040 @attr 4=109 41",1);
97
98     /* N=49, get both records */
99     Q( "@attr 2=3 @attr gils 1=2040 @attr 4=109 49",2);
100
101     /* W=-120 get both records */
102     Q( "@attr 2=3 @attr gils 1=2038 @attr 4=109 -120",2);
103
104     /* W<-122 get only rec1 */
105     Q( "@attr 2=1 @attr gils 1=2038 @attr 4=109 '-120' ",1);
106
107     /* N=41 and N=49 get only rec2 */
108     Q( "@attr 2=3 @attr gils 1=2040 @attr 4=109 \"41 49\" ",1);
109
110     zebra_commit (zh);
111     zebra_close (zh);
112     zebra_stop (zs);
113
114     nmem_exit ();
115     xmalloc_trav ("x");
116     logf(LOG_LOG,"All tests OK");
117     exit (0);
118 }