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