1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
/* This file is part of the Zebra server.
Copyright (C) Index Data
Zebra is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/** test resources */
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "testlib.h"
#include <idzebra/api.h>
static void tst_res(void)
{
Res default_res; /* default resources */
Res temp_res; /* temporary resources */
ZebraService zs;
ZebraHandle zh;
const char *val;
int i;
default_res = res_open(0, 0); /* completely empty */
YAZ_CHECK(default_res);
res_set(default_res, "name1", "value1");
temp_res = res_open(0, 0); /* completely empty */
YAZ_CHECK(temp_res);
zs = zebra_start_res(0, default_res, temp_res);
YAZ_CHECK(zs);
zh = zebra_open(zs, 0);
YAZ_CHECK(zh);
YAZ_CHECK(zebra_select_database(zh, "Default") == ZEBRA_OK);
/* run this a few times so we can see leaks easier */
for (i = 0; i<10; i++)
{
/* we should find the name1 from default_res */
val = zebra_get_resource(zh, "name1", 0);
YAZ_CHECK(val && !strcmp(val, "value1"));
/* make local override */
res_set(temp_res, "name1", "value2");
res_set(temp_res, "name4", "value4");
/* we should find the name1 from temp_res */
val = zebra_get_resource(zh, "name1", 0);
YAZ_CHECK(val && !strcmp(val, "value2"));
val = zebra_get_resource(zh, "name4", 0);
YAZ_CHECK(val && !strcmp(val, "value4"));
res_clear(temp_res);
}
zebra_close(zh);
zebra_stop(zs);
res_close(temp_res);
res_close(default_res);
}
static void tst_no_config(void)
{
static char *xml_buf = "<gils><title>myx</title></gils>";
ZebraService zs;
ZebraHandle zh;
zint sysno = 0;
zs = zebra_start_res(0, 0, 0);
YAZ_CHECK(zs);
zh = zebra_open(zs, 0);
YAZ_CHECK(zh);
YAZ_CHECK_EQ(zebra_select_database(zh, "Default"), ZEBRA_OK);
YAZ_CHECK_EQ(zebra_init(zh), ZEBRA_OK);
zebra_set_resource(zh, "profilePath", "${srcdir:-.}/../../tab");
YAZ_CHECK_EQ(zebra_update_record(zh /* handle */,
action_insert,
"grs.sgml" /* record type */,
&sysno, 0 /* match */,
0 /* fname */,
xml_buf, strlen(xml_buf)),
ZEBRA_OK);
zebra_close(zh);
zebra_stop(zs);
}
static void tst(int argc, char **argv)
{
tst_res();
tst_no_config();
}
TL_MAIN
/*
* Local variables:
* c-basic-offset: 4
* c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
*/
|