GCC Code Coverage Report


Directory: ./
File: tests/test_mymemory_lib.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 112 112 100.0%
Functions: 20 20 100.0%
Branches: 114 344 33.1%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2024
3 ** test_mymemory_lib
4 ** File description:
5 ** Unit tests for each function of the mymemory lib
6 */
7 /**
8 * @file test_mymemory_lib.c
9 * @brief Unit tests for each function of the mymemory lib
10 * @author Nicolas TORO
11 */
12
13 #include "criterion/criterion.h"
14 #include "criterion/redirect.h"
15 #include "../include/mymemory.h"
16
17 4 Test(my_memset, test_my_memset)
18 {
19 2 char *str = malloc(sizeof(char) * 10);
20
21
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_not_null(str);
22 2 my_memset(str, 'a', 10);
23
6/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
2 cr_assert_str_eq(str, "aaaaaaaaaa");
24 2 free(str);
25 2 my_memset(NULL, 'a', 10);
26 2 }
27
28 4 Test(my_memcpy, test_my_memcpy)
29 {
30 2 char *str = malloc(sizeof(char) * 10);
31 2 char *str2 = malloc(sizeof(char) * 10);
32 2 char *str3 = malloc(sizeof(char) * 10);
33 2 char *str4 = malloc(sizeof(char) * 10);
34
35
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_not_null(str);
36
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_not_null(str2);
37 2 my_memset(str, 'a', 10);
38 2 my_memcpy(str2, str, 10);
39 2 my_memcpy(str3, str, 5);
40 2 my_memcpy(str4, str, 15);
41
6/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
2 cr_assert_str_eq(str2, "aaaaaaaaaa");
42
6/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
2 cr_assert_str_eq(str3, "aaaaa");
43
6/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
2 cr_assert_str_eq(str4, "aaaaaaaaaa");
44 2 free(str);
45 2 free(str2);
46 2 free(str3);
47 2 free(str4);
48 2 my_memcpy(NULL, NULL, 10);
49 2 }
50
51 4 Test(my_memmove, test_my_memmove)
52 {
53 2 char *str = malloc(sizeof(char) * 10);
54 2 char *str2 = malloc(sizeof(char) * 10);
55 2 char *str3 = malloc(sizeof(char) * 10);
56 2 char *str4 = malloc(sizeof(char) * 10);
57
58
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_not_null(str);
59
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_not_null(str2);
60 2 my_memset(str, 'a', 10);
61 2 my_memmove(str2, str, 10);
62 2 my_memmove(str3, str, 5);
63 2 my_memmove(str4, str, 15);
64
6/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
2 cr_assert_str_eq(str2, "aaaaaaaaaa");
65
6/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
2 cr_assert_str_eq(str3, "aaaaa");
66
6/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
2 cr_assert_str_eq(str4, "aaaaaaaaaa");
67 2 free(str);
68 2 free(str2);
69 2 free(str3);
70 2 free(str4);
71 2 my_memmove(NULL, NULL, 10);
72 2 }
73
74 4 Test(my_memchr, test_my_memchr)
75 {
76 2 char *str = malloc(sizeof(char) * 10);
77
78
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_not_null(str);
79 2 my_memset(str, 'a', 10);
80
3/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
2 cr_assert_eq(my_memchr(str, 'a', 10), str);
81
3/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
2 cr_assert_eq(my_memchr(str, 'b', 10), NULL);
82 2 free(str);
83 2 my_memchr(NULL, 'a', 10);
84 2 }
85
86 4 Test(my_memcmp, test_my_memcmp)
87 {
88 2 char *str = malloc(sizeof(char) * 10);
89 2 char *str2 = malloc(sizeof(char) * 10);
90
91
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_not_null(str);
92
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_not_null(str2);
93 2 my_memset(str, 'a', 10);
94 2 my_memset(str2, 'a', 10);
95
3/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
2 cr_assert_eq(my_memcmp(str, str2, 10), 0);
96 2 my_memset(str2, 'b', 10);
97
3/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 1 times.
2 cr_assert_eq(my_memcmp(str, str2, 10), -1);
98 2 free(str);
99 2 free(str2);
100 2 my_memcmp(NULL, NULL, 10);
101 2 }
102
103 4 Test(my_calloc, test_my_calloc)
104 {
105 2 char *str = my_calloc(10, sizeof(char), 1);
106
107
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_not_null(str);
108
6/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
2 cr_assert_str_eq(str, "\0");
109 2 my_calloc(0, 0, 1);
110 2 my_calloc(100000000000000000, 100000000000000000, 1);
111 2 my_free();
112 2 }
113
114 4 Test(my_malloc_strdup, test_my_malloc_strdup)
115 {
116 2 char *str = my_malloc_strdup("Hello World");
117
118
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_not_null(str);
119
6/16
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
2 cr_assert_str_eq(str, "Hello World");
120 2 my_malloc_strdup(NULL);
121 2 }
122
123 4 Test(my_malloc_strdup_word_array, test_my_malloc_strdup_word_array)
124 {
125 2 char **array = malloc(sizeof(char *) * 3);
126 2 char **array2 = my_malloc_strdup_word_array(array);
127
128
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_not_null(array2);
129
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_eq(array2[0], NULL);
130
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_eq(array2[1], NULL);
131
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_eq(array2[2], NULL);
132 2 my_malloc_strdup_word_array(NULL);
133 2 array = STR2ARRAY_SEP("Hello World", " ");
134 2 array2 = my_malloc_strdup_word_array(array);
135 2 my_free();
136 2 }
137
138 4 Test(my_realloc, test_my_realloc)
139 {
140 2 char *str = malloc(sizeof(char) * 10);
141 2 char *str2 = my_realloc(str, 20, 1);
142
143
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_not_null(str2);
144 2 free(str2);
145 2 my_realloc(NULL, 0, 1);
146 2 my_realloc(NULL, 100000000000000000, 1);
147 2 }
148
149 4 Test(my_malloc, test_my_malloc)
150 {
151 2 char *str = my_malloc(10, 1);
152
153
3/10
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
2 cr_assert_not_null(str);
154 2 free(str);
155 2 my_malloc(0, 1);
156 2 my_malloc(100000000000000000, 1);
157 2 }
158
159