c1badecbb266860383686b33e3d260ce6ad6bf27
[idzebra-moved-to-github.git] / test / api / test_result_sets.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 1994-2009 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 /* Creates a few result sets */
21
22 #include "testlib.h"
23
24 const char *myrec[] ={
25         "<gils>\n"
26         "  <title>My title</title>\n"
27         "</gils>\n",
28         0};
29
30 static void tst(int argc, char **argv)
31 {
32     int i;
33     ZebraService zs = tl_start_up(0, argc, argv);
34     ZebraHandle zh = zebra_open(zs, 0);
35
36     YAZ_CHECK(tl_init_data(zh, myrec));
37
38     for (i = 0; i<4; i++)
39     {
40         char setname[20];
41         char *setnamep = setname;
42         int status;
43         ODR odr_input = odr_createmem (ODR_DECODE);    
44         ODR odr_output = odr_createmem (ODR_ENCODE);    
45         YAZ_PQF_Parser parser = yaz_pqf_create();
46         Z_RPNQuery *query = yaz_pqf_parse(parser, odr_input, 
47                                           "@attr 1=4 my");
48         zint hits;
49         if (zebra_begin_trans (zh, 1) != ZEBRA_OK)
50         {
51             fprintf(stderr, "zebra_begin_trans failed\n");
52             exit(1);
53         }
54         if (zebra_begin_trans (zh, 0) != ZEBRA_OK)
55         {
56             fprintf(stderr, "zebra_begin_trans failed\n");
57             exit(1);
58         }
59         
60         sprintf(setname, "s%d", i+1);
61         zebra_search_RPN (zh, odr_input, query, setname, &hits);
62
63         if (zebra_end_trans (zh) != ZEBRA_OK)
64         {
65             fprintf(stderr, "zebra_end_trans failed\n");
66             exit(1);
67         }
68         if (zebra_end_trans (zh) != ZEBRA_OK)
69         {
70             fprintf(stderr, "zebra_end_trans failed\n");
71             exit(1);
72         }
73         yaz_pqf_destroy(parser);
74         zebra_deleteResultSet(zh, Z_DeleteRequest_list,
75                               1, &setnamep, &status);
76         odr_destroy(odr_input);
77         odr_destroy(odr_output);
78     }
79     zebra_commit(zh);
80
81     YAZ_CHECK(tl_close_down(zh, zs));
82 }
83
84 TL_MAIN
85
86 /*
87  * Local variables:
88  * c-basic-offset: 4
89  * indent-tabs-mode: nil
90  * End:
91  * vim: shiftwidth=4 tabstop=8 expandtab
92  */
93