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