aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_base64_len_to_raw_len_.c
blob: a540278b3371ca4b90771a9cde312493627f95e7 (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 int librecrypt_base64_len_to_raw_len_(size_t ascii_len, size_t *raw_len_out);


#else


#define CHECK_GOOD(IN, OUT)\
	do {\
		size_t out = SIZE_MAX;\
		assert(librecrypt_base64_len_to_raw_len_((IN), &out) == 1);\
		assert(out == (OUT));\
	} while (0)


#define CHECK_BAD(IN)\
	do {\
		size_t out;\
		assert(librecrypt_base64_len_to_raw_len_((IN), &out) == 0);\
	} while (0)


int
main(void)
{
	size_t i, in_off = 0u, out_off = 0u;

	SET_UP_ALARM();
	INIT_RESOURCE_TEST();

	for (i = 0u; i < 8u; i++) {
		CHECK_GOOD(in_off + 0u, out_off + 0u);
		CHECK_BAD(in_off + 1u);
		CHECK_GOOD(in_off + 2u, out_off + 1u);
		CHECK_GOOD(in_off + 3u, out_off + 2u);
		in_off += 4u;
		out_off += 3u;
	}

	STOP_RESOURCE_TEST();
	return 0;
}


#endif