Refactored more stuff into testlib, cleaned up the tests.
[idzebra-moved-to-github.git] / test / api / t8.c
1 /* $Id: t8.c,v 1.5 2004-10-29 13:02:39 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 "testlib.h"
26
27
28         
29 const char *recs[] = {
30         "<gils>\n"
31         "  <title>My title</title>\n"
32         "  <abstract>test record with single coordset, negatives</abstract>\n"
33         "  <Spatial-Domain><Bounding-Coordinates>\n"
34         "    <West-Bounding-Coordinate> -120 </West-Bounding-Coordinate>\n"
35         "    <East-Bounding-Coordinate> -102 </East-Bounding-Coordinate>\n"
36         "    <North-Bounding-Coordinate>  49 </North-Bounding-Coordinate>\n"
37         "    <South-Bounding-Coordinate>  31 </South-Bounding-Coordinate>\n"
38         "  </Bounding-Coordinates></Spatial-Domain>"
39         "</gils>\n",
40
41         "<gils>\n"
42         "  <title>Another title</title>\n"
43         "  <abstract>second test with two coord sets</abstract>\n"
44         "  <Spatial-Domain><Bounding-Coordinates>\n"
45         "    <West-Bounding-Coordinate> -120 </West-Bounding-Coordinate>\n"
46         "    <East-Bounding-Coordinate> -102 </East-Bounding-Coordinate>\n"
47         "    <North-Bounding-Coordinate>  49 </North-Bounding-Coordinate>\n"
48         "    <South-Bounding-Coordinate>  31 </South-Bounding-Coordinate>\n"
49         "  </Bounding-Coordinates>"
50         "  <Bounding-Coordinates>\n"
51         "    <West-Bounding-Coordinate> -125 </West-Bounding-Coordinate>\n"
52         "    <East-Bounding-Coordinate> -108 </East-Bounding-Coordinate>\n"
53         "    <North-Bounding-Coordinate>  41 </North-Bounding-Coordinate>\n"
54         "    <South-Bounding-Coordinate>  25 </South-Bounding-Coordinate>\n"
55         "  </Bounding-Coordinates></Spatial-Domain>"
56         "</gils>\n",
57         0};
58         
59
60
61
62 int main(int argc, char **argv)
63 {
64     ZebraService zs = start_up("zebra8.cfg", argc, argv);
65     ZebraHandle  zh = zebra_open (zs);
66
67     init_data(zh, recs);
68
69 #define Q(q,n) do_query(__LINE__,zh,q,n)
70     /* couple of simple queries just to see that we have indexed the stuff */
71     Q( "@attr 1=4 title",2 );
72     Q( "title",2 );
73     
74     /* 1=2038: West-Bounding-Coordinate 2039: East: 2040: North: 2041 South*/
75     /* 4=109: numeric string */
76     /* 2=3: equal  2=1: less, 2=4: greater or equal 2=5 greater */
77
78     /* N>25, search attributes work */
79     Q( "@attr 2=4 @attr gils 1=2040 @attr 4=109 25",2);
80
81     /* N=41, get rec1 only */
82     Q( "@attr 2=3 @attr gils 1=2040 @attr 4=109 41",1);
83
84     /* N=49, get both records */
85     Q( "@attr 2=3 @attr gils 1=2040 @attr 4=109 49",2);
86
87     /* W=-120 get both records */
88     Q( "@attr 2=3 @attr gils 1=2038 @attr 4=109 -120",2);
89
90     /* W<-122 get only rec1 */
91     Q( "@attr 2=1 @attr gils 1=2038 @attr 4=109 '-120' ",1);
92
93     /* N=41 and N=49 get only rec2 */
94     Q( "@attr 2=3 @attr gils 1=2040 @attr 4=109 \"41 49\" ",1);
95
96     return close_down(zh,zs,0);
97 }