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
46 changes: 43 additions & 3 deletions tests/src/hashmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,24 @@ extern "C" {
}

#include <stdio.h>
#define HM_SIZE 100
#define HM_SIZE 1000

TEST_CASE( "create_destroy hashmap", "[hashmap]" ) {
void *hashmap = hm_new(HM_SIZE);
REQUIRE(hashmap != NULL);
hm_destroy(hashmap, free);
}

TEST_CASE( "hm_set hashmap", "[hashmap]" ) {
TEST_CASE("basic hm_set test", "[hashmap]") {
void *hashmap = hm_new(HM_SIZE);
char *key = ft_strdup("Hello hashmap hm_set tester, let's find the bug ! @@@@@@@@\n");
char *value = ft_strdup("An exemple of value to test !##############\n");
REQUIRE(hm_set(hashmap, key, value) != NULL);
free(key);
hm_destroy(hashmap, free);
}

TEST_CASE( "hm_set in a simple loop", "[hashmap]" ) {
void *hashmap = hm_new(HM_SIZE);
int i = 0;
while(i < 5)
Expand All @@ -46,6 +55,37 @@ TEST_CASE( "hm_set hashmap", "[hashmap]" ) {
hm_destroy(hashmap, free);
}

/* double free */

TEST_CASE("hm_set 2 insertions on the same key, key is const char *.")
{
void *hashmap = hm_new(HM_SIZE);
const char *str_key = "&1";
const char *str = "TEST ARRAY @@@ #### \n\n 0123456789 -+---*-*-+6fefefefsfgesfefefefefefefefesfesfsfesfsffefefsfsffefsfsfefesfesfs";
char *value = ft_strdup(str);
REQUIRE(hm_set(hashmap, (char *)str_key, value));
REQUIRE(hm_set(hashmap, (char *)str_key, value));
hm_destroy(hashmap, free);
}

/* DOUBLE FREE */

TEST_CASE("hm_set 2 insertions on 2 different keys . key is const char *")
{
void *hashmap = hm_new(HM_SIZE);
const char *str_key = "&1";
const char *str_key2 = "&2";
const char *str = "TEST ARRAY @@@ #### \n\n 0123456789 -+---*-*-+6fefefefsfgesfefefefefefefefesfesfsfesfsffefefsfsffefsfsfefesfesfs";
char *value = ft_strdup(str);
REQUIRE(hm_set(hashmap, (char *)str_key, value));
REQUIRE(hm_set(hashmap, (char *)str_key2, value));
hm_destroy(hashmap, free);
}


/*
LEAKS

TEST_CASE("hm_set further testing", "[hashmap]")
{
void *hashmap = hm_new(HM_SIZE);
Expand All @@ -62,4 +102,4 @@ TEST_CASE("hm_set further testing", "[hashmap]")
}
hm_destroy(hashmap, free);
}

*/