Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions mini-moul/tests/C03/ex05/ft_strlcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ typedef struct s_test
char *dest;
int size;
char *expected_output;
unsigned int pot;
} t_test;

int run_tests(t_test *tests, int count);
Expand All @@ -24,35 +25,48 @@ int main(void)
.dest = "1337 42",
.size = 20,
.expected_output = "1337 42Born to code",
.pot = 19,
},
{
.desc = "Concatenate empty strings",
.src = "",
.dest = "",
.size = 10,
.expected_output = "",
.pot = 0,
},
{
.desc = "Append to an empty string",
.src = "hello",
.dest = "",
.size = 10,
.expected_output = "hello",
.pot = 5,
},
{
.desc = "Concatenate with string larger than size",
.src = "Born to code",
.dest = "1337 42",
.size = 7,
.expected_output = "1337 42",
.pot = 19,
},
{
.desc = "Concatenate same strings with size larger than sum of their lengths",
.src = "Test",
.dest = "Test",
.size = 10,
.expected_output = "TestTest",
.pot = 8,
},
{
.desc = "Something",
.src = "and!",
.dest = "hello world",
.size = 5,
.expected_output = "hello world",
.pot = 9,
}
};
int count = sizeof(tests) / sizeof(tests[0]);

Expand All @@ -69,11 +83,12 @@ int run_tests(t_test *tests, int count)
char dest[strlen(tests[i].dest) + 1];
strcpy(dest, tests[i].dest);

ft_strlcat(dest, tests[i].src, tests[i].size);
unsigned int pot_len = ft_strlcat(dest, tests[i].src, tests[i].size);

if (strcmp(dest, tests[i].expected_output) != 0)
if (strcmp(dest, tests[i].expected_output) != 0 || pot_len != tests[i].pot)
{
printf(" " RED "[%d] %s Expected \"%s\" output \"%s\"\n" DEFAULT, i + 1, tests[i].desc, tests[i].expected_output, dest);
printf(" " RED "[%d] %s Len Expected \"%u\" output \"%u\"\n\n" DEFAULT, i + 1, "Expected Lenth V. Output Length", tests[i].pot, pot_len);
error -= 1;
}
else
Expand All @@ -83,4 +98,4 @@ int run_tests(t_test *tests, int count)
}

return error;
}
}