adding additional checks for correct side conditions on next metadata in record
[pazpar2-moved-to-github.git] / src / test_record.c
1 /* $Id: test_record.c,v 1.2 2007-04-24 13:50:07 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 #include "record.h"
48 //#include "pazpar2.h"
49
50
51 void test_record(int argc, char **argv)
52 {
53   NMEM  nmem = nmem_create();
54
55   struct conf_service *service = 0; 
56   struct record *record = 0;
57
58   struct client *client = 0;
59
60   service =  conf_service_create(nmem, 4, 3);
61   YAZ_CHECK(service);
62
63   YAZ_CHECK(conf_service_add_metadata(nmem, service, 0, "title",
64                             Metadata_type_generic, Metadata_merge_unique,
65                             1, 1, 1, 0));
66
67   YAZ_CHECK(conf_service_add_metadata(nmem, service, 1, "author",
68                             Metadata_type_generic, Metadata_merge_longest,
69                             1, 1, 1, 0));
70
71   YAZ_CHECK(conf_service_add_metadata(nmem, service, 2, "isbn",
72                             Metadata_type_number, Metadata_merge_no,
73                             1, 1, 1, 0));
74
75   YAZ_CHECK(conf_service_add_metadata(nmem, service, 3, "year",
76                             Metadata_type_year, Metadata_merge_range,
77                             1, 1, 1, 0));
78
79   YAZ_CHECK(conf_service_add_sortkey(nmem, service, 0, "relevance",
80                                      Metadata_sortkey_relevance));
81
82   YAZ_CHECK(conf_service_add_sortkey(nmem, service, 1, "title",
83                                      Metadata_sortkey_string));
84   
85   YAZ_CHECK(conf_service_add_sortkey(nmem, service, 2, "year",
86                                      Metadata_sortkey_numeric));
87   
88
89
90
91   // testing record things
92   record = record_create(nmem, 4, 3);
93   YAZ_CHECK(record);
94
95   // why on earth do we have a client dangeling from the record ??
96   record->client = client;
97
98   char * bla = "blabla";
99   union data_types data_text;
100   data_text.text = bla;
101
102   
103   union data_types data_num;
104   data_num.number.min = 2;
105   data_num.number.max = 5;
106
107   struct record_metadata * tmp_md = 0;
108   tmp_md = record_metadata_insert(nmem, &(record->metadata[0]), data_text);
109   YAZ_CHECK(tmp_md);
110   YAZ_CHECK(0 == record->metadata[0]->next);
111
112   tmp_md = record_metadata_insert(nmem, &(record->metadata[0]->next), 
113                                   data_text);
114   YAZ_CHECK(tmp_md);
115   YAZ_CHECK(record->metadata[0]->next);
116
117   YAZ_CHECK(record_add_metadata_field_id(nmem, record, 3, data_num));
118   YAZ_CHECK(0 == record->metadata[3]->next);
119   YAZ_CHECK(record_add_metadata_field_id(nmem, record, 3, data_num));
120   YAZ_CHECK(record->metadata[3]->next);
121
122   YAZ_CHECK(record_add_metadata(nmem, record, service, "author", data_text));
123   YAZ_CHECK(0 == record->metadata[1]->next);
124   YAZ_CHECK(record_add_metadata(nmem, record, service, "author", data_text));
125   YAZ_CHECK(record->metadata[1]->next);
126
127
128   YAZ_CHECK(record_assign_sortkey_field_id(nmem, record, 0, data_text));
129   YAZ_CHECK(record_assign_sortkey_field_id(nmem, record, 1, data_text));
130   YAZ_CHECK(record_assign_sortkey_field_id(nmem, record, 2, data_num));
131
132
133   YAZ_CHECK(record_assign_sortkey(nmem, record, service, "relevance", data_text));
134   YAZ_CHECK(record_assign_sortkey(nmem, record, service, "title", data_text));
135   YAZ_CHECK(record_assign_sortkey(nmem, record, service, "year", data_num));
136
137
138
139
140   nmem_destroy(nmem);
141
142   //YAZ_CHECK(0 == 0);
143   //YAZ_CHECK_EQ(0, 1);
144 }
145
146
147 int main(int argc, char **argv)
148 {
149     YAZ_CHECK_INIT(argc, argv); 
150     YAZ_CHECK_LOG(); 
151
152
153     test_record(argc, argv); 
154
155     
156     YAZ_CHECK_TERM;
157 }
158
159
160
161
162 /*
163  * Local variables:
164  * c-basic-offset: 4
165  * indent-tabs-mode: nil
166  * End:
167  * vim: shiftwidth=4 tabstop=8 expandtab
168  */