add c03/ex05

This commit is contained in:
Aleksei Chubukov 2023-12-01 00:01:29 +04:00
parent 18b889e75a
commit e7b3c1bb7d
2 changed files with 76 additions and 0 deletions

3
.vimrc Normal file
View File

@ -0,0 +1,3 @@
let g:ale_c_clang_options="-Icommon -Icontrib/Unity/src/ -Wall -Wextra -Werror"
let g:ale_c_cc_options="-Icommon -Icontrib/Unity/src/ -Wall -Wextra -Werror"

73
c03/ex05.c Normal file
View File

@ -0,0 +1,73 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ex05.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: achubuko <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/30 23:28:26 by achubuko #+# #+# */
/* Updated: 2023/11/30 23:58:06 by achubuko ### ########.fr */
/* */
/* ************************************************************************** */
#include <unity.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
unsigned int ft_strlcat(char *dest, char *src, unsigned int size);
char g_dest[100] = "Hello ";
char g_dest_1[100];
char g_dest_2[100];
char *g_src = "world\0\0\0\0\0\0\0\0";
size_t g_r1;
size_t g_r2;
void setUp(void)
{
memcpy(g_dest_1, g_dest, 100);
memcpy(g_dest_2, g_dest, 100);
}
void tearDown(void)
{
}
void test_strlcat_short_retval(void)
{
g_r1 = strlcat(g_dest_1, g_src, 3);
g_r2 = ft_strlcat(g_dest_2, g_src, 3);
TEST_ASSERT_EQUAL_INT(g_r1, g_r1);
}
void test_strlcat_short(void)
{
g_r1 = strlcat(g_dest_1, g_src, 3);
g_r2 = ft_strlcat(g_dest_2, g_src, 3);
TEST_ASSERT_EQUAL_STRING(g_dest_1, g_dest_2);
TEST_ASSERT_EQUAL_INT(g_r1, g_r1);
}
void test_strlcat_normal_retval(void)
{
g_r1 = strlcat(g_dest_1, g_src, 20);
g_r2 = ft_strlcat(g_dest_2, g_src, 20);
TEST_ASSERT_EQUAL_INT(g_r1, g_r1);
}
void test_strlcat_normal(void)
{
g_r1 = strlcat(g_dest_1, g_src, 20);
g_r2 = ft_strlcat(g_dest_2, g_src, 20);
TEST_ASSERT_EQUAL_STRING(g_dest_1, g_dest_2);
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_strlcat_normal);
RUN_TEST(test_strlcat_normal_retval);
RUN_TEST(test_strlcat_short);
RUN_TEST(test_strlcat_short_retval);
return (UNITY_END());
}