diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/src/ht/test_ft_htcontent_new.c | 43 | ||||
| -rw-r--r-- | test/src/ht/test_ft_htnew.c | 10 | ||||
| -rw-r--r-- | test/src/ht/test_ft_htset.c | 72 | ||||
| -rw-r--r-- | test/src/main.c | 1 | ||||
| -rw-r--r-- | test/src/runner/test_runner_ht.c | 8 |
5 files changed, 112 insertions, 22 deletions
diff --git a/test/src/ht/test_ft_htcontent_new.c b/test/src/ht/test_ft_htcontent_new.c index e69de29..6993581 100644 --- a/test/src/ht/test_ft_htcontent_new.c +++ b/test/src/ht/test_ft_htcontent_new.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* test_ft_htcontent_new.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/17 04:07:04 by cacharle #+# #+# */ +/* Updated: 2020/02/17 04:15:39 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_test.h" + +TEST_GROUP(ft_htcontent_new); + +TEST_SETUP(ft_htcontent_new) +{} + +TEST_TEAR_DOWN(ft_htcontent_new) +{} + +TEST(ft_htcontent_new, basic) +{ + t_ftht_content *c = NULL; + + char *k = "bonjour"; + c = ft_htcontent_new(k, NULL); + TEST_ASSERT_NOT_NULL(c); + TEST_ASSERT(k != c->key); + TEST_ASSERT_EQUAL_STRING(k, c->key); + TEST_ASSERT_NULL(c->value); + + c = ft_htcontent_new(k, k); + TEST_ASSERT_NOT_NULL(c); + TEST_ASSERT(k != c->key); + TEST_ASSERT_EQUAL_STRING(k, c->key); + TEST_ASSERT_EQUAL_PTR(k, c->value); + TEST_ASSERT_EQUAL_STRING(k, (char*)c->value); + + /* free(c->key); */ + /* free(c); */ +} diff --git a/test/src/ht/test_ft_htnew.c b/test/src/ht/test_ft_htnew.c index b8729bd..6b90f03 100644 --- a/test/src/ht/test_ft_htnew.c +++ b/test/src/ht/test_ft_htnew.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/12 22:30:06 by cacharle #+# #+# */ -/* Updated: 2020/02/12 22:30:09 by cacharle ### ########.fr */ +/* Updated: 2020/02/17 04:18:20 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,6 @@ int helper_segfault_pid; TEST(ft_htnew, segfault) { - TEST_IGNORE(); TEST_ASSERT_SEGFAULT(ft_htnew(10)); TEST_ASSERT_SEGFAULT(ft_htnew(0)); TEST_ASSERT_SEGFAULT(ft_htnew((1 << 14) + 1)); @@ -32,20 +31,17 @@ TEST(ft_htnew, segfault) TEST(ft_htnew, error_null) { - TEST_IGNORE(); - TEST_ASSERT_NOT_NULL(ft_htnew(10)); // leak + TEST_ASSERT_NOT_NULL(ft_htnew(10)); TEST_ASSERT_NULL(ft_htnew(0)); - TEST_ASSERT_NULL(ft_htnew((1 << 14) + 1)); } TEST(ft_htnew, happy_path) { - TEST_IGNORE(); t_ftht *ht; ht = ft_htnew(10); TEST_ASSERT_NOT_NULL(ht); - TEST_ASSERT_EQUAL(ht->size, 10); + TEST_ASSERT_EQUAL(10, ht->size); 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 index aa6bfc5..c4b53b9 100644 --- a/test/src/ht/test_ft_htset.c +++ b/test/src/ht/test_ft_htset.c @@ -16,28 +16,28 @@ TEST_TEAR_DOWN(ft_htset) 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_ASSERT_SEGFAULT(ft_htset(NULL, "", strdup(""), NULL)); + TEST_ASSERT_SEGFAULT(ft_htset(ft_htnew(1), NULL, strdup(""), NULL)); + TEST_ASSERT_SEGFAULT(ft_htset(ft_htnew(1), "", NULL, NULL)); + TEST_ASSERT_SEGFAULT(ft_htset(ft_htnew(1), "", strdup(""), NULL)); + TEST_ASSERT_SEGFAULT(ft_htset(ft_htnew(1), "hi", strdup(""), NULL)); + TEST_ASSERT_SEGFAULT(ft_htset(ft_htnew(1), "asdfasdfasdc", strdup(""), NULL)); } 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_ASSERT_NULL(ft_htset(NULL, "", strdup("1"), NULL)); + TEST_ASSERT_NULL(ft_htset(ht, NULL, strdup("2"), NULL)); + TEST_ASSERT_NOT_NULL(ft_htset(ht, "", strdup("3"), NULL)); + TEST_ASSERT_NOT_NULL(ft_htset(ht, "a", strdup("4"), NULL)); + TEST_ASSERT_NOT_NULL(ft_htset(ht, "b", strdup("5"), NULL)); + TEST_ASSERT_NOT_NULL(ft_htset(ht, "c", strdup("6"), NULL)); + TEST_ASSERT_NOT_NULL(ft_htset(ht, "d", strdup("7"), NULL)); } TEST(ft_htset, happy_path) { - t_ftht_content *content = ft_htset(ht, "bonjour", strdup("content")); + t_ftht_content *content = ft_htset(ht, "bonjour", strdup("content"), NULL); TEST_ASSERT_NOT_NULL(content); TEST_ASSERT_NOT_NULL(content->key); TEST_ASSERT_NOT_NULL(content->value); @@ -45,7 +45,51 @@ TEST(ft_htset, happy_path) TEST_ASSERT_EQUAL_STRING(content->value, "content"); } +TEST(ft_htset, reset) +{ + t_ftht *small = NULL; + + small = ft_htnew(3); + + t_ftht_content *content = ft_htset(ht, "bonjour", strdup("content"), free); + 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"); + + t_ftht_content *content_re = ft_htset(ht, "bonjour", strdup("yo"), free); + TEST_ASSERT_NOT_NULL(content_re); + TEST_ASSERT_EQUAL_PTR(content, content_re); + TEST_ASSERT_NOT_NULL(content_re->key); + TEST_ASSERT_NOT_NULL(content_re->value); + TEST_ASSERT_EQUAL_STRING(content_re->key, "bonjour"); + TEST_ASSERT_EQUAL_STRING(content_re->value, "yo"); +} + TEST(ft_htset, collision) { + t_ftht *small = NULL; + small = ft_htnew(1); + + t_ftht_content *content1 = ft_htset(ht, "bonjour", strdup("content1"), free); + TEST_ASSERT_NOT_NULL(content1); + TEST_ASSERT_NOT_NULL(content1->key); + TEST_ASSERT_NOT_NULL(content1->value); + TEST_ASSERT_EQUAL_STRING(content1->key, "bonjour"); + TEST_ASSERT_EQUAL_STRING(content1->value, "content1"); + + t_ftht_content *content2 = ft_htset(ht, "aurevoir", strdup("content2"), free); + TEST_ASSERT_NOT_NULL(content2); + TEST_ASSERT_NOT_NULL(content2->key); + TEST_ASSERT_NOT_NULL(content2->value); + TEST_ASSERT_EQUAL_STRING(content2->key, "aurevoir"); + TEST_ASSERT_EQUAL_STRING(content2->value, "content2"); + t_ftht_content *content3 = ft_htset(ht, "aloa", strdup("content3"), free); + TEST_ASSERT_NOT_NULL(content3); + TEST_ASSERT_NOT_NULL(content3->key); + TEST_ASSERT_NOT_NULL(content3->value); + TEST_ASSERT_EQUAL_STRING(content3->key, "aloa"); + TEST_ASSERT_EQUAL_STRING(content3->value, "content3"); } diff --git a/test/src/main.c b/test/src/main.c index 0a6d2ee..c015945 100644 --- a/test/src/main.c +++ b/test/src/main.c @@ -31,6 +31,7 @@ static void run_all_test(void) RUN_TEST_GROUP(ft_strlen); // ht + RUN_TEST_GROUP(ft_htcontent_new); RUN_TEST_GROUP(ft_htnew); RUN_TEST_GROUP(ft_htget); RUN_TEST_GROUP(ft_htset); diff --git a/test/src/runner/test_runner_ht.c b/test/src/runner/test_runner_ht.c index de20c5b..f25a61a 100644 --- a/test/src/runner/test_runner_ht.c +++ b/test/src/runner/test_runner_ht.c @@ -6,12 +6,17 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/12 22:44:39 by cacharle #+# #+# */ -/* Updated: 2020/02/12 22:47:11 by cacharle ### ########.fr */ +/* Updated: 2020/02/17 05:02:25 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft_test.h" +TEST_GROUP_RUNNER(ft_htcontent_new) +{ + RUN_TEST_CASE(ft_htcontent_new, basic); +} + TEST_GROUP_RUNNER(ft_htnew) { RUN_TEST_CASE(ft_htnew, segfault); @@ -30,5 +35,6 @@ 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, reset); RUN_TEST_CASE(ft_htset, collision); } |
