0ced9c235460b1283a895fd583d05f65d9fea379
[idzebra-moved-to-github.git] / test / api / test_sort3.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2011 Index Data
3
4 Zebra 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 Zebra 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 /** \file
21     \brief sort using various sortindex types
22  */
23
24 #if HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 #include <yaz/test.h>
28 #include "testlib.h"
29
30 const char *myrec[] = {
31     /* 2 */
32     "<gils>\n"
33     "  <title>My title</title>\n"
34     "  <title>X</title>\n"
35     "</gils>\n",
36
37     /* 3 */
38     "<gils>\n"
39     "  <title>My x title</title>\n"
40     "  <title>B</title>\n"
41     "</gils>\n",
42
43     /* 4 */
44     "<gils>\n"
45     "  <title>My title x</title>\n"
46     "  <title>A</title>\n"
47     "</gils>\n" ,
48     0} ;
49
50 static void tst_sortindex(int argc, char **argv, const char *type)
51 {
52     zint ids[5];
53     Res res = res_open(0, 0);
54
55     ZebraService zs = tl_start_up("test_sort3.cfg", argc, argv);
56     ZebraHandle  zh;
57
58     res_set(res, "sortindex", type);
59
60     zh = zebra_open(zs, res);
61
62     YAZ_CHECK(tl_init_data(zh, myrec));
63
64     if (strcmp(type, "m"))
65     {
66         /* i, f only takes first title into consideration */
67         ids[0] = 2;
68         ids[1] = 4;
69         ids[2] = 3;
70     }
71     else
72     {
73         /* m takes all titles into consideration */
74         ids[0] = 4;
75         ids[1] = 3;
76         ids[2] = 2;
77     }
78     YAZ_CHECK(tl_sort(zh, "@or @attr 1=4 title @attr 7=1 @attr 1=4 0", 3, ids));
79
80     if (strcmp(type, "m"))
81     {
82         /* i, f only takes first title into consideration */
83         ids[0] = 3;
84         ids[1] = 4;
85         ids[2] = 2;
86     }
87     else
88     {
89         /* m takes all titles into consideration */
90         ids[0] = 2;
91         ids[1] = 3;
92         ids[2] = 4;
93     }
94     YAZ_CHECK(tl_sort(zh, "@or @attr 1=4 title @attr 7=2 @attr 1=4 0", 3, ids));
95
96     YAZ_CHECK(tl_close_down(zh, zs));
97 }
98
99 static void tst(int argc, char **argv)
100 {
101     tst_sortindex(argc, argv, "i");
102     tst_sortindex(argc, argv, "f");
103     tst_sortindex(argc, argv, "m");
104 }
105
106 TL_MAIN
107
108 /*
109  * Local variables:
110  * c-basic-offset: 4
111  * c-file-style: "Stroustrup"
112  * indent-tabs-mode: nil
113  * End:
114  * vim: shiftwidth=4 tabstop=8 expandtab
115  */
116