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


extern inline void librecrypt_concat_char_no_nul_(struct concat_state *state, char c);


#else


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

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

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

	librecrypt_concat_char_no_nul_(&state, 'a');
	librecrypt_concat_char_no_nul_(&state, 'b');
	librecrypt_concat_char_no_nul_(&state, 'c');
	librecrypt_concat_char_no_nul_(&state, 'd');
	assert(!memcmp(buf, "abx", sizeof(buf)));
	assert(state.buf == &buf[2u]);
	assert(state.size == 1u);
	assert(state.len == 4u);

	state = (struct concat_state){NULL, 0u, 0u};
	librecrypt_concat_char_no_nul_(&state, 'a');
	assert(state.len == 1u);

	state = (struct concat_state){NULL, 0u, SIZE_MAX};
	EXPECT_ABORT(librecrypt_concat_char_no_nul_(&state, 'a'));

	STOP_RESOURCE_TEST();
	return 0;
}


#endif