Update configure to generate config.h
[yaz-moved-to-github.git] / test / test_wrbuf.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2010 Index Data
3  * See the file LICENSE for details.
4  */
5 #if HAVE_CONFIG_H
6 #include <config.h>
7 #endif
8
9 #include <stdlib.h>
10 #include <stdio.h>
11
12 #include <yaz/wrbuf.h>
13 #include <yaz/test.h>
14
15 static void tstwrbuf(void)
16 {
17     int step;
18     WRBUF wr;
19
20     wr = 0;
21     wrbuf_destroy(wr);
22
23     wr = wrbuf_alloc();
24     YAZ_CHECK(wr);
25     wrbuf_destroy(wr);
26
27     wr = wrbuf_alloc();
28
29     YAZ_CHECK(wr);
30
31     for (step = 1; step < 65; step++)
32     {
33         int i, j, k;
34         int len;
35         char buf[64];
36         char *cp;
37         for (j = 1; j<step; j++)
38         {
39             for (i = 0; i<j; i++)
40                 buf[i] = i+1;
41             buf[i] = '\0';
42             wrbuf_puts(wr, buf);
43         }
44         
45         cp = wrbuf_buf(wr);
46         len = wrbuf_len(wr);
47         YAZ_CHECK(len == step * (step-1) / 2);
48         k = 0;
49         for (j = 1; j<step; j++)
50             for (i = 0; i<j; i++)
51             {
52                 YAZ_CHECK(cp[k] == i+1);
53                 k++;
54             }
55         wrbuf_rewind(wr);
56     }
57     wrbuf_destroy(wr);
58 }
59
60 int main (int argc, char **argv)
61 {
62     YAZ_CHECK_INIT(argc, argv);
63     tstwrbuf();
64     YAZ_CHECK_TERM;
65 }
66
67 /*
68  * Local variables:
69  * c-basic-offset: 4
70  * c-file-style: "Stroustrup"
71  * indent-tabs-mode: nil
72  * End:
73  * vim: shiftwidth=4 tabstop=8 expandtab
74  */
75