diff --git a/include/kernaux/memmap.h b/include/kernaux/memmap.h index c0537a94..837400f1 100644 --- a/include/kernaux/memmap.h +++ b/include/kernaux/memmap.h @@ -29,7 +29,7 @@ typedef struct KernAux_MemMap { struct KernAux_MemMap KernAux_MemMap_create(size_t memory_size); void KernAux_MemMap_init(KernAux_MemMap memmap, size_t memory_size); -/// @warning Must only be called with unfinished memmap, otherwise panics. +/// @warning Must only be called with NOT finished memmap, otherwise panics. bool KernAux_MemMap_add_entry( KernAux_MemMap memmap, bool is_available, @@ -38,7 +38,7 @@ bool KernAux_MemMap_add_entry( size_t size ); -/// @warning Must only be called with unfinished memmap, otherwise panics. +/// @warning Must only be called with NOT finished memmap, otherwise panics. bool KernAux_MemMap_finish(KernAux_MemMap memmap); /// @warning Must only be called with finished memmap, otherwise panics. diff --git a/tests/test_memmap.c b/tests/test_memmap.c index 825d7cd5..2694d0e9 100644 --- a/tests/test_memmap.c +++ b/tests/test_memmap.c @@ -2,6 +2,7 @@ #include "config.h" #endif +#include #include #include @@ -11,11 +12,27 @@ static KernAux_MemMap memmap; +static unsigned int assert_count_exp = 0; +static unsigned int assert_count_ctr = 0; + +static const char *assert_last_file = NULL; + +static void assert_cb( + const char *const file, + __attribute__((unused)) const int line, + __attribute__((unused)) const char *const msg +) { + ++assert_count_ctr; + assert_last_file = file; +} + #define MEMSET memset(memmap, 0xff, sizeof(memmap)) #define MEMMAP (*memmap) int main() { + kernaux_assert_cb = assert_cb; + { MEMSET; KernAux_MemMap_init(memmap, 0); @@ -31,6 +48,12 @@ int main() assert(MEMMAP.entries_count == 0); assert(KernAux_MemMap_entry_by_index(memmap, 0) == NULL); + + assert(assert_count_ctr == assert_count_exp); + assert(!KernAux_MemMap_finish(memmap)); + assert(assert_count_ctr == ++assert_count_exp); + assert(strstr(assert_last_file, "src/memmap.c") != NULL); + assert_last_file = NULL; } { @@ -140,7 +163,11 @@ int main() assert(MEMMAP.entries[0].end == 1); assert(MEMMAP.entries[0].limit == 2); + assert(assert_count_ctr == assert_count_exp); assert(KernAux_MemMap_entry_by_index(memmap, 0) == NULL); + assert(assert_count_ctr == ++assert_count_exp); + assert(strstr(assert_last_file, "src/memmap.c") != NULL); + assert_last_file = NULL; } { @@ -185,5 +212,7 @@ int main() assert(KernAux_MemMap_entry_by_index(memmap, 1) == &MEMMAP.entries[1]); } + assert(assert_count_ctr == assert_count_exp); + return 0; }