1 /* $Id: buffer-t.c 5469 2002-05-20 12:50:57Z alexk $ */
2 /* buffer test suite. */
7 #include "inn/buffer.h"
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";
17 struct buffer one = { 0, 0, 0, NULL };
18 struct buffer two = { 0, 0, 0, NULL };
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);
40 memcmp(one.data + one.used, test_string2, sizeof(test_string2)) == 0);
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);
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);