691d70006b39c58048494285855889424d25f184
[idzebra-moved-to-github.git] / test / api / t13.c
1 /* $Id: t13.c,v 1.11 2006-11-22 14:06:53 adam Exp $
2    Copyright (C) 1995-2006
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 this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21 */
22
23 /** test resources */
24 #include <stdlib.h>
25 #include <string.h>
26 #include "testlib.h"
27 #include <idzebra/api.h>
28
29 static void tst_res(void)
30 {
31     Res default_res;  /* default resources */
32     Res temp_res;     /* temporary resources */
33     ZebraService zs;
34     ZebraHandle zh;
35     const char *val;
36     int i;
37
38     default_res = res_open(0, 0); /* completely empty */
39     YAZ_CHECK(default_res);
40
41     res_set(default_res, "name1", "value1");
42
43     temp_res = res_open(0, 0); /* completely empty */
44     YAZ_CHECK(temp_res);
45     
46     zs = zebra_start_res(0, default_res, temp_res);
47     YAZ_CHECK(zs);
48     
49     zh = zebra_open(zs, 0);
50     YAZ_CHECK(zh);
51
52     YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
53
54     /* run this a few times so we can see leaks easier */
55     for (i = 0; i<10; i++)
56     {
57         /* we should find the name1 from default_res */
58         val = zebra_get_resource(zh, "name1", 0);
59         YAZ_CHECK(val && !strcmp(val, "value1"));
60
61         /* make local override */
62         res_set(temp_res, "name1", "value2");
63         res_set(temp_res, "name4", "value4");
64
65         /* we should find the name1 from temp_res */
66         val = zebra_get_resource(zh, "name1", 0);
67         YAZ_CHECK(val && !strcmp(val, "value2"));
68         
69         val = zebra_get_resource(zh, "name4", 0);
70         YAZ_CHECK(val && !strcmp(val, "value4"));
71         
72         res_clear(temp_res);
73     }
74     zebra_close(zh);
75     zebra_stop(zs);
76
77     res_close(temp_res);
78     res_close(default_res);
79 }
80
81 static void tst_no_config(void)
82 {
83     static char *xml_buf = "<gils><title>myx</title></gils>";
84     ZebraService zs;
85     ZebraHandle zh;
86     zint sysno = 0;
87
88     zs = zebra_start_res(0, 0, 0);
89     YAZ_CHECK(zs);
90
91     zh = zebra_open(zs, 0);
92     YAZ_CHECK(zh);
93
94     YAZ_CHECK_EQ(zebra_select_database(zh, "Default"), ZEBRA_OK);
95
96     YAZ_CHECK_EQ(zebra_init(zh), ZEBRA_OK);
97     
98     zebra_set_resource(zh, "profilePath", "${srcdir:-.}/../../tab");
99     
100     YAZ_CHECK_EQ(zebra_insert_record(zh /* handle */,
101                                      "grs.sgml" /* record type */,
102                                      &sysno, 0 /* match */,
103                                      0 /* fname */,
104                                      xml_buf, strlen(xml_buf),
105                                      0 /* force_update */),
106               ZEBRA_OK);
107
108     zebra_close(zh);
109     zebra_stop(zs);
110 }
111
112 static void tst(int argc, char **argv)
113 {
114     tst_res();
115     tst_no_config();
116 }
117
118 TL_MAIN
119 /*
120  * Local variables:
121  * c-basic-offset: 4
122  * indent-tabs-mode: nil
123  * End:
124  * vim: shiftwidth=4 tabstop=8 expandtab
125  */
126