74 lines
2.1 KiB
C
74 lines
2.1 KiB
C
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* 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());
|
||
|
}
|