51 #define DATA(...) { __VA_ARGS__ } 54 #define BASE16( name, DATA, ENCODED ) \ 55 static const uint8_t name ## _data[] = DATA; \ 56 static struct base16_test name = { \ 57 .data = name ## _data, \ 58 .len = sizeof ( name ## _data ), \ 67 DATA (
'H',
'e',
'l',
'l',
'o',
' ',
'w',
'o',
'r',
'l',
'd' ),
68 "48656c6c6f20776f726c64" );
72 DATA ( 0x8b, 0x1a, 0xa2, 0x6c, 0xa9, 0x38, 0x43, 0xb8, 0x81, 0xf8,
73 0x30, 0x44, 0xb2, 0x32, 0x6e, 0x82, 0xfe, 0x0f, 0x84, 0x91 ),
74 "8b1aa26ca93843b881f83044b2326e82fe0f8491" );
90 check_len = base16_encode (
test->data,
test->len, buf, sizeof ( buf ));
91 okx ( check_len ==
len, file, line );
94 #define base16_encode_ok( test ) base16_encode_okx ( test, __FILE__, __LINE__ ) 104 unsigned int line ) {
109 len = base16_decode (
test->encoded, buf, sizeof ( buf ) );
110 okx (
len >= 0, file, line );
111 okx ( (
size_t )
len <= max_len, file, line );
112 okx ( (
size_t )
len ==
test->len, file, line );
115 #define base16_decode_ok( test ) base16_decode_okx ( test, __FILE__, __LINE__ ) #define DATA(...)
Define inline data.
#define BASE16(name, DATA, ENCODED)
Define a base16 test.
const char * encoded
Base16-encoded data.
Self-test infrastructure.
const char * name
Test set name.
static void base16_decode_okx(struct base16_test *test, const char *file, unsigned int line)
Report a base16 decoding test result.
static size_t base16_decoded_max_len(const char *encoded)
Calculate maximum length of base16-decoded string.
static size_t base16_encoded_len(size_t raw_len)
Calculate length of base16-encoded data.
#define base16_encode_ok(test)
#define base16_decode_ok(test)
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define okx(success, file, line)
Report test result.
static void base16_test_exec(void)
Perform Base16 self-tests.
size_t strlen(const char *src)
Get length of string.
struct self_test base16_test __self_test
Base16 self-test.
size_t len
Length of raw data.
static void base16_encode_okx(struct base16_test *test, const char *file, unsigned int line)
Report a base16 encoding test result.
int strcmp(const char *first, const char *second)
Compare strings.
const void * data
Raw data.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.