1fecf13fd2029689535c9d47ba664799f90a3e03
[idzebra-moved-to-github.git] / test / api / test_sort1.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 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include "testlib.h"
24
25 const char *myrec[] = {
26     "<sort1>\n"
27     "  <title>first computer</title>\n"
28     "  <dateTime>2</dateTime>\n"
29     "  <cost>2</cost>\n"
30     "</sort1>\n"
31     ,
32     "<sort1>\n"
33     "  <title>second computer</title>\n"
34     "  <dateTime>1</dateTime>\n"
35     "  <cost>21</cost>\n"
36     "</sort1>\n"
37     ,
38     "<sort1>\n"
39     "  <title>3rd computer</title>\n"
40     "  <dateTime>a^3</dateTime>\n"
41     "  <cost>15</cost>\n"
42     "</sort1>\n"
43     ,
44     "<sort1>\n"
45     "  <title>fourth computer</title>\n"
46     "  <dateTime>4</dateTime>\n"
47     "  <cost>11</cost>\n"
48     "</sort1>\n"
49     ,
50     0
51 };
52
53 static void tst(int argc, char **argv)
54 {
55     ZebraService zs = tl_start_up("test_sort1.cfg", argc, argv);
56     ZebraHandle  zh = zebra_open(zs, 0);
57     zint ids[5];
58
59     YAZ_CHECK(tl_init_data(zh, myrec));
60
61     ids[0] = 3;
62     ids[1] = 2;
63     ids[2] = 4;
64     ids[3] = 5;
65     YAZ_CHECK(tl_sort(zh, "@or @attr 1=4 computer @attr 7=1 @attr 1=30 0", 4, ids));
66     YAZ_CHECK(tl_sort(zh, "@or @attr 1=4 computer @attr 7=1 @attr 1=Date 0", 4, ids));
67
68     ids[0] = 5;
69     ids[1] = 4;
70     ids[2] = 2;
71     ids[3] = 3;
72     YAZ_CHECK(tl_sort(zh, "@or @attr 1=4 computer @attr 7=1 @attr 1=1021 0", 4, ids));
73     YAZ_CHECK(tl_sort(zh, "@or @attr 1=4 computer @attr 7=1 @attr 1=Bib-Level 0", 4, ids));
74
75     ids[0] = 2;
76     ids[1] = 5;
77     ids[2] = 4;
78     ids[3] = 3;
79     YAZ_CHECK(tl_sort(zh, "@or @attr 1=4 computer @attr 7=1 @attr 1=1021 @attr 4=109 0", 4, ids));
80     YAZ_CHECK(tl_sort(zh, "@or @attr 1=4 computer @attr 7=1 @attr 1=Bib-Level @attr 4=109 0", 4, ids));
81
82     YAZ_CHECK(tl_close_down(zh, zs));
83 }
84
85
86 TL_MAIN
87 /*
88  * Local variables:
89  * c-basic-offset: 4
90  * c-file-style: "Stroustrup"
91  * indent-tabs-mode: nil
92  * End:
93  * vim: shiftwidth=4 tabstop=8 expandtab
94  */
95