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