Skip to content

Commit

Permalink
updated tests for null
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and root committed Oct 20, 2024
1 parent 0620624 commit 97cf7ad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ alloc_array( size_t item_count, size_t item_size ) {
}

malloc_func_t stumpless_get_malloc(void) {
return stumpless_malloc;
return stumpless_malloc ? stumpless_malloc : NULL;
}

free_func_t stumpless_get_free(void) {
return stumpless_free;
return stumpless_free ? stumpless_free : NULL;
}

realloc_func_t stumpless_get_realloc(void) {
return stumpless_realloc;
return stumpless_realloc ? stumpless_realloc : NULL;
}
21 changes: 21 additions & 0 deletions test/function/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,25 @@ namespace {
EXPECT_EQ(realloc_function, realloc);
}

TEST(MemoryFunctionsTest, GetMalloc_NullFunction) {
stumpless_set_malloc(NULL);
auto malloc_function = stumpless_get_malloc();
EXPECT_EQ(malloc_function, nullptr);
EXPECT_ERROR_ID_EQ(STUMPLESS_ARGUMENT_EMPTY);
}

TEST(MemoryFunctionsTest, GetFree_NullFunction) {
stumpless_set_free(NULL);
auto free_function = stumpless_get_free();
EXPECT_EQ(free_function, nullptr);
EXPECT_ERROR_ID_EQ(STUMPLESS_ARGUMENT_EMPTY);
}

TEST(MemoryFunctionsTest, GetRealloc_NullFunction) {
stumpless_set_realloc(NULL);
auto realloc_function = stumpless_get_realloc();
EXPECT_EQ(realloc_function, nullptr);
EXPECT_ERROR_ID_EQ(STUMPLESS_ARGUMENT_EMPTY);
}

}

0 comments on commit 97cf7ad

Please sign in to comment.