aboutsummaryrefslogtreecommitdiff
path: root/test_mini/libft/test/src/mem
diff options
context:
space:
mode:
authornass1pro <nass1pro@gmail.com>2020-06-09 19:48:34 +0200
committernass1pro <nass1pro@gmail.com>2020-06-13 11:31:00 +0200
commit579a26f5593039ffbbd1a81e45ecf0ef8797cb5d (patch)
treec5b6761db98e27d15bab3fb45ba9e0a646cf06e0 /test_mini/libft/test/src/mem
parent9fabc25a980550afc6337fd729632462f2680daa (diff)
downloadminishell-579a26f5593039ffbbd1a81e45ecf0ef8797cb5d.tar.gz
minishell-579a26f5593039ffbbd1a81e45ecf0ef8797cb5d.tar.bz2
minishell-579a26f5593039ffbbd1a81e45ecf0ef8797cb5d.zip
add lexer
add single quote
Diffstat (limited to 'test_mini/libft/test/src/mem')
-rw-r--r--test_mini/libft/test/src/mem/test_ft_bzero.c30
-rw-r--r--test_mini/libft/test/src/mem/test_ft_calloc.c33
-rw-r--r--test_mini/libft/test/src/mem/test_ft_memccpy.c45
-rw-r--r--test_mini/libft/test/src/mem/test_ft_memchr.c35
-rw-r--r--test_mini/libft/test/src/mem/test_ft_memcmp.c42
-rw-r--r--test_mini/libft/test/src/mem/test_ft_memcpy.c47
-rw-r--r--test_mini/libft/test/src/mem/test_ft_memmem.c65
-rw-r--r--test_mini/libft/test/src/mem/test_ft_memmove.c39
-rw-r--r--test_mini/libft/test/src/mem/test_ft_memset.c42
-rw-r--r--test_mini/libft/test/src/mem/test_ft_memset_pattern4.c42
-rw-r--r--test_mini/libft/test/src/mem/test_ft_memswap.c41
11 files changed, 461 insertions, 0 deletions
diff --git a/test_mini/libft/test/src/mem/test_ft_bzero.c b/test_mini/libft/test/src/mem/test_ft_bzero.c
new file mode 100644
index 0000000..20e560d
--- /dev/null
+++ b/test_mini/libft/test/src/mem/test_ft_bzero.c
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* test_ft_bzero.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/13 03:32:20 by cacharle #+# #+# */
+/* Updated: 2020/02/13 04:30:39 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_test.h"
+
+TEST_GROUP(ft_bzero);
+
+TEST_SETUP(ft_bzero)
+{}
+
+TEST_TEAR_DOWN(ft_bzero)
+{}
+
+TEST(ft_bzero, basic)
+{
+ char buf[32] = {'a'};
+
+ ft_bzero(buf, 32);
+ for (int i = 0; i < 32; i++)
+ TEST_ASSERT_EQUAL(0x0, buf[i]);
+}
diff --git a/test_mini/libft/test/src/mem/test_ft_calloc.c b/test_mini/libft/test/src/mem/test_ft_calloc.c
new file mode 100644
index 0000000..0df9b95
--- /dev/null
+++ b/test_mini/libft/test/src/mem/test_ft_calloc.c
@@ -0,0 +1,33 @@
+#include "libft_test.h"
+
+TEST_GROUP(ft_calloc);
+
+TEST_SETUP(ft_calloc)
+{}
+
+TEST_TEAR_DOWN(ft_calloc)
+{}
+
+TEST(ft_calloc, basic)
+{
+ char *ptr = NULL;
+
+ ptr = ft_calloc(45, sizeof(char));
+ TEST_ASSERT_NOT_NULL(ptr);
+#ifdef __APPLE__
+ TEST_ASSERT_GREATER_THAN(45 * sizeof(char) - 1, malloc_size(ptr));
+#endif
+ for (int i = 0; i < 45; i++)
+ TEST_ASSERT_EQUAL(0x0, ptr[i]);
+ /* free(ptr); */
+
+ int *ptrint = NULL;
+ ptrint = ft_calloc(10, sizeof(int));
+ TEST_ASSERT_NOT_NULL(ptr);
+#ifdef __APPLE__
+ TEST_ASSERT_GREATER_THAN(10 * sizeof(int) - 1, malloc_size(ptrint));
+#endif
+ for (int i = 0; i < 10; i++)
+ TEST_ASSERT_EQUAL(0x0, ptrint[i]);
+ /* free(ptrint); */
+}
diff --git a/test_mini/libft/test/src/mem/test_ft_memccpy.c b/test_mini/libft/test/src/mem/test_ft_memccpy.c
new file mode 100644
index 0000000..39925a1
--- /dev/null
+++ b/test_mini/libft/test/src/mem/test_ft_memccpy.c
@@ -0,0 +1,45 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* test_ft_memccpy.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/13 03:34:13 by cacharle #+# #+# */
+/* Updated: 2020/02/13 19:35:17 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_test.h"
+
+TEST_GROUP(ft_memccpy);
+
+TEST_SETUP(ft_memccpy)
+{}
+
+TEST_TEAR_DOWN(ft_memccpy)
+{}
+
+TEST(ft_memccpy, basic)
+{
+ char buf[32] = "bonjour";
+ char buf2[32] = {0};
+
+ char *ptr = ft_memccpy(buf2, buf, 0x0, 32);
+ TEST_ASSERT_EQUAL_PTR(&buf2[8], ptr);
+ for (int i = 0; i < 32; i++)
+ TEST_ASSERT_EQUAL_CHAR(buf[i], buf2[i]);
+
+ ptr = ft_memccpy(buf2, buf, 0x1, 32);
+ TEST_ASSERT_NULL(ptr);
+ for (int i = 0; i < 32; i++)
+ TEST_ASSERT_EQUAL_CHAR(buf[i], buf2[i]);
+
+ char buf3[10] = "aurevoir";
+ ptr = ft_memccpy(buf, buf3, 'e', 10);
+ TEST_ASSERT_EQUAL_PTR(buf + 4, ptr);
+ for (int i = 0; i < 4; i++)
+ TEST_ASSERT_EQUAL_CHAR(buf[i], buf3[i]);
+ for (int i = 4; i < 32; i++)
+ TEST_ASSERT_EQUAL_CHAR(buf[i], buf2[i]);
+}
diff --git a/test_mini/libft/test/src/mem/test_ft_memchr.c b/test_mini/libft/test/src/mem/test_ft_memchr.c
new file mode 100644
index 0000000..135edfb
--- /dev/null
+++ b/test_mini/libft/test/src/mem/test_ft_memchr.c
@@ -0,0 +1,35 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* test_ft_memchr.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/13 03:33:14 by cacharle #+# #+# */
+/* Updated: 2020/02/13 19:38:17 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_test.h"
+
+TEST_GROUP(ft_memchr);
+
+TEST_SETUP(ft_memchr)
+{}
+
+TEST_TEAR_DOWN(ft_memchr)
+{}
+
+TEST(ft_memchr, basic)
+{
+ char *a = "bonjour";
+
+ char *ptr = ft_memchr(a, 'j', sizeof(a));
+ TEST_ASSERT_EQUAL_PTR(a + 3, ptr);
+
+ ptr = ft_memchr(a, 'z', sizeof(a));
+ TEST_ASSERT_NULL(ptr);
+
+ ptr = ft_memchr(a, '\0', sizeof(a));
+ TEST_ASSERT_EQUAL_PTR(a + 7, ptr);
+}
diff --git a/test_mini/libft/test/src/mem/test_ft_memcmp.c b/test_mini/libft/test/src/mem/test_ft_memcmp.c
new file mode 100644
index 0000000..81871a1
--- /dev/null
+++ b/test_mini/libft/test/src/mem/test_ft_memcmp.c
@@ -0,0 +1,42 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* test_ft_memcmp.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/13 03:32:16 by cacharle #+# #+# */
+/* Updated: 2020/02/13 19:41:08 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_test.h"
+
+TEST_GROUP(ft_memcmp);
+
+TEST_SETUP(ft_memcmp)
+{}
+
+TEST_TEAR_DOWN(ft_memcmp)
+{}
+
+TEST(ft_memcmp, basic)
+{
+ char buf1[32] = "bonjour";
+ char buf2[32] = "bonjoure";
+
+ int res = ft_memcmp(buf1, buf2, 32);
+ TEST_ASSERT_LESS_THAN(0, res);
+
+ res = ft_memcmp(buf2, buf1, 32);
+ TEST_ASSERT_GREATER_THAN(0, res);
+
+ res = ft_memcmp(buf2, buf1, 7);
+ TEST_ASSERT_EQUAL(0, res);
+ res = ft_memcmp(buf2, buf1, 6);
+ TEST_ASSERT_EQUAL(0, res);
+ res = ft_memcmp(buf2, buf1, 3);
+ TEST_ASSERT_EQUAL(0, res);
+ res = ft_memcmp(buf2, buf1, 0);
+ TEST_ASSERT_EQUAL(0, res);
+}
diff --git a/test_mini/libft/test/src/mem/test_ft_memcpy.c b/test_mini/libft/test/src/mem/test_ft_memcpy.c
new file mode 100644
index 0000000..3afe817
--- /dev/null
+++ b/test_mini/libft/test/src/mem/test_ft_memcpy.c
@@ -0,0 +1,47 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* test_ft_memcpy.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/13 03:33:22 by cacharle #+# #+# */
+/* Updated: 2020/02/13 04:27:55 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_test.h"
+
+TEST_GROUP(ft_memcpy);
+
+TEST_SETUP(ft_memcpy)
+{}
+
+TEST_TEAR_DOWN(ft_memcpy)
+{}
+
+TEST(ft_memcpy, basic)
+{
+ void *ptr;
+ unsigned char buf1[32] = {0};
+ unsigned char buf2[32] = "bonjour";
+
+ ptr = ft_memcpy(buf1, buf2, 32);
+ TEST_ASSERT_NOT_NULL(ptr);
+ TEST_ASSERT_EQUAL_PTR(buf1, ptr);
+ TEST_ASSERT_EQUAL(0, memcmp(buf1, buf2, 32));
+
+ ptr = ft_memcpy(buf1, "yo", 3);
+ TEST_ASSERT_NOT_NULL(ptr);
+ TEST_ASSERT_EQUAL_PTR(buf1, ptr);
+ TEST_ASSERT_EQUAL(0, memcmp(buf1, "yo", 3));
+ TEST_ASSERT_EQUAL(0, memcmp(buf1 + 3, buf2 + 3, 32 - 3));
+
+ char saved[32];
+
+ memcpy(saved, buf2, 32);
+ ptr = ft_memcpy(buf2, "", 0);
+ TEST_ASSERT_NOT_NULL(ptr);
+ TEST_ASSERT_EQUAL_PTR(buf2, ptr);
+ TEST_ASSERT_EQUAL(0, memcmp(buf2, saved, 32));
+}
diff --git a/test_mini/libft/test/src/mem/test_ft_memmem.c b/test_mini/libft/test/src/mem/test_ft_memmem.c
new file mode 100644
index 0000000..67514a5
--- /dev/null
+++ b/test_mini/libft/test/src/mem/test_ft_memmem.c
@@ -0,0 +1,65 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* test_ft_memmem.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/13 03:33:50 by cacharle #+# #+# */
+/* Updated: 2020/02/13 21:04:22 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_test.h"
+
+TEST_GROUP(ft_memmem);
+
+TEST_SETUP(ft_memmem)
+{}
+
+TEST_TEAR_DOWN(ft_memmem)
+{}
+
+TEST(ft_memmem, basic)
+{
+ char haystack[32] = "bonjour";
+ char *ptr;
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "jour\0", 5);
+ TEST_ASSERT_EQUAL_PTR(haystack + 3, ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "jour", 4);
+ TEST_ASSERT_EQUAL_PTR(haystack + 3, ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "jo", 2);
+ TEST_ASSERT_EQUAL_PTR(haystack + 3, ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "j", 1);
+ TEST_ASSERT_EQUAL_PTR(haystack + 3, ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "yo", 2);
+ TEST_ASSERT_NULL(ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "\0", 1);
+ TEST_ASSERT_EQUAL_PTR(haystack + 7, ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "bon", 3);
+ TEST_ASSERT_EQUAL_PTR(haystack, ptr);
+
+ ptr = ft_memmem(haystack, sizeof(haystack), "on", 2);
+ TEST_ASSERT_EQUAL_PTR(haystack + 1, ptr);
+}
+
+TEST(ft_memmem, invalid_len)
+{
+ char buf[32] = {0};
+
+ void *ptr = ft_memmem(buf, 2, "jour", 4);
+ TEST_ASSERT_NULL(ptr);
+
+ ptr = ft_memmem(buf, 0, "jour", 4);
+ TEST_ASSERT_NULL(ptr);
+
+ ptr = ft_memmem(buf, 2, "jour", 0);
+ TEST_ASSERT_NULL(ptr);
+}
diff --git a/test_mini/libft/test/src/mem/test_ft_memmove.c b/test_mini/libft/test/src/mem/test_ft_memmove.c
new file mode 100644
index 0000000..158cda9
--- /dev/null
+++ b/test_mini/libft/test/src/mem/test_ft_memmove.c
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* test_ft_memmove.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/13 03:34:21 by cacharle #+# #+# */
+/* Updated: 2020/02/13 19:49:07 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_test.h"
+
+TEST_GROUP(ft_memmove);
+
+TEST_SETUP(ft_memmove)
+{}
+
+TEST_TEAR_DOWN(ft_memmove)
+{}
+
+TEST(ft_memmove, basic)
+{
+ char buf1[32] = "bonjour";
+
+ char *ptr = ft_memmove(buf1, buf1 + 2, 29);
+ TEST_ASSERT_EQUAL_PTR(buf1, ptr);
+ TEST_ASSERT_EQUAL_STRING("njour", buf1);
+
+ ptr = ft_memmove(buf1 + 2, buf1, 29);
+ TEST_ASSERT_EQUAL_PTR(buf1 + 2, ptr);
+ TEST_ASSERT_EQUAL_STRING("njour", ptr);
+ TEST_ASSERT_EQUAL_STRING("njnjour", buf1);
+
+ ptr = ft_memmove(buf1, buf1, 32);
+ TEST_ASSERT_EQUAL_PTR(buf1, ptr);
+ TEST_ASSERT_EQUAL_STRING("njnjour", ptr);
+}
diff --git a/test_mini/libft/test/src/mem/test_ft_memset.c b/test_mini/libft/test/src/mem/test_ft_memset.c
new file mode 100644
index 0000000..7ec5846
--- /dev/null
+++ b/test_mini/libft/test/src/mem/test_ft_memset.c
@@ -0,0 +1,42 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* test_ft_memset.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/13 03:32:28 by cacharle #+# #+# */
+/* Updated: 2020/02/13 04:21:58 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_test.h"
+
+TEST_GROUP(ft_memset);
+
+TEST_SETUP(ft_memset)
+{}
+
+TEST_TEAR_DOWN(ft_memset)
+{}
+
+TEST(ft_memset, basic)
+{
+ int i;
+ unsigned char buf[32] = {0};
+
+ ft_memset(buf, 0xfa, 32);
+ for (i = 0; i < 32; i++)
+ TEST_ASSERT_EQUAL(0xfa, buf[i]);
+
+ ft_memset(buf, 0x00, 15);
+ for (i = 0; i < 15; i++)
+ TEST_ASSERT_EQUAL(0x00, buf[i]);
+ while (i++ < 31)
+ TEST_ASSERT_EQUAL(0xfa, buf[i]);
+
+ ft_memset(buf, 0x10, 31);
+ for (int i = 0; i < 31; i++)
+ TEST_ASSERT_EQUAL(0x10, buf[i]);
+ TEST_ASSERT_EQUAL(0xfa, buf[31]);
+}
diff --git a/test_mini/libft/test/src/mem/test_ft_memset_pattern4.c b/test_mini/libft/test/src/mem/test_ft_memset_pattern4.c
new file mode 100644
index 0000000..0e2806a
--- /dev/null
+++ b/test_mini/libft/test/src/mem/test_ft_memset_pattern4.c
@@ -0,0 +1,42 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* test_ft_memset_pattern4.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/13 03:32:43 by cacharle #+# #+# */
+/* Updated: 2020/02/13 19:57:48 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_test.h"
+
+TEST_GROUP(ft_memset_pattern4);
+
+TEST_SETUP(ft_memset_pattern4)
+{}
+
+TEST_TEAR_DOWN(ft_memset_pattern4)
+{}
+
+TEST(ft_memset_pattern4, basic)
+{
+ char buf[17] = {0};
+ char *pattern4 = "1234";
+
+ ft_memset_pattern4(buf, pattern4, 16);
+ TEST_ASSERT_EQUAL_STRING("1234123412341234", buf);
+
+ char buf1[10] = {0};
+ ft_memset_pattern4(buf1, "1234", 9);
+ TEST_ASSERT_EQUAL_STRING("123412341", buf1);
+
+ char buf2[11] = {0};
+ ft_memset_pattern4(buf2, "1234", 10);
+ TEST_ASSERT_EQUAL_STRING("1234123412", buf2);
+
+ char buf3[12] = {0};
+ ft_memset_pattern4(buf3, "1234", 11);
+ TEST_ASSERT_EQUAL_STRING("12341234123", buf3);
+}
diff --git a/test_mini/libft/test/src/mem/test_ft_memswap.c b/test_mini/libft/test/src/mem/test_ft_memswap.c
new file mode 100644
index 0000000..72c3402
--- /dev/null
+++ b/test_mini/libft/test/src/mem/test_ft_memswap.c
@@ -0,0 +1,41 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* test_ft_memswap.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/13 03:38:27 by cacharle #+# #+# */
+/* Updated: 2020/02/13 04:18:14 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_test.h"
+
+TEST_GROUP(ft_memswap);
+
+TEST_SETUP(ft_memswap)
+{}
+
+TEST_TEAR_DOWN(ft_memswap)
+{}
+
+TEST(ft_memswap, basic)
+{
+ char buf1[32] = "bonjour";
+ char buf2[32] = "aurevoir";
+ ft_memswap(buf1, buf2, 32);
+ TEST_ASSERT_EQUAL_STRING("bonjour", buf2);
+ TEST_ASSERT_EQUAL_STRING("aurevoir", buf1);
+ ft_memswap(buf1, buf2, 3);
+ TEST_ASSERT_EQUAL_STRING("aurjour", buf2);
+ TEST_ASSERT_EQUAL_STRING("bonevoir", buf1);
+ ft_memswap(buf1, buf2, 0);
+ TEST_ASSERT_EQUAL_STRING("aurjour", buf2);
+ TEST_ASSERT_EQUAL_STRING("bonevoir", buf1);
+ int a = 1234567;
+ int b = 7654321;
+ ft_memswap(&a, &b, sizeof(int));
+ TEST_ASSERT_EQUAL(7654321, a);
+ TEST_ASSERT_EQUAL(1234567, b);
+}