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