Testing ft_lstclear(), ft_lstnew(), ft_lstadd_front(), ft_lstsize()
This commit is contained in:
parent
07877a8909
commit
5a5ab6c1a1
2 changed files with 83 additions and 5 deletions
14
Makefile
14
Makefile
|
|
@ -6,16 +6,17 @@
|
|||
# By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2025/10/03 18:03:12 by lalgarra #+# #+# #
|
||||
# Updated: 2025/10/09 17:21:34 by lalgarra ### ########.fr #
|
||||
# Updated: 2025/10/10 20:04:50 by lalgarra ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
# Location of your libft.a; it must already exist
|
||||
LIBDIR = ../repo_libft_algarra
|
||||
#LIBDIR = ../vogsphere_repo
|
||||
#LIBDIR = ../repo_libft_algarra
|
||||
LIBDIR = ../vogsphere_repo
|
||||
|
||||
CFLAGS += -Wall -Wextra -Werror -g3 -iquote $(LIBDIR) \
|
||||
# -fsanitize=address -Wanalyzer-malloc-leak
|
||||
-O0
|
||||
# -fsanitize=address
|
||||
|
||||
TESTS := ft_isalpha_test ft_isdigit_test ft_isalnum_test ft_isascii_test \
|
||||
ft_isprint_test ft_toupper_test ft_tolower_test ft_strlen_test \
|
||||
|
|
@ -23,7 +24,10 @@ TESTS := ft_isalpha_test ft_isdigit_test ft_isalnum_test ft_isascii_test \
|
|||
ft_memmove_test ft_strlcpy_test ft_strlcat_test ft_strchr_test \
|
||||
ft_strrchr_test ft_strncmp_test ft_memcmp_test ft_strnstr_test \
|
||||
ft_atoi_test ft_substr_test ft_strjoin_test ft_strtrim_test \
|
||||
ft_split_test
|
||||
ft_split_test \
|
||||
\
|
||||
ft_lstclear_test
|
||||
|
||||
|
||||
%_test : %_test.c
|
||||
$(CC) $(CFLAGS) $*_test.c -L$(LIBDIR) -lft -o $*_test
|
||||
|
|
|
|||
74
ft_lstclear_test.c
Normal file
74
ft_lstclear_test.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstclear_test.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lalgarra <lalgarra@student.42madrid.c +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/10/10 18:39:09 by lalgarra #+# #+# */
|
||||
/* Updated: 2025/10/10 20:11:21 by lalgarra ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static void displaycontent(void *content)
|
||||
{
|
||||
printf("content points to %p and is ", content);
|
||||
if (content != NULL)
|
||||
printf("not NULL");
|
||||
//printf("not NULL (%i)", *(int*)content);
|
||||
else
|
||||
printf("NULL");
|
||||
}
|
||||
|
||||
static void del_content(void *content)
|
||||
{
|
||||
printf("del_content(): ");
|
||||
displaycontent(content);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void display(t_list *node, int idx)
|
||||
{
|
||||
printf("node [%i] is ", idx);
|
||||
if (node == NULL)
|
||||
printf("NULL");
|
||||
else
|
||||
{
|
||||
printf("not NULL (%p)", (void *)node);
|
||||
printf(", ");
|
||||
displaycontent(node->content);
|
||||
printf(", next is ");
|
||||
if (node->next == NULL)
|
||||
printf("NULL");
|
||||
else
|
||||
printf("not NULL (%p)", (void *)node->next);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ar[]={1, 2, 3, 4, 5};
|
||||
t_list **list;
|
||||
t_list *node1;
|
||||
t_list *node2;
|
||||
|
||||
node1 = ft_lstnew((void *)ar);
|
||||
node2 = ft_lstnew((void *)(ar + 1));
|
||||
display(node1, -1);
|
||||
display(node2, -1);
|
||||
list = malloc(sizeof(t_list *));
|
||||
if (list != NULL)
|
||||
{
|
||||
ft_lstadd_front(list, node1);
|
||||
ft_lstadd_front(list, node2);
|
||||
printf("My list has %i elements.\n", ft_lstsize(*list));
|
||||
ft_lstclear(list, del_content);
|
||||
display(node1, -1);
|
||||
display(node2, -1);
|
||||
free(list);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue