52d524a303dedb1fade0b90b08e6df53e968918f
[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     struct conf_service *service = 0;
38     service = conf_service_create(4, 3, 0);
39
40     YAZ_CHECK(service);
41
42     // expected metadata failures
43     YAZ_CHECK(!conf_service_add_metadata(0, 0, "service_needed",
44                                          Metadata_type_generic, 
45                                          Metadata_merge_unique,
46                                          Metadata_setting_no,
47                                          1, 1, 1, 0,
48                                          Metadata_mergekey_no));
49
50     YAZ_CHECK(!conf_service_add_metadata(service, -1, "out_of_bounds",
51                                          Metadata_type_generic,
52                                          Metadata_merge_unique,
53                                          Metadata_setting_no,
54                                          1, 1, 1, 0,
55                                          Metadata_mergekey_no));
56
57     YAZ_CHECK(!conf_service_add_metadata(service, 4, "out_of_bounds",
58                                          Metadata_type_generic,
59                                          Metadata_merge_unique,
60                                          Metadata_setting_no,
61                                          1, 1, 1, 0,
62                                          Metadata_mergekey_no));
63
64     YAZ_CHECK(!conf_service_add_metadata(service, 0, 0,  //missing name
65                                          Metadata_type_generic,
66                                          Metadata_merge_unique,
67                                          Metadata_setting_no,
68                                          1, 1, 1, 0,
69                                          Metadata_mergekey_no));
70
71     // expected metadata sucesses
72     YAZ_CHECK(conf_service_add_metadata(service, 0, "title",
73                                         Metadata_type_generic,
74                                         Metadata_merge_unique,
75                                         Metadata_setting_no,
76                                         1, 1, 1, 0,
77                                         Metadata_mergekey_no));
78
79     YAZ_CHECK(conf_service_add_metadata(service, 1, "author",
80                                         Metadata_type_generic,
81                                         Metadata_merge_longest,
82                                         Metadata_setting_no,
83                                         1, 1, 1, 0,
84                                         Metadata_mergekey_no));
85
86     YAZ_CHECK(conf_service_add_metadata(service, 2, "isbn",
87                                         Metadata_type_number,
88                                         Metadata_merge_no,
89                                         Metadata_setting_no,
90                                         1, 1, 1, 0,
91                                         Metadata_mergekey_no));
92
93     YAZ_CHECK(conf_service_add_metadata(service, 3, "year",
94                                         Metadata_type_year,
95                                         Metadata_merge_range,
96                                         Metadata_setting_no,
97                                         1, 1, 1, 0,
98                                         Metadata_mergekey_no));
99
100
101     // expected sortkey failures
102     YAZ_CHECK(!conf_service_add_sortkey(service, -1, "out_of_bounds",
103                                         Metadata_sortkey_skiparticle));
104
105     YAZ_CHECK(!conf_service_add_sortkey(service, -1, "out_of_bounds",
106                                         Metadata_sortkey_string));
107
108     YAZ_CHECK(!conf_service_add_sortkey(service, 3, "out_of_bounds",
109                                         Metadata_sortkey_relevance));
110
111     YAZ_CHECK(!conf_service_add_sortkey(service, 0, 0, //missing name
112                                         Metadata_sortkey_relevance));
113
114
115     // expected sortkey sucess
116     YAZ_CHECK(conf_service_add_sortkey(service, 0, "relevance",
117                                        Metadata_sortkey_relevance));
118
119     YAZ_CHECK(conf_service_add_sortkey(service, 1, "title",
120                                        Metadata_sortkey_string));
121   
122     YAZ_CHECK(conf_service_add_sortkey(service, 2, "year",
123                                        Metadata_sortkey_numeric));
124 }
125
126
127 int main(int argc, char **argv)
128 {
129     YAZ_CHECK_INIT(argc, argv); 
130     YAZ_CHECK_LOG();
131
132     test_conf_service(argc, argv);
133     
134     YAZ_CHECK_TERM;
135 }
136
137
138
139
140 /*
141  * Local variables:
142  * c-basic-offset: 4
143  * c-file-style: "Stroustrup"
144  * indent-tabs-mode: nil
145  * End:
146  * vim: shiftwidth=4 tabstop=8 expandtab
147  */
148