added conf_service creator inclusive metadata and sortkey assigners, added unittests...
[pazpar2-moved-to-github.git] / src / test_config.c
1 /* $Id: test_config.c,v 1.1 2007-04-19 19:42:30 marc Exp $
2    Copyright (c) 2006-2007, Index Data.
3
4 This file is part of Pazpar2.
5
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <sys/time.h>
26 #include <unistd.h>
27 #include <sys/socket.h>
28 #include <netdb.h>
29 #include <signal.h>
30 #include <ctype.h>
31 #include <assert.h>
32
33 #if HAVE_CONFIG_H
34 #include "cconfig.h"
35 #endif
36
37 #define USE_TIMING 0
38 #if USE_TIMING
39 #include <yaz/timing.h>
40 #endif
41
42 #include <yaz/test.h>
43
44
45 //#include "pazpar2.h"
46 #include "config.h"
47
48
49
50 void test_conf_service(int argc, char **argv)
51 {
52   NMEM  nmem = nmem_create();
53
54   struct conf_service *service = 0;
55   service = conf_service_create(nmem, 4, 1);
56
57   YAZ_CHECK(service);
58
59   // expected metadata failures
60   YAZ_CHECK(!conf_service_add_metadata(0, service, 0, "dead_nmem",
61                                       Metadata_type_generic,
62                                       Metadata_merge_unique,
63                                       1, 1, 1, 0));
64
65   YAZ_CHECK(!conf_service_add_metadata(nmem, 0, 0, "service_needed",
66                                        Metadata_type_generic, 
67                                        Metadata_merge_unique,
68                                        1, 1, 1, 0));
69
70   YAZ_CHECK(!conf_service_add_metadata(nmem, service, -1, "out_of_bounds",
71                                        Metadata_type_generic,
72                                        Metadata_merge_unique,
73                                        1, 1, 1, 0));
74
75   YAZ_CHECK(!conf_service_add_metadata(nmem, service, 4, "out_of_bounds",
76                                        Metadata_type_generic,
77                                        Metadata_merge_unique,
78                                        1, 1, 1, 0));
79
80   YAZ_CHECK(!conf_service_add_metadata(nmem, service, 0, 0,  //missing name
81                                        Metadata_type_generic,
82                                        Metadata_merge_unique,
83                                        1, 1, 1, 0));
84
85   // expected metadata sucesses
86   YAZ_CHECK(conf_service_add_metadata(nmem, service, 0, "title",
87                                       Metadata_type_generic,
88                                       Metadata_merge_unique,
89                                       1, 1, 1, 0));
90
91   YAZ_CHECK(conf_service_add_metadata(nmem, service, 1, "author",
92                                       Metadata_type_generic,
93                                       Metadata_merge_longest,
94                                       1, 1, 1, 0));
95
96   YAZ_CHECK(conf_service_add_metadata(nmem, service, 2, "isbn",
97                                       Metadata_type_number,
98                                       Metadata_merge_no,
99                                       1, 1, 1, 0));
100
101   YAZ_CHECK(conf_service_add_metadata(nmem, service, 3, "year",
102                                       Metadata_type_year,
103                                       Metadata_merge_range,
104                                       1, 1, 1, 0));
105
106
107   // expected sortkey failures
108   YAZ_CHECK(!conf_service_add_sortkey(0, service, 0, "dead_nmem",
109                                      Metadata_sortkey_relevance));
110
111   YAZ_CHECK(!conf_service_add_sortkey(nmem, 0, 0, "service_neeeded",
112                                      Metadata_sortkey_numeric));
113
114   YAZ_CHECK(!conf_service_add_sortkey(nmem, service, -1, "out_of_bounds",
115                                      Metadata_sortkey_skiparticle));
116
117   YAZ_CHECK(!conf_service_add_sortkey(nmem, service, -1, "out_of_bounds",
118                                      Metadata_sortkey_string));
119
120   YAZ_CHECK(!conf_service_add_sortkey(nmem, service, 1, "out_of_bounds",
121                                      Metadata_sortkey_relevance));
122
123   YAZ_CHECK(!conf_service_add_sortkey(nmem, service, 0, 0, //missing name
124                                      Metadata_sortkey_relevance));
125
126
127   // expected sortkey sucess
128   YAZ_CHECK(conf_service_add_sortkey(nmem, service, 0, "title",
129                                      Metadata_sortkey_relevance));
130   
131
132
133
134
135   nmem_destroy(nmem);
136
137   //YAZ_CHECK(0 == 0);
138   //YAZ_CHECK_EQ(0, 1);
139
140 }
141
142
143 int main(int argc, char **argv)
144 {
145     YAZ_CHECK_INIT(argc, argv); 
146     YAZ_CHECK_LOG();
147
148     test_conf_service(argc, argv);
149     
150     YAZ_CHECK_TERM;
151 }
152
153
154
155
156 /*
157  * Local variables:
158  * c-basic-offset: 4
159  * indent-tabs-mode: nil
160  * End:
161  * vim: shiftwidth=4 tabstop=8 expandtab
162  */