Omit CVS Id. Update copyright year.
[idzebra-moved-to-github.git] / test / api / t8.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1995-2008 Index Data
3
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 /** t8: test numeric attributes */
21
22 #include "testlib.h"
23
24 const char *recs[] = {
25         "<gils>\n"
26         "  <title>My title</title>\n"
27         "  <abstract>test record with single coordset, negatives</abstract>\n"
28         "  <Spatial-Domain><Bounding-Coordinates>\n"
29         "    <West-Bounding-Coordinate> -120 </West-Bounding-Coordinate>\n"
30         "    <East-Bounding-Coordinate> -102 </East-Bounding-Coordinate>\n"
31         "    <North-Bounding-Coordinate>  49 </North-Bounding-Coordinate>\n"
32         "    <South-Bounding-Coordinate>  31 </South-Bounding-Coordinate>\n"
33         "  </Bounding-Coordinates></Spatial-Domain>"
34         "</gils>\n",
35
36         "<gils>\n"
37         "  <title>Another title</title>\n"
38         "  <abstract>second test with two coord sets</abstract>\n"
39         "  <Spatial-Domain><Bounding-Coordinates>\n"
40         "    <West-Bounding-Coordinate> -120 </West-Bounding-Coordinate>\n"
41         "    <East-Bounding-Coordinate> -102 </East-Bounding-Coordinate>\n"
42         "    <North-Bounding-Coordinate>  49 </North-Bounding-Coordinate>\n"
43         "    <South-Bounding-Coordinate>  31 </South-Bounding-Coordinate>\n"
44         "  </Bounding-Coordinates>"
45         "  <Bounding-Coordinates>\n"
46         "    <West-Bounding-Coordinate> -125 </West-Bounding-Coordinate>\n"
47         "    <East-Bounding-Coordinate> -108 </East-Bounding-Coordinate>\n"
48         "    <North-Bounding-Coordinate>  41 </North-Bounding-Coordinate>\n"
49         "    <South-Bounding-Coordinate>  25 </South-Bounding-Coordinate>\n"
50         "  </Bounding-Coordinates></Spatial-Domain>"
51         "</gils>\n",
52         0};
53         
54
55 static void tst(int argc, char **argv)
56 {
57     ZebraService zs = tl_start_up("zebra8.cfg", argc, argv);
58     ZebraHandle zh = zebra_open (zs, 0);
59
60     YAZ_CHECK(tl_init_data(zh, recs));
61
62     /* couple of simple queries just to see that we have indexed the stuff */
63     YAZ_CHECK(tl_query(zh,  "@attr 1=4 title", 2));
64     
65     /* 1=2038: West-Bounding-Coordinate 2039: East: 2040: North: 2041 South*/
66     /* 4=109: numeric string */
67     /* 2=3: equal  2=1: less, 2=4: greater or equal 2=5 greater */
68
69     /* N>=25, search attributes work */
70     YAZ_CHECK(tl_query(zh,  "@attr 2=4 @attr gils 1=2040 @attr 4=109 25", 2));
71
72     /* N>49, search attributes work */
73     YAZ_CHECK(tl_query(zh,  "@attr 2=5 @attr gils 1=2040 @attr 4=109 49", 0));
74
75     /* N>=49, search attributes work */
76     YAZ_CHECK(tl_query(zh,  "@attr 2=4 @attr gils 1=2040 @attr 4=109 49", 2));
77
78     /* N>48, search attributes work */
79     YAZ_CHECK(tl_query(zh,  "@attr 2=5 @attr gils 1=2040 @attr 4=109 48", 2));
80
81     /* N<48, search attributes work */
82     YAZ_CHECK(tl_query(zh,  "@attr 2=1 @attr gils 1=2040 @attr 4=109 48", 1));
83
84     /* N<=48, search attributes work */
85     YAZ_CHECK(tl_query(zh,  "@attr 2=2 @attr gils 1=2040 @attr 4=109 48", 1));
86
87     /* N=41, get rec1 only */
88     YAZ_CHECK(tl_query(zh,  "@attr 2=3 @attr gils 1=2040 @attr 4=109 41", 1));
89
90     /* N=49, get both records */
91     YAZ_CHECK(tl_query(zh,  "@attr 2=3 @attr gils 1=2040 @attr 4=109 49", 2));
92
93     /* W=-120 get both records */
94     YAZ_CHECK(tl_query(zh,  "@attr 2=3 @attr gils 1=2038 @attr 4=109 -120", 2));
95
96     /* W<-122 get only rec1 */
97     YAZ_CHECK(tl_query(zh,  "@attr 2=1 @attr gils 1=2038 @attr 4=109 '-120' ", 1));
98
99     /* N=41 and N=49 get only rec2 */
100     YAZ_CHECK(tl_query(zh, "@attr 2=3 @attr gils 1=2040 @attr 4=109 \"41 49\" ", 1));
101
102     YAZ_CHECK(tl_close_down(zh, zs));
103 }
104
105 TL_MAIN
106 /*
107  * Local variables:
108  * c-basic-offset: 4
109  * indent-tabs-mode: nil
110  * End:
111  * vim: shiftwidth=4 tabstop=8 expandtab
112  */
113