aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_concat_void_.c
blob: 82bbef6dfa297433a1c1cc69ff6a7862b031f080 (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
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST


extern inline size_t librecrypt_concat_void_(struct concat_state *state, size_t len);


#else


int
main(void)
{
	char buf[4];
	struct concat_state state = {buf, sizeof(buf), 0u};

	SET_UP_ALARM();
	INIT_TEST_ABORT();
	INIT_RESOURCE_TEST();

	memset(buf, 'x', sizeof(buf));

	assert(librecrypt_concat_void_(&state, 2u) == 2u);
	assert(state.buf == &buf[2u]);
	assert(state.size == 2u);
	assert(state.len == 2u);
	assert(!memcmp(buf, "xx\0x", sizeof(buf)));
	assert(librecrypt_concat_void_(&state, 5u) == 1u);
	assert(state.buf == &buf[3u]);
	assert(state.size == 1u);
	assert(state.len == 7u);
	assert(!memcmp(buf, "xx\0\0", sizeof(buf)));

	state = (struct concat_state){NULL, 0u, 0u};
	assert(librecrypt_concat_void_(&state, 5u) == 0u);
	assert(state.buf == NULL);
	assert(state.size == 0u);
	assert(state.len == 5u);

	state = (struct concat_state){NULL, 0u, SIZE_MAX};
	EXPECT_ABORT(state.size = librecrypt_concat_void_(&state, 1u));

	STOP_RESOURCE_TEST();
	return 0;
}


#endif