Fix documentation of of chr's equivalent directive ZEB-672
[idzebra-moved-to-github.git] / util / tstres.c
1 /* This file is part of the Zebra server.
2    Copyright (C) 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 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <string.h>
24 #include <stdlib.h>
25 #include <idzebra/res.h>
26 #include <yaz/test.h>
27 #include <yaz/snprintf.h>
28
29 /* use env srcdir as base directory - or current directory if unset */
30 const char *get_srcdir(void)
31 {
32     const char *srcdir = getenv("srcdir");
33     if (!srcdir || ! *srcdir)
34         srcdir=".";
35     return srcdir;
36
37 }
38
39
40 static void tst_res_open(void)
41 {
42     Res res = 0;
43
44     res_close(res);
45
46     res = res_open(0, 0);
47     YAZ_CHECK(res);
48     res_close(res);
49 }
50
51
52 static void tst_res_read_file(void)
53 {
54     Res res = res_open(0, 0);
55
56     YAZ_CHECK(res);
57     if (res)
58     {
59         int r = res_read_file(res, "notfound");
60         YAZ_CHECK_EQ(r, ZEBRA_FAIL);
61     }
62     if (res)
63     {
64         const char *v;
65         char path[1024];
66         int r;
67
68         yaz_snprintf(path, sizeof(path), "%s/tstres.cfg", get_srcdir());
69         r = res_read_file(res, path);
70         YAZ_CHECK_EQ(r, ZEBRA_OK);
71
72         v = res_get_def(res, "register", "none");
73         YAZ_CHECK(!strcmp(v, "a:b"));
74
75         v = res_get_def(res, "name", "none");
76         YAZ_CHECK(!strcmp(v, "c d"));
77
78         v = res_get_def(res, "here", "none");
79         YAZ_CHECK(!strcmp(v, "_"));
80
81         v = res_get_def(res, "namex", "none");
82         YAZ_CHECK(!strcmp(v, "none"));
83     }
84     res_close(res);
85 }
86
87 int main (int argc, char **argv)
88 {
89     YAZ_CHECK_INIT(argc, argv);
90     YAZ_CHECK_LOG();
91     tst_res_open();
92     tst_res_read_file();
93     YAZ_CHECK_TERM;
94 }
95 /*
96  * Local variables:
97  * c-basic-offset: 4
98  * c-file-style: "Stroustrup"
99  * indent-tabs-mode: nil
100  * End:
101  * vim: shiftwidth=4 tabstop=8 expandtab
102  */
103