rpn2solr: support truncation left(2), left&right(3) YAZ-718
[yaz-moved-to-github.git] / test / test_xmalloc.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5
6 #if HAVE_CONFIG_H
7 #include <config.h>
8 #endif
9
10 #include <errno.h>
11 #include <string.h>
12 #include <yaz/xmalloc.h>
13 #include <yaz/test.h>
14
15 void tst(void)
16 {
17     char *p = 0;
18
19     p = (char *) xmalloc(10);
20     YAZ_CHECK(p);
21     p = (char *) xrealloc(p, 20);
22     YAZ_CHECK(p);
23     xfree(p);
24
25     p = xstrdup("hello");
26     YAZ_CHECK(p);
27     if (!p)
28         return;
29     YAZ_CHECK(!strcmp(p, "hello"));
30     xfree(p);
31
32     p = xstrndup("hello", 2);
33     YAZ_CHECK(p);
34     if (!p)
35         return;
36     YAZ_CHECK(!strcmp(p, "he"));
37     xfree(p);
38
39     p = xstrndup("hello", 6);
40     YAZ_CHECK(p);
41     if (!p)
42         return;
43     YAZ_CHECK(!strcmp(p, "hello"));
44     xfree(p);
45 }
46
47 int main (int argc, char **argv)
48 {
49     YAZ_CHECK_INIT(argc, argv);
50     tst();
51     YAZ_CHECK_TERM;
52 }
53 /*
54  * Local variables:
55  * c-basic-offset: 4
56  * c-file-style: "Stroustrup"
57  * indent-tabs-mode: nil
58  * End:
59  * vim: shiftwidth=4 tabstop=8 expandtab
60  */
61