Deb: idzebra-2.0-utils includes init.d script
[idzebra-moved-to-github.git] / bfile / tstmfile1.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 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <sys/stat.h>
24 #include <sys/types.h>
25 #include <errno.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <yaz/test.h>
29 #include "mfile.h"
30
31 #define BLOCK_SIZE 16
32
33 void tst1(void)
34 {
35     MFile_area a = mf_init("main", 0 /* spec */, 0 /* base */, 0 /* only sh */);
36     YAZ_CHECK(a);
37     mf_destroy(a);
38 }
39
40 void tst2(void)
41 {
42     char buf[BLOCK_SIZE];
43     MFile_area a = mf_init("main", 0 /* spec */, 0 /* base */, 0 /* only sh */);
44     MFile f;
45
46     YAZ_CHECK(a);
47
48     mf_reset(a, 1);
49
50     f = mf_open(a, "mymfile", BLOCK_SIZE, 1);
51     YAZ_CHECK(f);
52
53     YAZ_CHECK_EQ(mf_read(f, 0, 0, 0, buf), 0);
54
55     memset(buf, 'a', BLOCK_SIZE);
56     YAZ_CHECK_EQ(mf_write(f, 0, 0, 0, buf), 0);
57
58     YAZ_CHECK_EQ(mf_read(f, 0, 0, 0, buf), 1);
59
60     mf_close(f);
61
62     mf_destroy(a);
63 }
64
65 int main(int argc, char **argv)
66 {
67     YAZ_CHECK_INIT(argc, argv);
68     tst1();
69     tst2();
70     YAZ_CHECK_TERM;
71 }
72