aboutsummaryrefslogtreecommitdiffstats
path: root/tests/libntp/recvbuff.c
blob: 90986e0aba957b40770f6d3c13b38866ceed40e9 (plain) (blame)
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
#include "config.h"

#include "recvbuff.h"

#include "unity.h"

void setUp(void);
void test_Initialization(void);
void test_GetAndFree(void);
void test_GetAndFill(void);

void
setUp(void)
{
	init_recvbuff(RECV_INIT);
	init_lib();

	return;
}

void
test_Initialization(void) {
	TEST_ASSERT_EQUAL_UINT(RECV_INIT, free_recvbuffs());
	TEST_ASSERT_EQUAL_UINT(0, full_recvbuffs());
	TEST_ASSERT_FALSE(has_full_recv_buffer());
	TEST_ASSERT_NULL(get_full_recv_buffer());
}

void
test_GetAndFree(void) {
	u_long initial = free_recvbuffs();
	recvbuf_t* buf = get_free_recv_buffer(TRUE);

	TEST_ASSERT_EQUAL_UINT(initial-1, free_recvbuffs());
	freerecvbuf(buf);
	TEST_ASSERT_EQUAL_UINT(initial, free_recvbuffs());
}


void
test_GetAndFill(void) {
	// int initial = free_recvbuffs();
	recvbuf_t* buf = get_free_recv_buffer(TRUE);

	add_full_recv_buffer(buf);
	TEST_ASSERT_EQUAL_UINT(1, full_recvbuffs());
	TEST_ASSERT_TRUE(has_full_recv_buffer());
	TEST_ASSERT_EQUAL_PTR(buf, get_full_recv_buffer());
}