Align Zebra API more so that ZEBRA_RES is used to signal error/OK.
[idzebra-moved-to-github.git] / test / api / t7.c
1 /* $Id: t7.c,v 1.9 2005-05-11 12:39:38 adam Exp $
2    Copyright (C) 1995-2005
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23 /** t7.c sorting  */
24
25 #include "testlib.h"
26 #include <yaz/sortspec.h>
27
28 const char *recs[] = {
29         "<gils>\n"
30         "  <title>My title</title>\n"
31         "</gils>\n",
32         0};
33
34
35 int main(int argc, char **argv)
36 {
37     const char *setname1 = "set1";
38     const char *setname2 = "set2";
39     const char *setname3 = "set3";
40     int status;
41     ZEBRA_RES ret;
42     ZebraService zs = start_up(0, argc, argv);
43     ZebraHandle  zh = zebra_open (zs);
44     ODR odr_input = odr_createmem (ODR_DECODE);    
45     ODR odr_output = odr_createmem (ODR_ENCODE);    
46     YAZ_PQF_Parser parser = yaz_pqf_create();
47     Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, "@attr 1=4 my");
48     Z_SortKeySpecList *spec = yaz_sort_spec (odr_output, "1=4 <");
49     zint hits;
50
51     init_data(zh, recs);
52
53     zebra_begin_trans(zh, 0);
54         
55     ret = zebra_search_RPN(zh, odr_input, query, setname1, &hits);
56     if (ret == ZEBRA_FAIL)
57     {
58         int code = zebra_errCode(zh);
59         printf("search returned ERROR, OK was expected ret=%d  "
60                "code=%d\n", ret, code); 
61     }
62
63     ret = zebra_sort(zh, odr_output, 1, &setname1, setname2, spec, &status);
64     if (ret == ZEBRA_FAIL) 
65     { 
66         int code = zebra_errCode(zh);
67         printf("sort A returned ERROR, OK was expected ret=%d status=%d "
68                "code=%d\n", ret, status, code); 
69         exit(1);
70     }
71     
72     ret = zebra_sort(zh, odr_output, 1, &setname2, setname3, spec, &status);
73     if (ret == ZEBRA_FAIL)
74     { 
75         int code = zebra_errCode(zh);
76         printf("sort B returned ERROR, OK was expected ret=%d status=%d "
77                "code=%d\n", ret, status, code); 
78         exit(1);
79     }
80
81     spec = yaz_sort_spec(odr_output, "1=5 <"); /* invalid sort spec */
82
83     ret = zebra_sort(zh, odr_output, 1, &setname1, setname2, spec, &status);
84     if (ret == ZEBRA_OK) 
85     { 
86         printf("sort C returned OK, ERROR was expected ret=%d status=%d\n",
87                ret, status);
88         exit(1);
89     }
90     zebra_end_trans(zh);
91     yaz_pqf_destroy(parser);
92
93     /*
94      zebra_deleteResultSet(zh, Z_DeleteRequest_list,
95                           1, &setnamep, &status);
96     */  
97     odr_destroy(odr_input);
98     odr_destroy(odr_output);
99
100     zebra_commit(zh);
101
102     return close_down(zh, zs, 0);
103 }