Cub3D/libft/tests/ft_string/ft_str/test_strmapi.c
2024-11-08 19:37:30 +01:00

43 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bgoulard <bgoulard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/26 11:10:32 by bgoulard #+# #+# */
/* Updated: 2024/06/02 08:40:48 by bgoulard ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_string.h"
#include <stdlib.h>
static char local_mapi(unsigned int i, char c)
{
(void)i;
if (c >= 'a' && c <= 'z')
return (c - 32);
if (c >= 'A' && c <= 'Z')
return (c + 32);
return (c);
}
int test_strmapi(void)
{
char *str;
char *res;
str = "Hello World!";
res = ft_strmapi(str, &local_mapi);
if (ft_strcmp(res, "hELLO wORLD!") != 0)
return (1);
free(res);
res = ft_strmapi(NULL, &local_mapi);
if (res)
return (2);
res = ft_strmapi(str, NULL);
if (res)
return (3);
return (0);
}