ssl_des/t/base64_tests.c

78 lines
1.8 KiB
C
Raw Normal View History

2019-01-19 18:16:00 +02:00
#include "tests.h"
#include "tests_macros.h"
#include "ft_base64.h"
TEST_RESULT should_init_base64_ctx(TEST_PARAMS, TEST_DATA)
{
UNUSED(test_params);
UNUSED(test_data);
t_base64_ctx ctx;
2019-01-29 23:23:04 +02:00
char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2019-01-19 18:16:00 +02:00
ft_base64_init(&ctx);
for (int i = 0; i < FT_BASE64_BLOCK_SIZE; i++)
munit_assert_uchar(ctx.block[i], ==, 0);
2019-01-29 23:23:04 +02:00
for (int i = 0; i < FT_BASE64_CHARS_SIZE; i++)
munit_assert_uchar(ctx.chars[i], ==, 0);
munit_assert_string_equal(alphabet, (char *)ctx.alphabet);
return MUNIT_OK;
}
TEST_RESULT should_fill_base64_buffer(TEST_PARAMS, TEST_DATA)
{
UNUSED(test_params);
UNUSED(test_data);
t_base64_ctx ctx;
ft_base64_init(&ctx);
t_byte1 data[] = "123";
ft_base64_fill_buffer(&ctx, data, 3);
munit_assert_memory_equal(3, ctx.block, data);
return MUNIT_OK;
}
TEST_RESULT should_clean_base64_buffer(TEST_PARAMS, TEST_DATA)
{
UNUSED(test_params);
UNUSED(test_data);
t_base64_ctx ctx;
ft_base64_init(&ctx);
ft_base64_fill_buffer(&ctx, (t_byte1 *)"Man", 3);
ft_base64_encode_buffer(&ctx, 3);
for (int i = 0; i < FT_BASE64_BLOCK_SIZE; i++)
munit_assert_uchar(ctx.block[i], ==, 0);
return MUNIT_OK;
}
TEST_RESULT should_encode_base64_buffer(TEST_PARAMS, TEST_DATA)
{
UNUSED(test_params);
UNUSED(test_data);
t_base64_ctx ctx;
ft_base64_init(&ctx);
ft_base64_fill_buffer(&ctx, (t_byte1 *)"Man", 3);
ft_base64_encode_buffer(&ctx, 3);
munit_assert_string_equal((char *)ctx.chars, "TWFu");
ft_base64_fill_buffer(&ctx, (t_byte1 *)"Ma", 2);
ft_base64_encode_buffer(&ctx, 2);
munit_assert_string_equal((char *)ctx.chars, "TWE=");
ft_base64_fill_buffer(&ctx, (t_byte1 *)"M", 1);
ft_base64_encode_buffer(&ctx, 1);
munit_assert_string_equal((char *)ctx.chars, "TQ==");
2019-01-19 18:16:00 +02:00
return MUNIT_OK;
}