separate declarations in libasm.h file and add list_push_front and list_size

This commit is contained in:
2025-04-03 04:55:28 +02:00
parent 394b016f2f
commit 34b139c60b
5 changed files with 126 additions and 10 deletions

61
test.c
View File

@ -6,16 +6,16 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/29 19:53:58 by tomoron #+# #+# */
/* Updated: 2025/04/02 02:35:57 by tomoron ### ########.fr */
/* Updated: 2025/04/03 04:52:46 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "libasm.h"
#define OK "\033[32mOK\n\033[0m"
#define KO "\033[31mKO\n\033[0m"
@ -38,13 +38,6 @@
else \
write(1, KO, strlen(KO));\
size_t ft_strlen(char *str);
char *ft_strcpy(char *dest, char *src);
int ft_strcmp(char *dest, char *src);
ssize_t ft_write(int fd, const void *buffer, size_t count);
ssize_t ft_read(int fd, void *buffer, size_t count);
char *ft_strdup(char *src);
int ft_atoi_base(char *nbr, char *base);
int test_strlen(void)
{
@ -212,6 +205,52 @@ int test_atoi_base(void)
return(nb_tests == passed);
}
int test_list_push_front()
{
int nb_tests;
int passed;
t_list *tmp;
nb_tests = 4;
passed = 0;
tmp = (void *)0x321;
ft_list_push_front(&tmp, (void *)0x123);
TEST("does it have a different address", tmp != (void *)0x321);
TEST("value is in the right field", tmp->data == (void *)0x123);
TEST("is the next at prev", tmp->next == (void *)0x321);
free(tmp);
ft_list_push_front(0, 0);
TEST("call with null pointer (should not segfault)", 1);
return(nb_tests == passed);
}
int test_list_size()
{
int nb_tests;
int passed;
t_list *tmp;
nb_tests = 2;
passed = 0;
tmp = 0;
ft_list_push_front(&tmp, (void *)0x123);
ft_list_push_front(&tmp, (void *)0x123);
ft_list_push_front(&tmp, (void *)0x123);
TEST("null pointer (empty list)", ft_list_size(0) == 0);
TEST("list of 3", ft_list_size(tmp) == 3);
free(tmp->next->next);
free(tmp->next);
free(tmp);
return(nb_tests == passed);
}
int main(void)
{
FNC_TEST("ft_strlen", test_strlen());
@ -227,4 +266,8 @@ int main(void)
FNC_TEST("ft_strdup", test_strdup());
printf("\n\n");
FNC_TEST("atoi_base", test_atoi_base());
printf("\n\n");
FNC_TEST("list_push_front", test_list_push_front());
printf("\n\n");
FNC_TEST("list_size", test_list_size());
}