ssl_des/t/base64_tests.c

61 lines
1.5 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-02-02 19:13:36 +02:00
char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz0123456789+/";
2019-01-19 18:16:00 +02:00
ft_base64_init(&ctx);
2019-02-02 19:13:36 +02:00
for (int i = 0; i < FT_BASE64_GLUE_BLOCK_SIZE; i++)
munit_assert_uchar(ctx.glue_block[i], ==, 0);
2019-01-19 18:16:00 +02:00
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);
2019-02-02 19:13:36 +02:00
munit_assert_true(ctx.glue_block_bytes_count == 0);
2019-01-29 23:23:04 +02:00
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);
2019-02-02 19:13:36 +02:00
ft_base64_fill_buffer(&ctx, (t_byte1 *)"123", 3);
munit_assert_memory_equal(3, ctx.glue_block, "123");
munit_assert_true(ctx.glue_block_bytes_count == 3);
2019-01-29 23:23:04 +02:00
2019-02-02 19:13:36 +02:00
ft_base64_fill_buffer(&ctx, (t_byte1 *)"22", 2);
munit_assert_memory_equal(2, ctx.glue_block, "22");
munit_assert_true(ctx.glue_block_bytes_count == 2);
2019-01-29 23:23:04 +02:00
return MUNIT_OK;
}
2019-02-02 19:13:36 +02:00
TEST_RESULT should_encode_base64_data(TEST_PARAMS, TEST_DATA)
2019-01-29 23:23:04 +02:00
{
UNUSED(test_params);
UNUSED(test_data);
t_base64_ctx ctx;
ft_base64_init(&ctx);
2019-02-02 19:13:36 +02:00
ft_base64_encode(&ctx, (t_byte1 *)"Man");
2019-01-29 23:23:04 +02:00
munit_assert_string_equal((char *)ctx.chars, "TWFu");
2019-02-02 19:13:36 +02:00
ft_base64_encode(&ctx, (t_byte1 *)"LOL");
munit_assert_string_equal((char *)ctx.chars, "TE9M");
2019-01-19 18:16:00 +02:00
return MUNIT_OK;
}