aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile4
-rw-r--r--README.md10
-rw-r--r--include/libft_ctype.h10
-rw-r--r--include/libft_ht.h60
-rw-r--r--include/libft_io.h17
-rw-r--r--include/libft_lst.h11
-rw-r--r--include/libft_mem.h15
-rw-r--r--include/libft_printf.h15
-rw-r--r--include/libft_str.h15
-rw-r--r--include/libft_types.h15
-rwxr-xr-xscript/find_src.sh1
-rw-r--r--src/ht/ft_htdelone.c2
-rw-r--r--src/ht/ft_htdestroy_all.c4
-rw-r--r--src/ht/ft_htdestroy_key.c2
-rw-r--r--src/ht/ft_htget.c4
-rw-r--r--src/ht/ft_htnew.c9
-rw-r--r--src/ht/ft_htset.c2
-rw-r--r--src/ht/ft_inter_htkey_equal.c5
-rw-r--r--src/io/ft_next_line.c12
-rw-r--r--src/lst/ft_lstbsearch.c8
-rw-r--r--test/Makefile27
-rw-r--r--test/include/helper/helper_segfault.h19
-rw-r--r--test/include/libft_test.h6
-rwxr-xr-xtest/libft_testbin34012 -> 45308 bytes
-rw-r--r--test/src/ht/test_ft_htcontent_new.c0
-rw-r--r--test/src/ht/test_ft_htdelone.c0
-rw-r--r--test/src/ht/test_ft_htdelone_key.c0
-rw-r--r--test/src/ht/test_ft_htdestroy.c0
-rw-r--r--test/src/ht/test_ft_htdestroy_all.c0
-rw-r--r--test/src/ht/test_ft_htdestroy_key.c0
-rw-r--r--test/src/ht/test_ft_htget.c35
-rw-r--r--test/src/ht/test_ft_hthash.c0
-rw-r--r--test/src/ht/test_ft_htnew.c38
-rw-r--r--test/src/ht/test_ft_htset.c51
-rw-r--r--test/src/main.c14
-rw-r--r--test/src/runner/test_runner_ht.c22
-rw-r--r--test/src/runner/test_runner_str.c (renamed from test/src/runner/test_ft_strlen_runner.c)0
38 files changed, 372 insertions, 63 deletions
diff --git a/.gitignore b/.gitignore
index 4a29186..35d1ada 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,8 +2,8 @@
*.so
*.a
*.ghc
+*.dSYM
a.out
test_libft
-main.c
obj/*
rendu.makefile
diff --git a/Makefile b/Makefile
index ed5ad8a..66f4038 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/10/08 15:45:53 by cacharle #+# #+# #
-# Updated: 2020/01/31 08:26:39 by cacharle ### ########.fr #
+# Updated: 2020/01/31 09:20:36 by cacharle ### ########.fr #
# #
# **************************************************************************** #
@@ -35,6 +35,8 @@ OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
INCLUDE = $(shell find $(INCLUDE_DIR) -name "*.h")
+# export LIBFT_SRC = $(SRC)
+
all: prebuild $(NAME)
.PHONY: test
diff --git a/README.md b/README.md
index 875f6e0..abbd1a9 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,16 @@ make all
This will produce a `libft.a` library which you can link to your project.
+## Unit Test
+
+```
+make test
+```
+
+## Dependencies
+
+* [Unity](https://github.com/ThrowTheSwitch/Unity) - unit testing lib
+
## .libftignore
Much like the `.gitignore` file, you can put the files/directory to ignore when compiling.
diff --git a/include/libft_ctype.h b/include/libft_ctype.h
index 44e88b8..85e0e05 100644
--- a/include/libft_ctype.h
+++ b/include/libft_ctype.h
@@ -1,17 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* ft_ctype.h :+: :+: :+: */
+/* libft_ctype.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2020/01/17 09:59:10 by cacharle #+# #+# */
-/* Updated: 2020/01/17 10:00:13 by cacharle ### ########.fr */
+/* Created: 2020/01/31 10:35:31 by cacharle #+# #+# */
+/* Updated: 2020/01/31 10:36:34 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-#ifndef FT_CTYPE_H
-# define FT_CTYPE_H
+#ifndef LIBFT_CTYPE_H
+# define LIBFT_CTYPE_H
/*
** assertion
diff --git a/include/libft_ht.h b/include/libft_ht.h
index 8dff87a..8551ddb 100644
--- a/include/libft_ht.h
+++ b/include/libft_ht.h
@@ -1,44 +1,56 @@
-
-#ifndef LIBFT_HT
-# define LIBFT_HT
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libft_ht.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/31 10:36:09 by cacharle #+# #+# */
+/* Updated: 2020/01/31 10:41:24 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef LIBFT_HT_H
+# define LIBFT_HT_H
# include "libft.h"
# include "libft_lst.h"
-typedef struct
+typedef struct s_ftht_content
{
- char *key;
- void *value;
-} t_ftht_content;
+ char *key;
+ void *value;
+} t_ftht_content;
typedef t_ftlst* t_ftht_entry;
-typedef struct
+typedef struct s_ftht
{
- t_ftsize size;
- t_ftht_entry *entries;
-} t_ftht;
+ t_ftsize size;
+ t_ftht_entry *entries;
+} t_ftht;
typedef t_ftuint t_ftht_digest;
+t_ftht_digest ft_hthash(t_ftht *ht, char *key);
-t_ftht_digest ft_hthash(t_ftht *ht, char *key);
-
-t_ftht *ft_htnew(t_ftsize size);
-void ft_htdestroy(t_ftht *ht, void (*del)(t_ftht_content*));
-void ft_htdestroy_all(t_ftht *ht);
-void ft_htdestroy_key(t_ftht *ht);
-t_ftht_content *ft_htget(t_ftht *ht, char *key);
-t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value);
-void ft_htdelone(t_ftht *ht, char *key, void (*del)(t_ftht_content*));
-void ft_htdelone_key(t_ftht *ht, char *key);
-t_ftht_content *ft_htcontent_new(char *key, void *value);
+t_ftht *ft_htnew(t_ftsize size);
+void ft_htdestroy(t_ftht *ht, void (*del)(t_ftht_content*));
+void ft_htdestroy_all(t_ftht *ht);
+void ft_htdestroy_key(t_ftht *ht);
+t_ftht_content *ft_htget(t_ftht *ht, char *key);
+t_ftht_content *ft_htset(t_ftht *ht, char *key, void *value);
+void ft_htdelone(t_ftht *ht, char *key,
+ void (*del)(t_ftht_content*));
+void ft_htdelone_key(t_ftht *ht, char *key);
+t_ftht_content *ft_htcontent_new(char *key, void *value);
/*
** internals
*/
-void ft_inter_htdelcontent_key(t_ftht_content *content);
-t_ftbool ft_inter_htkey_equal(char *ref_key, t_ftht_content *content);
+void ft_inter_htdelcontent_key(t_ftht_content *content);
+t_ftbool ft_inter_htkey_equal(char *ref_key,
+ t_ftht_content *content);
#endif
diff --git a/include/libft_io.h b/include/libft_io.h
index 75dda57..e1a2536 100644
--- a/include/libft_io.h
+++ b/include/libft_io.h
@@ -1,6 +1,17 @@
-
-#ifndef FT_IO_H
-# define FT_IO_H
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libft_io.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/31 10:35:43 by cacharle #+# #+# */
+/* Updated: 2020/01/31 10:35:48 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef LIBFT_IO_H
+# define LIBFT_IO_H
# include <unistd.h>
# include <stdlib.h>
diff --git a/include/libft_lst.h b/include/libft_lst.h
index b9475f9..2a420c4 100644
--- a/include/libft_lst.h
+++ b/include/libft_lst.h
@@ -1,3 +1,14 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libft_lst.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/31 10:36:39 by cacharle #+# #+# */
+/* Updated: 2020/01/31 10:36:41 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
#ifndef LIBFT_LST_H
# define LIBFT_LST_H
diff --git a/include/libft_mem.h b/include/libft_mem.h
index a9717b8..5465d72 100644
--- a/include/libft_mem.h
+++ b/include/libft_mem.h
@@ -1,6 +1,17 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libft_mem.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/31 10:35:57 by cacharle #+# #+# */
+/* Updated: 2020/01/31 10:35:59 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
-#ifndef FT_MEM_H
-# define FT_MEM_H
+#ifndef LIBFT_MEM_H
+# define LIBFT_MEM_H
void ft_bzero(void *s, size_t n);
void *ft_memset(void *s, int c, size_t n);
diff --git a/include/libft_printf.h b/include/libft_printf.h
index 1200478..8e64208 100644
--- a/include/libft_printf.h
+++ b/include/libft_printf.h
@@ -1,6 +1,17 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libft_printf.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/31 10:36:47 by cacharle #+# #+# */
+/* Updated: 2020/01/31 10:36:51 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
-#ifndef FT_PRINTF_H
-# define FT_PRINTF_H
+#ifndef LIBFT_PRINTF_H
+# define LIBFT_PRINTF_H
int ft_printf(const char *format, ...);
int ft_sprintf(char *str, const char *format, ...);
diff --git a/include/libft_str.h b/include/libft_str.h
index 8c4bef5..e44c995 100644
--- a/include/libft_str.h
+++ b/include/libft_str.h
@@ -1,6 +1,17 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libft_str.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/31 10:39:22 by cacharle #+# #+# */
+/* Updated: 2020/01/31 10:39:26 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
-#ifndef FT_STR_H
-# define FT_STR_H
+#ifndef LIBFT_STR_H
+# define LIBFT_STR_H
/*
** std
diff --git a/include/libft_types.h b/include/libft_types.h
index be1cc20..8df4e00 100644
--- a/include/libft_types.h
+++ b/include/libft_types.h
@@ -1,6 +1,17 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* libft_types.h :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/31 10:36:56 by cacharle #+# #+# */
+/* Updated: 2020/01/31 10:37:01 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
-#ifndef FT_TYPES_H
-# define FT_TYPES_H
+#ifndef LIBFT_TYPES_H
+# define LIBFT_TYPES_H
# define TRUE 1
# define FALSE 0
diff --git a/script/find_src.sh b/script/find_src.sh
index 3773fc9..511642b 100755
--- a/script/find_src.sh
+++ b/script/find_src.sh
@@ -15,7 +15,6 @@ fi
SRC_DIR=src
IGNORE_FIND_ARGS=`sed 's/.*/-not -path "&"/' $IGNORE_FILE | paste -sd " " -`
-IGNORE_FIND_ARGS="$IGNORE_FIND_ARGS -not -name \"*inter*\""
sh -c "find $SRC_DIR $IGNORE_FIND_ARGS -name \"*.c\""
# find $SRC_DIR $IGNORE_FIND_ARGS -name "*.c"
diff --git a/src/ht/ft_htdelone.c b/src/ht/ft_htdelone.c
index b376d8b..d502bf2 100644
--- a/src/ht/ft_htdelone.c
+++ b/src/ht/ft_htdelone.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/30 09:27:18 by cacharle #+# #+# */
-/* Updated: 2020/01/30 09:55:06 by cacharle ### ########.fr */
+/* Updated: 2020/01/31 10:40:40 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/src/ht/ft_htdestroy_all.c b/src/ht/ft_htdestroy_all.c
index ec54044..6f98a43 100644
--- a/src/ht/ft_htdestroy_all.c
+++ b/src/ht/ft_htdestroy_all.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/30 08:29:58 by cacharle #+# #+# */
-/* Updated: 2020/01/30 08:30:53 by cacharle ### ########.fr */
+/* Updated: 2020/01/31 10:43:13 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,7 +20,7 @@ static void st_htdelcontent_all(t_ftht_content *content)
free(content->value);
}
-void ft_htdestroy_all(t_ftht *ht)
+void ft_htdestroy_all(t_ftht *ht)
{
ft_htdestroy(ht, *st_htdelcontent_all);
}
diff --git a/src/ht/ft_htdestroy_key.c b/src/ht/ft_htdestroy_key.c
index 1cae2fd..a704314 100644
--- a/src/ht/ft_htdestroy_key.c
+++ b/src/ht/ft_htdestroy_key.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/30 08:31:02 by cacharle #+# #+# */
-/* Updated: 2020/01/30 09:46:14 by cacharle ### ########.fr */
+/* Updated: 2020/01/31 10:43:45 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/src/ht/ft_htget.c b/src/ht/ft_htget.c
index b4715a3..0002249 100644
--- a/src/ht/ft_htget.c
+++ b/src/ht/ft_htget.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/30 08:33:21 by cacharle #+# #+# */
-/* Updated: 2020/01/30 09:25:51 by cacharle ### ########.fr */
+/* Updated: 2020/01/31 10:40:57 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,8 +15,10 @@
t_ftht_content *ft_htget(t_ftht *ht, char *key)
{
+
t_ftht_digest digest;
+ return (NULL); // lstbsearch breaking
if (ht == NULL || key == NULL)
return (NULL);
digest = ft_hthash(ht, key);
diff --git a/src/ht/ft_htnew.c b/src/ht/ft_htnew.c
index bcf81d1..950a4fe 100644
--- a/src/ht/ft_htnew.c
+++ b/src/ht/ft_htnew.c
@@ -6,20 +6,25 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/30 08:19:16 by cacharle #+# #+# */
-/* Updated: 2020/01/30 08:19:18 by cacharle ### ########.fr */
+/* Updated: 2020/01/31 10:41:57 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "libft_ht.h"
+#define FT_HT_MAX_SIZE (1 << 14)
+
t_ftht *ft_htnew(t_ftsize size)
{
t_ftht *ht;
+ if (size == 0 || size > FT_HT_MAX_SIZE)
+ return (NULL);
if ((ht = (t_ftht*)malloc(sizeof(t_ftht))) == NULL)
return (NULL);
- if ((ht->entries = (t_ftht_entry*)ft_calloc(size, sizeof(t_ftht_entry))) == NULL)
+ ht->entries = (t_ftht_entry*)ft_calloc(size, sizeof(t_ftht_entry));
+ if (ht->entries == NULL)
{
free(ht);
return (NULL);
diff --git a/src/ht/ft_htset.c b/src/ht/ft_htset.c
index 86e9690..5ace788 100644
--- a/src/ht/ft_htset.c
+++ b/src/ht/ft_htset.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/30 08:41:52 by cacharle #+# #+# */
-/* Updated: 2020/01/30 08:50:48 by cacharle ### ########.fr */
+/* Updated: 2020/01/31 10:33:39 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/src/ht/ft_inter_htkey_equal.c b/src/ht/ft_inter_htkey_equal.c
index b652bba..7714c84 100644
--- a/src/ht/ft_inter_htkey_equal.c
+++ b/src/ht/ft_inter_htkey_equal.c
@@ -6,15 +6,16 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/30 09:24:39 by cacharle #+# #+# */
-/* Updated: 2020/01/30 09:25:36 by cacharle ### ########.fr */
+/* Updated: 2020/01/31 09:51:03 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
+#include "libft_ht.h"
t_ftbool ft_inter_htkey_equal(char *ref_key, t_ftht_content *content)
{
if (ref_key == NULL || content == NULL)
return (FALSE);
- return (ft_strcmp(ref_key, content->key) == 0)
+ return (ft_strcmp(ref_key, content->key) == 0);
}
diff --git a/src/io/ft_next_line.c b/src/io/ft_next_line.c
index 59e245b..51d21ec 100644
--- a/src/io/ft_next_line.c
+++ b/src/io/ft_next_line.c
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_next_line.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/31 10:39:38 by cacharle #+# #+# */
+/* Updated: 2020/01/31 10:39:40 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "libft.h"
static int st_find_newline(char *str)
diff --git a/src/lst/ft_lstbsearch.c b/src/lst/ft_lstbsearch.c
index 3d5dbde..25a7b4c 100644
--- a/src/lst/ft_lstbsearch.c
+++ b/src/lst/ft_lstbsearch.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/30 09:17:51 by cacharle #+# #+# */
-/* Updated: 2020/01/30 09:17:53 by cacharle ### ########.fr */
+/* Updated: 2020/01/31 10:42:22 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,7 +26,7 @@ static t_ftlst *st_lstmiddle(t_ftlst *lst, t_ftlst *last)
{
fast = fast->next;
if (fast == NULL)
- break;
+ break ;
slow = slow->next;
fast = fast->next;
}
@@ -34,7 +34,7 @@ static t_ftlst *st_lstmiddle(t_ftlst *lst, t_ftlst *last)
}
static t_ftlst *st_lstbsearch_rec(t_ftlst *lst, t_ftlst *last,
- t_ftbool (*equal)(void *ref, void *content), void *ref)
+ t_ftbool (*equal)(void *ref, void *content), void *ref)
{
t_ftlst *mid;
t_ftlst *left;
@@ -50,7 +50,7 @@ static t_ftlst *st_lstbsearch_rec(t_ftlst *lst, t_ftlst *last,
return (st_lstbsearch_rec(mid, NULL, equal, ref));
}
-t_ftlst *ft_lstbsearch(t_ftlst *lst,
+t_ftlst *ft_lstbsearch(t_ftlst *lst,
t_ftbool (*equal)(void *ref, void *content), void *ref)
{
return (st_lstbsearch_rec(lst, NULL, equal, ref));
diff --git a/test/Makefile b/test/Makefile
index 4d84321..f429a29 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -8,11 +8,12 @@ SRC_DIR = src
INCLUDE_DIR = include
CC = gcc
-CCFLAGS = -I$(INCLUDE_DIR) -I$(UNITY_DIR)/include -I$(LIBFT_DIR)/include -Wall -Wextra -Werror
+CCFLAGS = -I$(INCLUDE_DIR) -I$(UNITY_DIR)/include -I$(LIBFT_DIR)/include -Wall -Wextra #-Werror
LDFLAGS = -L$(UNITY_DIR) -lunity -L$(LIBFT_DIR) -lft
NAME = libft_test
+INCLUDE = $(shell find $(INCLUDE_DIR) -type f -name "*.h")
SRC = $(shell find $(SRC_DIR) -type f -name "*.c")
OBJ = $(SRC:.c=.o)
@@ -23,26 +24,40 @@ run: all
@echo "Test: Running"
@./$(NAME)
-$(NAME): $(OBJ)
+run_v: all
+ @echo "Test: Running"
+ @./$(NAME) -v
+
+$(NAME): libft_all $(OBJ)
@echo "Test: Linking: $@"
- @$(CC) -o $@ $^ $(LDFLAGS)
+ @$(CC) -o $@ $(OBJ) $(LDFLAGS)
-%.o: %.c
+%.o: %.c $(INCLUDE) $(LIBFT_SRC)
@echo "Test: Compiling: $@"
@$(CC) $(CCFLAGS) -c -o $@ $<
-clean: unity_fclean
+clean:
@echo "Test: Removing object"
@$(RM) $(OBJ)
-fclean:
+clean_dep: unity_fclean libft_fclean
+
+fclean: clean
@echo "Test: Removing executable"
@$(RM) $(NAME)
re: fclean all
+re_dep: clean_dep fclean all
+
unity_all:
@$(MAKE) $(MAKE_ARGS) -s -C $(UNITY_DIR) all
unity_fclean:
@$(MAKE) $(MAKE_ARGS) -s -C $(UNITY_DIR) fclean
+
+libft_all:
+ @$(MAKE) $(MAKE_ARGS) -s -C $(LIBFT_DIR) all
+
+libft_fclean:
+ @$(MAKE) $(MAKE_ARGS) -s -C $(LIBFT_DIR) fclean
diff --git a/test/include/helper/helper_segfault.h b/test/include/helper/helper_segfault.h
new file mode 100644
index 0000000..99351af
--- /dev/null
+++ b/test/include/helper/helper_segfault.h
@@ -0,0 +1,19 @@
+#ifndef HELPER_SEGFAULT_H
+# define HELPER_SEGFAULT_H
+
+extern int helper_segfault_pid;
+
+# define TEST_ASSERT_SEGFAULT(code) do { \
+ if ((helper_segfault_pid = fork()) < 0) \
+ exit(EXIT_FAILURE); \
+ if (helper_segfault_pid == 0) \
+ { \
+ do { code; } while (0); \
+ exit(EXIT_FAILURE); \
+ } \
+ wait(&helper_segfault_pid); \
+ if (WIFSIGNALED(helper_segfault_pid)) \
+ TEST_FAIL_MESSAGE("Segfault"); \
+} while (0)
+
+#endif
diff --git a/test/include/libft_test.h b/test/include/libft_test.h
index 1c5ebb5..c5eb5e2 100644
--- a/test/include/libft_test.h
+++ b/test/include/libft_test.h
@@ -1,8 +1,14 @@
#ifndef LIBFT_TEST_H
# define LIBFT_TEST_H
+# include <string.h>
+# include <sys/wait.h>
+
# include "unity.h"
# include "unity_fixture.h"
# include "libft.h"
+# include "libft_ht.h"
+
+# include "helper/helper_segfault.h"
#endif
diff --git a/test/libft_test b/test/libft_test
index 13cbab2..050602b 100755
--- a/test/libft_test
+++ b/test/libft_test
Binary files differ
diff --git a/test/src/ht/test_ft_htcontent_new.c b/test/src/ht/test_ft_htcontent_new.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/src/ht/test_ft_htcontent_new.c
diff --git a/test/src/ht/test_ft_htdelone.c b/test/src/ht/test_ft_htdelone.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/src/ht/test_ft_htdelone.c
diff --git a/test/src/ht/test_ft_htdelone_key.c b/test/src/ht/test_ft_htdelone_key.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/src/ht/test_ft_htdelone_key.c
diff --git a/test/src/ht/test_ft_htdestroy.c b/test/src/ht/test_ft_htdestroy.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/src/ht/test_ft_htdestroy.c
diff --git a/test/src/ht/test_ft_htdestroy_all.c b/test/src/ht/test_ft_htdestroy_all.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/src/ht/test_ft_htdestroy_all.c
diff --git a/test/src/ht/test_ft_htdestroy_key.c b/test/src/ht/test_ft_htdestroy_key.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/src/ht/test_ft_htdestroy_key.c
diff --git a/test/src/ht/test_ft_htget.c b/test/src/ht/test_ft_htget.c
new file mode 100644
index 0000000..5c7db28
--- /dev/null
+++ b/test/src/ht/test_ft_htget.c
@@ -0,0 +1,35 @@
+#include "libft_test.h"
+
+TEST_GROUP(ft_htget);
+
+static t_ftht *ht;
+
+TEST_SETUP(ft_htget)
+{
+ ht = ft_htnew(10);
+}
+
+TEST_TEAR_DOWN(ft_htget)
+{
+ /* ft_htdestroy_key(ht); */
+}
+
+int helper_segfault_pid;
+
+TEST(ft_htget, segfault)
+{
+ TEST_ASSERT_SEGFAULT(ft_htget((t_ftht*)NULL, ""));
+ TEST_ASSERT_SEGFAULT(ft_htget(ft_htnew(1), (char*)NULL));
+ TEST_ASSERT_SEGFAULT(ft_htget(ft_htnew(1), ""));
+ TEST_ASSERT_SEGFAULT(ft_htget(ft_htnew(1), "asdkfhjaklsdfhahjsdfk"));
+}
+
+TEST(ft_htget, error_null)
+{
+ TEST_ASSERT_NULL(ft_htget(NULL, NULL));
+ TEST_ASSERT_NULL(ft_htget(ht, NULL));
+ TEST_ASSERT_NULL(ft_htget(NULL, ""));
+ TEST_ASSERT_NULL(ft_htget(ht, ""));
+ TEST_ASSERT_NULL(ft_htget(ht, "hi"));
+ TEST_ASSERT_NULL(ft_htget(ht, "asdfkasdflk"));
+}
diff --git a/test/src/ht/test_ft_hthash.c b/test/src/ht/test_ft_hthash.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/src/ht/test_ft_hthash.c
diff --git a/test/src/ht/test_ft_htnew.c b/test/src/ht/test_ft_htnew.c
new file mode 100644
index 0000000..2696e7f
--- /dev/null
+++ b/test/src/ht/test_ft_htnew.c
@@ -0,0 +1,38 @@
+#include "libft_test.h"
+
+
+TEST_GROUP(ft_htnew);
+
+TEST_SETUP(ft_htnew)
+{}
+
+TEST_TEAR_DOWN(ft_htnew)
+{}
+
+int helper_segfault_pid;
+
+TEST(ft_htnew, segfault)
+{
+ TEST_ASSERT_SEGFAULT(ft_htnew(10));
+ TEST_ASSERT_SEGFAULT(ft_htnew(0));
+ TEST_ASSERT_SEGFAULT(ft_htnew((1 << 14) + 1));
+}
+
+TEST(ft_htnew, error_null)
+{
+ TEST_ASSERT_NOT_NULL(ft_htnew(10)); // leak
+ TEST_ASSERT_NULL(ft_htnew(0));
+ TEST_ASSERT_NULL(ft_htnew((1 << 14) + 1));
+}
+
+TEST(ft_htnew, happy_path)
+{
+ t_ftht *ht;
+
+ ht = ft_htnew(10);
+ TEST_ASSERT_NOT_NULL(ht);
+ TEST_ASSERT_EQUAL(ht->size, 10);
+ TEST_ASSERT_NOT_NULL(ht->entries);
+ for (t_ftsize i = 0; i < ht->size; i++)
+ TEST_ASSERT_NULL(ht->entries[i]);
+}
diff --git a/test/src/ht/test_ft_htset.c b/test/src/ht/test_ft_htset.c
new file mode 100644
index 0000000..aa6bfc5
--- /dev/null
+++ b/test/src/ht/test_ft_htset.c
@@ -0,0 +1,51 @@
+#include "libft_test.h"
+
+TEST_GROUP(ft_htset);
+
+static t_ftht *ht;
+
+TEST_SETUP(ft_htset)
+{
+ ht = ft_htnew(10);
+}
+
+TEST_TEAR_DOWN(ft_htset)
+{
+ ft_htdestroy_key(ht);
+}
+
+TEST(ft_htset, segfault)
+{
+ TEST_ASSERT_SEGFAULT(ft_htset(NULL, "", strdup("")));
+ TEST_ASSERT_SEGFAULT(ft_htset(ft_htnew(1), NULL, strdup("")));
+ TEST_ASSERT_SEGFAULT(ft_htset(ft_htnew(1), "", NULL));
+ TEST_ASSERT_SEGFAULT(ft_htset(ft_htnew(1), "", strdup("")));
+ TEST_ASSERT_SEGFAULT(ft_htset(ft_htnew(1), "hi", strdup("")));
+ TEST_ASSERT_SEGFAULT(ft_htset(ft_htnew(1), "asdfasdfasdc", strdup("")));
+}
+
+TEST(ft_htset, error_null)
+{
+ TEST_ASSERT_NULL(ft_htset(NULL, "", strdup("1")));
+ TEST_ASSERT_NULL(ft_htset(ht, NULL, strdup("2")));
+ TEST_ASSERT_NOT_NULL(ft_htset(ht, "", strdup("3")));
+ TEST_ASSERT_NOT_NULL(ft_htset(ht, "a", strdup("4")));
+ TEST_ASSERT_NOT_NULL(ft_htset(ht, "b", strdup("5")));
+ TEST_ASSERT_NOT_NULL(ft_htset(ht, "c", strdup("6")));
+ TEST_ASSERT_NOT_NULL(ft_htset(ht, "d", strdup("7")));
+}
+
+TEST(ft_htset, happy_path)
+{
+ t_ftht_content *content = ft_htset(ht, "bonjour", strdup("content"));
+ TEST_ASSERT_NOT_NULL(content);
+ TEST_ASSERT_NOT_NULL(content->key);
+ TEST_ASSERT_NOT_NULL(content->value);
+ TEST_ASSERT_EQUAL_STRING(content->key, "bonjour");
+ TEST_ASSERT_EQUAL_STRING(content->value, "content");
+}
+
+TEST(ft_htset, collision)
+{
+
+}
diff --git a/test/src/main.c b/test/src/main.c
new file mode 100644
index 0000000..a81bc8f
--- /dev/null
+++ b/test/src/main.c
@@ -0,0 +1,14 @@
+#include "libft_test.h"
+
+static void run_all_test(void)
+{
+ RUN_TEST_GROUP(ft_strlen);
+ RUN_TEST_GROUP(ft_htnew);
+ RUN_TEST_GROUP(ft_htget);
+ RUN_TEST_GROUP(ft_htset);
+}
+
+int main(int argc, const char **argv)
+{
+ return UnityMain(argc, argv, run_all_test);
+}
diff --git a/test/src/runner/test_runner_ht.c b/test/src/runner/test_runner_ht.c
new file mode 100644
index 0000000..d8718af
--- /dev/null
+++ b/test/src/runner/test_runner_ht.c
@@ -0,0 +1,22 @@
+#include "libft_test.h"
+
+TEST_GROUP_RUNNER(ft_htnew)
+{
+ RUN_TEST_CASE(ft_htnew, segfault);
+ RUN_TEST_CASE(ft_htnew, error_null);
+ RUN_TEST_CASE(ft_htnew, happy_path);
+}
+
+TEST_GROUP_RUNNER(ft_htget)
+{
+ RUN_TEST_CASE(ft_htget, segfault);
+ RUN_TEST_CASE(ft_htget, error_null);
+}
+
+TEST_GROUP_RUNNER(ft_htset)
+{
+ RUN_TEST_CASE(ft_htset, segfault);
+ RUN_TEST_CASE(ft_htset, error_null);
+ RUN_TEST_CASE(ft_htset, happy_path);
+ RUN_TEST_CASE(ft_htset, collision);
+}
diff --git a/test/src/runner/test_ft_strlen_runner.c b/test/src/runner/test_runner_str.c
index 368c033..368c033 100644
--- a/test/src/runner/test_ft_strlen_runner.c
+++ b/test/src/runner/test_runner_str.c