blob: d2db8b9ce480208683dae5e4381e21ab16ddcf7a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# Checking the btparser. -*- Autotest -*-
AT_BANNER([strbuf])
## ---------------------- ##
## strbuf_append_char ##
## ---------------------- ##
AT_TESTFUN([strbuf_append_char],
[[
#include "strbuf.h"
#include <assert.h>
int main(void)
{
int i;
struct strbuf *strbuf = strbuf_new();
for (i = 0; i < 100; ++i)
{
assert(strbuf->len == i);
assert(strbuf->alloc > strbuf->len);
assert(strbuf->buf[i] == '\0');
strbuf_append_char(strbuf, 'a');
assert(strbuf->buf[i] == 'a');
assert(strbuf->buf[i+1] == '\0');
assert(strbuf->len == i + 1);
assert(strbuf->alloc > strbuf->len);
}
strbuf_free(strbuf);
return 0;
}
]])
## --------------------- ##
## strbuf_append_str ##
## --------------------- ##
AT_TESTFUN([strbuf_append_str],
[[
#include "strbuf.h"
#include <assert.h>
/* Test appending strings of certain length. 'len' must be < 50. */
void test(int len)
{
int i;
char str[50];
for (i = 0; i < len; ++i)
str[i] = 'a';
str[i] = '\0';
struct strbuf *strbuf = strbuf_new();
for (i = 0; i < 100; ++i)
{
assert(strbuf->len == i*len);
assert(strbuf->alloc > strbuf->len);
assert(strbuf->buf[i*len] == '\0');
strbuf_append_str(strbuf, str);
assert(strbuf->buf[i*len] == str[0]);
assert(strbuf->buf[i*len+len] == '\0');
assert(strbuf->len == i*len + len);
assert(strbuf->alloc > strbuf->len);
}
strbuf_free(strbuf);
}
int main(void)
{
int i;
for (i = 0; i < 50; ++i)
test(i);
return 0;
}
]])
|