github.com/study-group-99/pilates@v0.2.2/libft/test_ft_lstclear.cpp (about)

     1  #include <gtest/gtest.h>
     2  #include <stdlib.h>
     3  #include <strings.h>
     4  
     5  extern "C" {
     6  #include "../libft.h"
     7  }
     8  
     9  void lstclear_f(void *elem) {
    10  	*(int *)elem *= 10;
    11  }
    12  
    13  TEST(TestFtLstclear, Basic) {
    14  	t_list *s1 = (t_list *)malloc(sizeof(t_list));
    15  	t_list *s2 = (t_list *)malloc(sizeof(t_list));
    16  	t_list *s3 = (t_list *)malloc(sizeof(t_list));
    17  	int got1 = 1;
    18  	int got2 = 2;
    19  	int got3 = 3;
    20  	s1->next = s2;
    21  	s1->content = &got1;
    22  	s2->next = s3;
    23  	s2->content = &got2;
    24  	s3->next = NULL;
    25  	s3->content = &got3;
    26  	t_list	*got = s1;
    27  
    28  	ft_lstclear(&got, lstclear_f);
    29  
    30  	EXPECT_TRUE(got1 == 10);
    31  	EXPECT_TRUE(got2 == 20);
    32  	EXPECT_TRUE(got3 == 30);
    33  	EXPECT_TRUE(got == NULL);
    34  }
    35  
    36  TEST(TestFtLstclear, Null) {
    37  	t_list	*got = NULL;
    38  	ft_lstclear(&got, lstclear_f);
    39  	EXPECT_TRUE(got == NULL);
    40  }