17c63817fff2c215e8600652f965cc3d9550d683
[pazpar2-moved-to-github.git] / src / test_config.c
1 /* This file is part of Pazpar2.
2    Copyright (C) 2006-2009 Index Data
3
4 Pazpar2 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 Pazpar2 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 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #define USE_TIMING 0
25 #if USE_TIMING
26 #include <yaz/timing.h>
27 #endif
28
29 #include <yaz/test.h>
30
31 #include "pazpar2_config.h"
32
33
34
35 void test_conf_service(int argc, char **argv)
36 {
37   NMEM  nmem = nmem_create();
38
39   struct conf_service *service = 0;
40   service = conf_service_create(nmem, 4, 3);
41
42   YAZ_CHECK(service);
43
44   // expected metadata failures
45   YAZ_CHECK(!conf_service_add_metadata(0, service, 0, "dead_nmem",
46                                       Metadata_type_generic,
47                                       Metadata_merge_unique,
48                                       Metadata_setting_no,
49                                       1, 1, 1, 0));
50
51   YAZ_CHECK(!conf_service_add_metadata(nmem, 0, 0, "service_needed",
52                                        Metadata_type_generic, 
53                                        Metadata_merge_unique,
54                                        Metadata_setting_no,
55                                        1, 1, 1, 0));
56
57   YAZ_CHECK(!conf_service_add_metadata(nmem, service, -1, "out_of_bounds",
58                                        Metadata_type_generic,
59                                        Metadata_merge_unique,
60                                        Metadata_setting_no,
61                                        1, 1, 1, 0));
62
63   YAZ_CHECK(!conf_service_add_metadata(nmem, service, 4, "out_of_bounds",
64                                        Metadata_type_generic,
65                                        Metadata_merge_unique,
66                                        Metadata_setting_no,
67                                        1, 1, 1, 0));
68
69   YAZ_CHECK(!conf_service_add_metadata(nmem, service, 0, 0,  //missing name
70                                        Metadata_type_generic,
71                                        Metadata_merge_unique,
72                                        Metadata_setting_no,
73                                        1, 1, 1, 0));
74
75   // expected metadata sucesses
76   YAZ_CHECK(conf_service_add_metadata(nmem, service, 0, "title",
77                                       Metadata_type_generic,
78                                       Metadata_merge_unique,
79                                        Metadata_setting_no,
80                                       1, 1, 1, 0));
81
82   YAZ_CHECK(conf_service_add_metadata(nmem, service, 1, "author",
83                                       Metadata_type_generic,
84                                       Metadata_merge_longest,
85                                        Metadata_setting_no,
86                                       1, 1, 1, 0));
87
88   YAZ_CHECK(conf_service_add_metadata(nmem, service, 2, "isbn",
89                                       Metadata_type_number,
90                                       Metadata_merge_no,
91                                        Metadata_setting_no,
92                                       1, 1, 1, 0));
93
94   YAZ_CHECK(conf_service_add_metadata(nmem, service, 3, "year",
95                                       Metadata_type_year,
96                                       Metadata_merge_range,
97                                        Metadata_setting_no,
98                                       1, 1, 1, 0));
99
100
101   // expected sortkey failures
102   YAZ_CHECK(!conf_service_add_sortkey(0, service, 0, "dead_nmem",
103                                      Metadata_sortkey_relevance));
104
105   YAZ_CHECK(!conf_service_add_sortkey(nmem, 0, 0, "service_neeeded",
106                                      Metadata_sortkey_numeric));
107
108   YAZ_CHECK(!conf_service_add_sortkey(nmem, service, -1, "out_of_bounds",
109                                      Metadata_sortkey_skiparticle));
110
111   YAZ_CHECK(!conf_service_add_sortkey(nmem, service, -1, "out_of_bounds",
112                                      Metadata_sortkey_string));
113
114   YAZ_CHECK(!conf_service_add_sortkey(nmem, service, 3, "out_of_bounds",
115                                      Metadata_sortkey_relevance));
116
117   YAZ_CHECK(!conf_service_add_sortkey(nmem, service, 0, 0, //missing name
118                                      Metadata_sortkey_relevance));
119
120
121   // expected sortkey sucess
122   YAZ_CHECK(conf_service_add_sortkey(nmem, service, 0, "relevance",
123                                      Metadata_sortkey_relevance));
124
125   YAZ_CHECK(conf_service_add_sortkey(nmem, service, 1, "title",
126                                      Metadata_sortkey_string));
127   
128   YAZ_CHECK(conf_service_add_sortkey(nmem, service, 2, "year",
129                                      Metadata_sortkey_numeric));
130   
131
132
133
134
135
136   nmem_destroy(nmem);
137
138   //YAZ_CHECK(0 == 0);
139   //YAZ_CHECK_EQ(0, 1);
140
141 }
142
143
144 int main(int argc, char **argv)
145 {
146     YAZ_CHECK_INIT(argc, argv); 
147     YAZ_CHECK_LOG();
148
149     test_conf_service(argc, argv);
150     
151     YAZ_CHECK_TERM;
152 }
153
154
155
156
157 /*
158  * Local variables:
159  * c-basic-offset: 4
160  * indent-tabs-mode: nil
161  * End:
162  * vim: shiftwidth=4 tabstop=8 expandtab
163  */