Removed unneeded include.
[idzebra-moved-to-github.git] / util / tst_index_types.c
1 /* $Id: tst_index_types.c,v 1.2 2007-10-25 09:23:34 adam Exp $
2    Copyright (C) 1995-2007
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21 */
22
23 #include <yaz/test.h>
24 #include <index_types.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 const char *xml_str = 
29 "    <indextypes>"
30 "      <indextype id=\"*:w:el\" position=\"1\" alwaysmatches=\"1\" firstinfield=\"1\"\n"
31 "       locale=\"el\">\n"
32 "        <!-- conversion rules for words -->\n"
33 "      </indextype>\n"
34 "      <indextype id=\"*:w\" position=\"1\" alwaysmatches=\"1\" firstinfield=\"1\"\n"
35 "       locale=\"en\">\n"
36 "        <!-- conversion rules for words -->\n"
37 "      </indextype>\n"
38 "      <indextype id=\"*:p\" position=\"0\" alwaysmatches=\"0\" firstinfield=\"0\"\n"
39 "        locale=\"en\">\n"
40 "        <!-- conversion rules for phrase -->\n"
41 "      </indextype>\n"
42 "      <indextype id=\"*:s\" sort=\"1\" \n"
43 "        locale=\"en\">\n"
44 "        <!-- conversion rules for phrase -->\n"
45 "      </indextype>\n"
46 "    </indextypes>\n"
47 ;
48
49 int compare_lookup(zebra_index_types_t r, const char *id,
50                    const char *expected_id)
51 {
52     const char *got_id = zebra_index_type_lookup_str(r, id);
53     if (!got_id && !expected_id)
54         return 1;  /* none expected */
55
56     if (got_id && expected_id && !strcmp(got_id, expected_id))
57         return 1;
58     return 0;
59 }
60
61 void tst1(void)
62 {
63     xmlDocPtr doc = xmlParseMemory(xml_str, strlen(xml_str));
64
65     YAZ_CHECK(doc);
66     if (doc)
67     {
68         zebra_index_types_t rules = zebra_index_types_create_doc(doc);
69         YAZ_CHECK(rules);
70
71         if (!rules)
72             return ;
73         
74         YAZ_CHECK(compare_lookup(rules, "title:s", "*:s"));
75         YAZ_CHECK(compare_lookup(rules, "title:sx", 0));
76         YAZ_CHECK(compare_lookup(rules, "title:Sx", 0));
77         YAZ_CHECK(compare_lookup(rules, "any:w", "*:w"));
78         YAZ_CHECK(compare_lookup(rules, "any:w:en", 0));
79         YAZ_CHECK(compare_lookup(rules, "any:w:el", "*:w:el"));
80         
81         {
82             int i, iter = 3333;
83             for (i = 0; i < iter; i++)
84             {
85                 compare_lookup(rules, "title:s", "*:s");
86                 compare_lookup(rules, "title:sx", 0);
87                 compare_lookup(rules, "title:Sx", 0);
88             }
89         }
90
91         zebra_index_types_destroy(rules);
92     }
93 }
94
95 int main(int argc, char **argv)
96 {
97     YAZ_CHECK_INIT(argc, argv);
98     YAZ_CHECK_LOG();
99
100     tst1();
101
102     YAZ_CHECK_TERM;
103 }
104
105 /*
106  * Local variables:
107  * c-basic-offset: 4
108  * indent-tabs-mode: nil
109  * End:
110  * vim: shiftwidth=4 tabstop=8 expandtab
111  */
112