chiark / gitweb /
Commit 2.4.5-5 as unpacked
[inn-innduct.git] / tests / lib / buffer-t.c
1 /* $Id: buffer-t.c 5469 2002-05-20 12:50:57Z alexk $ */
2 /* buffer test suite. */
3
4 #include "config.h"
5 #include "clibrary.h"
6
7 #include "inn/buffer.h"
8 #include "libtest.h"
9
10 static const char test_string1[] = "This is a test";
11 static const char test_string2[] = " of the buffer system";
12 static const char test_string3[] = "This is a test\0 of the buffer system";
13
14 int
15 main(void)
16 {
17     struct buffer one = { 0, 0, 0, NULL };
18     struct buffer two = { 0, 0, 0, NULL };
19     struct buffer *three;
20
21     puts("26");
22
23     buffer_set(&one, test_string1, sizeof(test_string1));
24     ok_int(1, 1024, one.size);
25     ok_int(2, 0, one.used);
26     ok_int(3, sizeof(test_string1), one.left);
27     ok_string(4, test_string1, one.data);
28     buffer_append(&one, test_string2, sizeof(test_string2));
29     ok_int(5, 1024, one.size);
30     ok_int(6, 0, one.used);
31     ok_int(7, sizeof(test_string3), one.left);
32     ok(8, memcmp(one.data, test_string3, sizeof(test_string3)) == 0);
33     one.left -= sizeof(test_string1);
34     one.used += sizeof(test_string1);
35     buffer_append(&one, test_string1, sizeof(test_string1));
36     ok_int(9, 1024, one.size);
37     ok_int(10, sizeof(test_string1), one.used);
38     ok_int(11, sizeof(test_string3), one.left);
39     ok(12,
40        memcmp(one.data + one.used, test_string2, sizeof(test_string2)) == 0);
41     ok(13,
42        memcmp(one.data + one.used + sizeof(test_string2), test_string1,
43               sizeof(test_string1)) == 0);
44     buffer_set(&one, test_string1, sizeof(test_string1));
45     buffer_set(&two, test_string2, sizeof(test_string2));
46     buffer_swap(&one, &two);
47     ok_int(14, 1024, one.size);
48     ok_int(15, 0, one.used);
49     ok_int(16, sizeof(test_string2), one.left);
50     ok_string(17, test_string2, one.data);
51     ok_int(18, 1024, two.size);
52     ok_int(19, 0, two.used);
53     ok_int(20, sizeof(test_string1), two.left);
54     ok_string(21, test_string1, two.data);
55
56     three = buffer_new();
57     ok(22, three != NULL);
58     ok_int(23, 0, three->size);
59     buffer_set(three, test_string1, sizeof(test_string1));
60     ok_int(24, 1024, three->size);
61     buffer_resize(three, 512);
62     ok_int(25, 1024, three->size);
63     buffer_resize(three, 1025);
64     ok_int(26, 2048, three->size);
65     free(three->data);
66     free(three);
67
68     return 0;
69 }