-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_common.c
84 lines (63 loc) · 1.56 KB
/
test_common.c
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
74
75
76
77
78
79
80
81
82
83
84
/*
$Id$
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "nassert.h"
#include "nmalloc.h"
#include "nbuf.h"
void assert_hook(const char *expr, const char *file, int line)
{
printf("n_assert hook: Ajajaj! %s, %s:%d -- OK\n", expr, file, line);
/*exit(1); */
}
void trurldie_hook(const char *expr, const char *file, int line)
{
printf("\nn_assert hook: Ajajaj! %s, %s:%d -- OK\n", expr, file, line);
/*exit(1); */
}
void xmallocs_handler(void)
{
printf("\nxmallocs_test: xmallocs_handler: memory full -- OK\n");
/*exit(1); */
}
void test_buf(void)
{
tn_buf *nbuf;
nbuf = n_buf_new(64);
n_buf_printf(nbuf, "dupa blada i co z tego\n");
n_buf_seek(nbuf, 2, SEEK_SET);
n_buf_printf(nbuf, "zo");
n_buf_seek(nbuf, 0, SEEK_END);
n_buf_puts_z(nbuf, "AAAA\n");
printf("%d, %d (%s)\n", n_buf_size(nbuf), strlen(n_buf_ptr(nbuf)),
n_buf_ptr(nbuf));
}
void test_buf2(void)
{
tn_buf *nbuf;
tn_buf_it it;
char *line;
int len;
nbuf = n_buf_new(4);
n_buf_printf(nbuf, "dupa");
n_buf_it_init(&it, nbuf);
line = n_buf_it_gets(&it, &len);
printf("line = (%s), len = %d\n", line, len);
printf("%d, %d (%s)\n", n_buf_size(nbuf), strlen(n_buf_ptr(nbuf)),
n_buf_ptr(nbuf));
}
int main()
{
void *p;
test_buf2();
exit(0);
printf("n_assert test:");
n_assert_sethook(assert_hook);
n_assert(0);
n_assert_sethook(NULL);
n_malloc_set_failhook(xmallocs_handler);
p = n_malloc(1024 * 1024 * 1024);
return 0;
}