some tests format according to norm

This commit is contained in:
Gregory 2018-10-23 21:07:38 +03:00
parent efd7701b78
commit 814dd940b0
3 changed files with 84 additions and 61 deletions

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* md5_tests.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/23 21:06:22 by gtertysh #+# #+# */
/* Updated: 2018/10/23 21:06:33 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "tests.h" #include "tests.h"
#include "tests_macros.h" #include "tests_macros.h"
#include "ft_md5.h" #include "ft_md5.h"
@ -5,59 +17,59 @@
TEST_RESULT should_init_ctx(TEST_PARAMS, TEST_DATA) TEST_RESULT should_init_ctx(TEST_PARAMS, TEST_DATA)
{ {
UNUSED(test_params); UNUSED(test_params);
UNUSED(test_data); UNUSED(test_data);
t_md5_ctx ctx; t_md5_ctx ctx;
ft_md5_init(&ctx); ft_md5_init(&ctx);
munit_assert_uint(ctx.a, ==, 0x67452301); munit_assert_uint(ctx.a, ==, 0x67452301);
munit_assert_uint(ctx.b, ==, 0xefcdab89); munit_assert_uint(ctx.b, ==, 0xefcdab89);
munit_assert_uint(ctx.c, ==, 0x98badcfe); munit_assert_uint(ctx.c, ==, 0x98badcfe);
munit_assert_uint(ctx.d, ==, 0x10325476); munit_assert_uint(ctx.d, ==, 0x10325476);
munit_assert_true(ctx.bit_len == 0); munit_assert_true(ctx.bit_len == 0);
for (int i = 0; i < 64; i++) for (int i = 0; i < 64; i++)
munit_assert_uchar(ctx.block[i], ==, 0); munit_assert_uchar(ctx.block[i], ==, 0);
return MUNIT_OK; return MUNIT_OK;
} }
TEST_RESULT decode_string_to_int(TEST_PARAMS, TEST_DATA) TEST_RESULT decode_string_to_int(TEST_PARAMS, TEST_DATA)
{ {
UNUSED(test_params); UNUSED(test_params);
UNUSED(test_data); UNUSED(test_data);
t_byte1 block[FT_MD5_BLOCK_SIZE]; t_byte1 block[FT_MD5_BLOCK_SIZE];
t_byte4 words[FT_MD5_WORDS_COUNT]; t_byte4 words[FT_MD5_WORDS_COUNT];
ft_bzero(block, FT_MD5_BLOCK_SIZE); ft_bzero(block, FT_MD5_BLOCK_SIZE);
block[0] = 'a'; block[0] = 'a';
block[9] = 'b'; block[9] = 'b';
block[63] = 'c'; block[63] = 'c';
ft_md5_decode(words, block); ft_md5_decode(words, block);
munit_assert_true((words[0] & 0xff) == 97); munit_assert_true((words[0] & 0xff) == 97);
munit_assert_true(((words[2] >> 8) & 0xff) == 98); munit_assert_true(((words[2] >> 8) & 0xff) == 98);
munit_assert_true(((words[15] >> 24) & 0xff) == 99); munit_assert_true(((words[15] >> 24) & 0xff) == 99);
return MUNIT_OK; return MUNIT_OK;
} }
TEST_RESULT update_should_change_count(TEST_PARAMS, TEST_DATA) TEST_RESULT update_should_change_count(TEST_PARAMS, TEST_DATA)
{ {
UNUSED(test_params); UNUSED(test_params);
UNUSED(test_data); UNUSED(test_data);
t_md5_ctx ctx; t_md5_ctx ctx;
char message[] = "hello, World!"; char message[] = "hello, World!";
t_byte8 size = ft_strlen(message); t_byte8 size = ft_strlen(message);
ft_md5_init(&ctx); ft_md5_init(&ctx);
ft_md5_update(&ctx, (t_byte1 *)message, size); ft_md5_update(&ctx, (t_byte1 *)message, size);
munit_assert_true(size * 8 == ctx.bit_len); munit_assert_true(size * 8 == ctx.bit_len);
return MUNIT_OK; return MUNIT_OK;
} }
TEST_RESULT encode_bits_to_string(TEST_PARAMS, TEST_DATA) TEST_RESULT encode_bits_to_string(TEST_PARAMS, TEST_DATA)
@ -184,4 +196,4 @@ TEST_RESULT create_string(TEST_PARAMS, TEST_DATA)
munit_assert_string_equal((const char *)digest_string, "d41d8cd98f00b204e9800998ecf8427e"); munit_assert_string_equal((const char *)digest_string, "d41d8cd98f00b204e9800998ecf8427e");
return MUNIT_OK; return MUNIT_OK;
} }

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sha_tests.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/23 21:06:43 by gtertysh #+# #+# */
/* Updated: 2018/10/23 21:06:44 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "tests.h" #include "tests.h"
#include "tests_macros.h" #include "tests_macros.h"
#include "ft_sha.h" #include "ft_sha.h"
@ -283,4 +295,4 @@ TEST_RESULT create_digest_string_sha224(TEST_PARAMS, TEST_DATA)
(const char *)digest_string); (const char *)digest_string);
return MUNIT_OK; return MUNIT_OK;
} }

View file

@ -1,8 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/23 21:00:24 by gtertysh #+# #+# */
/* Updated: 2018/10/23 21:05:47 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "tests.h" #include "tests.h"
#include "tests_macros.h" #include "tests_macros.h"
MunitTest g_md5_tests[] = {
MunitTest md5_tests[] = {
IT("/init_ctx", should_init_ctx, NULL, NULL, 0, NULL), IT("/init_ctx", should_init_ctx, NULL, NULL, 0, NULL),
IT("/updates_ctx_count", update_should_change_count, NULL, NULL, 0, NULL), IT("/updates_ctx_count", update_should_change_count, NULL, NULL, 0, NULL),
IT("/decode_string_to_int", decode_string_to_int, NULL, NULL, 0, NULL), IT("/decode_string_to_int", decode_string_to_int, NULL, NULL, 0, NULL),
@ -13,7 +24,7 @@ MunitTest md5_tests[] = {
END_IT END_IT
}; };
MunitTest sha_tests[] = { MunitTest g_sha_tests[] = {
IT("/init_ctx_256", should_init_ctx_sha256, NULL, NULL, 0, NULL), IT("/init_ctx_256", should_init_ctx_sha256, NULL, NULL, 0, NULL),
IT("/init_ctx_224", should_init_ctx_sha224, NULL, NULL, 0, NULL), IT("/init_ctx_224", should_init_ctx_sha224, NULL, NULL, 0, NULL),
IT("/decode_string", decode_string_to_int_sha256, NULL, NULL, 0, NULL), IT("/decode_string", decode_string_to_int_sha256, NULL, NULL, 0, NULL),
@ -28,33 +39,21 @@ MunitTest sha_tests[] = {
IT("/creates_string_224", create_digest_string_sha224, NULL, NULL, 0, NULL), IT("/creates_string_224", create_digest_string_sha224, NULL, NULL, 0, NULL),
END_IT}; END_IT};
static const MunitSuite ft_ssl_suites[] = { static const MunitSuite g_ft_ssl_suites[] = {
{ {(char *)"/md5_suite", g_md5_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE},
(char *)"/md5_suite", /* name */ {(char *)"/sha_suite", g_sha_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE},
md5_tests, /* tests */
NULL, /* suites */
1, /* iterations */
MUNIT_SUITE_OPTION_NONE /* options */
},
{
(char *)"/sha_suite", /* name */
sha_tests, /* tests */
NULL, /* suites */
1, /* iterations */
MUNIT_SUITE_OPTION_NONE /* options */
},
{NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE} {NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE}
}; };
static const MunitSuite main_suite = { static const MunitSuite g_main_suite = {
(char *)"/ft_ssl", /* name */ (char *)"/ft_ssl",
NULL, /* tests */ NULL,
(MunitSuite *)ft_ssl_suites, /* suites */ (MunitSuite *)g_ft_ssl_suites,
1, /* iterations */ 1,
MUNIT_SUITE_OPTION_NONE /* options */ MUNIT_SUITE_OPTION_NONE
}; };
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
return munit_suite_main(&main_suite, NULL, argc, argv); return (munit_suite_main(&g_main_suite, NULL, argc, argv));
} }