2019-02-07 23:22:40 +02:00
|
|
|
#include <unistd.h>
|
2019-03-02 20:52:33 +02:00
|
|
|
#include "t.h"
|
2019-01-19 18:16:00 +02:00
|
|
|
#include "tests.h"
|
|
|
|
#include "ft_base64.h"
|
2019-03-02 20:52:33 +02:00
|
|
|
#include "libft.h"
|
2019-01-19 18:16:00 +02:00
|
|
|
|
2019-03-02 20:52:33 +02:00
|
|
|
static int init_ctx()
|
2019-01-19 18:16:00 +02:00
|
|
|
{
|
|
|
|
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-04-10 17:20:22 +03:00
|
|
|
_IS(ctx.input_fd == STDIN_FILENO);
|
|
|
|
_IS(ctx.output_fd == STDOUT_FILENO);
|
2019-02-07 23:22:40 +02:00
|
|
|
|
2019-04-10 17:20:22 +03:00
|
|
|
_IS(ft_strcmp(alphabet, (char *)ctx.alphabet) == 0);
|
2019-01-29 23:23:04 +02:00
|
|
|
|
2019-04-10 17:20:22 +03:00
|
|
|
_END("init ctx");
|
2019-01-29 23:23:04 +02:00
|
|
|
}
|
|
|
|
|
2019-03-02 20:52:33 +02:00
|
|
|
static int transform_block()
|
2019-01-29 23:23:04 +02:00
|
|
|
{
|
|
|
|
t_base64_ctx ctx;
|
2019-02-23 23:56:27 +02:00
|
|
|
t_byte1 buff[FT_BASE64_DECODE_BLOCK_SIZE];
|
2019-01-29 23:23:04 +02:00
|
|
|
|
|
|
|
ft_base64_init(&ctx);
|
|
|
|
|
2019-02-23 23:56:27 +02:00
|
|
|
ft_base64_encode_transform(&ctx, (t_byte1 *)"Man", buff);
|
2019-04-10 17:20:22 +03:00
|
|
|
_IS(ft_strncmp((char *)buff, "TWFu", 4) == 0);
|
2019-01-29 23:23:04 +02:00
|
|
|
|
2019-02-23 23:56:27 +02:00
|
|
|
ft_base64_encode_transform(&ctx, (t_byte1 *)"LOL", buff);
|
2019-04-10 17:20:22 +03:00
|
|
|
_IS(ft_strncmp((char *)buff, "TE9M", 4) == 0);
|
2019-03-02 20:52:33 +02:00
|
|
|
|
2019-04-10 17:20:22 +03:00
|
|
|
_END("transform block");
|
2019-03-02 20:52:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int base64_tests(void)
|
|
|
|
{
|
2019-04-10 17:20:22 +03:00
|
|
|
_SHOULD(init_ctx);
|
|
|
|
_SHOULD(transform_block);
|
2019-03-02 20:52:33 +02:00
|
|
|
return 0;
|
2019-01-19 18:16:00 +02:00
|
|
|
}
|