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