Do not write zebrasrv.pid in daemon mode
[idzebra-moved-to-github.git] / util / tst_index_rules.c
1 /* $Id: tst_index_rules.c,v 1.2 2007-10-24 13:55:55 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 <charmap.h>
24 #include <yaz/test.h>
25 #include <index_rules.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 const char *xml_str = 
30 "    <indexrules>"
31 "      <indexrule id=\"*:w:el\" position=\"1\" alwaysmatches=\"1\" firstinfield=\"1\"\n"
32 "       locale=\"el\">\n"
33 "        <!-- conversion rules for words -->\n"
34 "      </indexrule>\n"
35 "      <indexrule id=\"*:w\" position=\"1\" alwaysmatches=\"1\" firstinfield=\"1\"\n"
36 "       locale=\"en\">\n"
37 "        <!-- conversion rules for words -->\n"
38 "      </indexrule>\n"
39 "      <indexrule id=\"*:p\" position=\"0\" alwaysmatches=\"0\" firstinfield=\"0\"\n"
40 "        locale=\"en\">\n"
41 "        <!-- conversion rules for phrase -->\n"
42 "      </indexrule>\n"
43 "      <indexrule id=\"*:s\" sort=\"1\" \n"
44 "        locale=\"en\">\n"
45 "        <!-- conversion rules for phrase -->\n"
46 "      </indexrule>\n"
47 "    </indexrules>\n"
48 ;
49
50 int compare_lookup(zebra_index_rules_t r, const char *id,
51                    const char *expected_id)
52 {
53     const char *got_id = zebra_index_rule_lookup_str(r, id);
54     if (!got_id && !expected_id)
55         return 1;  /* none expected */
56
57     if (got_id && expected_id && !strcmp(got_id, expected_id))
58         return 1;
59     return 0;
60 }
61
62 void tst1(void)
63 {
64     xmlDocPtr doc = xmlParseMemory(xml_str, strlen(xml_str));
65
66     YAZ_CHECK(doc);
67     if (doc)
68     {
69         zebra_index_rules_t rules = zebra_index_rules_create_doc(doc);
70         YAZ_CHECK(rules);
71
72         if (!rules)
73             return ;
74         
75         YAZ_CHECK(compare_lookup(rules, "title:s", "*:s"));
76         YAZ_CHECK(compare_lookup(rules, "title:sx", 0));
77         YAZ_CHECK(compare_lookup(rules, "title:Sx", 0));
78         YAZ_CHECK(compare_lookup(rules, "any:w", "*:w"));
79         YAZ_CHECK(compare_lookup(rules, "any:w:en", 0));
80         YAZ_CHECK(compare_lookup(rules, "any:w:el", "*:w:el"));
81         
82         {
83             int i, iter = 3333;
84             for (i = 0; i < iter; i++)
85             {
86                 compare_lookup(rules, "title:s", "*:s");
87                 compare_lookup(rules, "title:sx", 0);
88                 compare_lookup(rules, "title:Sx", 0);
89             }
90         }
91
92         zebra_index_rules_destroy(rules);
93     }
94 }
95
96 int main(int argc, char **argv)
97 {
98     YAZ_CHECK_INIT(argc, argv);
99     YAZ_CHECK_LOG();
100
101     tst1();
102
103     YAZ_CHECK_TERM;
104 }
105
106 /*
107  * Local variables:
108  * c-basic-offset: 4
109  * indent-tabs-mode: nil
110  * End:
111  * vim: shiftwidth=4 tabstop=8 expandtab
112  */
113