61c0739ef4eb2d1f4eb1270564d7ac334e972adc
[yaz-moved-to-github.git] / test / test_nmem.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2011 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 <stdlib.h>
13
14 #include <yaz/nmem.h>
15 #include <yaz/test.h>
16
17 void tst(void)
18 {
19     NMEM n;
20     int j;
21     char *cp;
22
23     n = nmem_create();
24     YAZ_CHECK(n);
25
26     for (j = 1; j<500; j++)
27     {
28         cp = (char *) nmem_malloc(n, j);
29         YAZ_CHECK(cp);
30         if ((int) sizeof(long) >= j)
31             *(long*) cp = 123L;
32 #if HAVE_LONG_LONG
33         if ((int) sizeof(long long) >= j)
34             *(long long*) cp = 123L;
35 #endif
36         if ((int) sizeof(double) >= j)
37             *(double*) cp = 12.2;
38     }
39     
40     for (j = 2000; j<20000; j+= 2000)
41     {
42         cp = (char *) nmem_malloc(n, j);
43         YAZ_CHECK(cp);
44     }
45     nmem_destroy(n);
46 }
47
48 int main (int argc, char **argv)
49 {
50     YAZ_CHECK_INIT(argc, argv);
51     tst();
52     YAZ_CHECK_TERM;
53 }
54 /*
55  * Local variables:
56  * c-basic-offset: 4
57  * c-file-style: "Stroustrup"
58  * indent-tabs-mode: nil
59  * End:
60  * vim: shiftwidth=4 tabstop=8 expandtab
61  */
62