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