43653cc4cd7f9a733d4b2abb5d551834cd2d9130
[idzebra-moved-to-github.git] / test / api / test_sort_set.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 2004-2013 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 #include <yaz/sortspec.h>
25
26 const char *recs[] = {
27         "<gils>\n"
28         "  <title>My title</title>\n"
29         "</gils>\n",
30         0};
31
32 static void tst(int argc, char **argv)
33 {
34     const char *setname1 = "set1";
35     const char *setname2 = "set2";
36     const char *setname3 = "set3";
37     int status;
38     ZebraService zs = tl_start_up(0, argc, argv);
39     ZebraHandle  zh = zebra_open (zs, 0);
40     ODR odr_input = odr_createmem (ODR_DECODE);
41     ODR odr_output = odr_createmem (ODR_ENCODE);
42     YAZ_PQF_Parser parser = yaz_pqf_create();
43     Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, "@attr 1=4 my");
44     Z_SortKeySpecList *spec = yaz_sort_spec (odr_output, "1=4 <!");
45     zint hits;
46
47     YAZ_CHECK(tl_init_data(zh, recs));
48
49     YAZ_CHECK(zebra_begin_trans(zh, 0) == ZEBRA_OK);
50
51     YAZ_CHECK(zebra_search_RPN(zh, odr_input, query, setname1, &hits) ==
52               ZEBRA_OK);
53
54     YAZ_CHECK(zebra_sort(zh, odr_output, 1, &setname1, setname2, spec,
55                          &status)
56               == ZEBRA_OK);
57     YAZ_CHECK(zebra_sort(zh, odr_output, 1, &setname2, setname3, spec,
58                          &status) == ZEBRA_OK);
59
60     spec = yaz_sort_spec(odr_output, "1=5 <!"); /* invalid sort spec */
61
62     YAZ_CHECK(zebra_sort(zh, odr_output, 1, &setname1, setname2, spec,
63                          &status) == ZEBRA_FAIL);
64
65     YAZ_CHECK(zebra_end_trans(zh) == ZEBRA_OK);
66
67     yaz_pqf_destroy(parser);
68
69     /*
70      zebra_deleteResultSet(zh, Z_DeleteRequest_list,
71                           1, &setnamep, &status);
72     */
73     odr_destroy(odr_input);
74     odr_destroy(odr_output);
75
76     zebra_commit(zh);
77
78     YAZ_CHECK(tl_close_down(zh, zs));
79 }
80
81 TL_MAIN
82 /*
83  * Local variables:
84  * c-basic-offset: 4
85  * c-file-style: "Stroustrup"
86  * indent-tabs-mode: nil
87  * End:
88  * vim: shiftwidth=4 tabstop=8 expandtab
89  */
90