From 97cf7ad965e8e7c2b45fdc37cff561875cfb6705 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 20 Oct 2024 15:59:59 +0200 Subject: [PATCH] updated tests for null --- src/memory.c | 6 +++--- test/function/memory.cpp | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/memory.c b/src/memory.c index 7c9d225f..51bacf94 100644 --- a/src/memory.c +++ b/src/memory.c @@ -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; } \ No newline at end of file diff --git a/test/function/memory.cpp b/test/function/memory.cpp index cf658fa7..96c98f1e 100644 --- a/test/function/memory.cpp +++ b/test/function/memory.cpp @@ -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); + } + }