Browse Source

Update memory and data tests

Use modes for list teardown calls to prevent pollution of the tracked
calls.
master
TheoryOfNekomata 1 year ago
parent
commit
0ad985b4f0
4 changed files with 23 additions and 4 deletions
  1. +1
    -1
      __mocks__/src/packages/log/IZ_log.mock.h
  2. +10
    -1
      __mocks__/src/packages/stdinc/IZ_stdlib.mock.h
  3. +8
    -1
      src/packages/game/data/data.test.c
  4. +4
    -1
      src/packages/game/memory/IZ_pool.c

+ 1
- 1
__mocks__/src/packages/log/IZ_log.mock.h View File

@@ -9,7 +9,7 @@ mock_modes(IZ_LogInfo) {
IZ_LOG_INFO_LOG, IZ_LOG_INFO_LOG,
}; };


mock(IZ_LogInfo) void IZ_LogInfo(IZ_LogCategory category, const char* fmt, ...) {
mock(IZ_LogInfo) void IZ_LogInfo(IZ_LogCategory category, const char* context, const char* fmt, ...) {
mock_mode_if(IZ_LogInfo, IZ_LOG_INFO_SUPPRESS) { mock_mode_if(IZ_LogInfo, IZ_LOG_INFO_SUPPRESS) {
mock_return(IZ_LogInfo); mock_return(IZ_LogInfo);
} else mock_mode_if(IZ_LogInfo, IZ_LOG_INFO_LOG) { } else mock_mode_if(IZ_LogInfo, IZ_LOG_INFO_LOG) {


+ 10
- 1
__mocks__/src/packages/stdinc/IZ_stdlib.mock.h View File

@@ -8,8 +8,17 @@ mock(IZ_malloc) void* IZ_malloc(size_t size) {
mock_return(IZ_malloc) SDL_malloc(size); mock_return(IZ_malloc) SDL_malloc(size);
} }


mock_modes(IZ_free) {
IZ_FREE_CALLS_TRACKED = 0,
IZ_FREE_CALLS_UNTRACKED,
};

mock(IZ_free) void IZ_free(void* mem) { mock(IZ_free) void IZ_free(void* mem) {
mock_return(IZ_free) SDL_free(mem);
mock_mode_if(IZ_free, IZ_FREE_CALLS_TRACKED) {
mock_return(IZ_free) SDL_free(mem);
} else mock_mode_if(IZ_free, IZ_FREE_CALLS_UNTRACKED) {
SDL_free(mem);
}
} }


mock(IZ_calloc) void* IZ_calloc(unsigned int num, size_t size) { mock(IZ_calloc) void* IZ_calloc(unsigned int num, size_t size) {


+ 8
- 1
src/packages/game/data/data.test.c View File

@@ -21,8 +21,8 @@ spec("data") {
static IZ_List list; static IZ_List list;


after_each() { after_each() {
mock_mode(IZ_free, IZ_FREE_CALLS_UNTRACKED);
IZ_ListTeardown(&list); IZ_ListTeardown(&list);
mock_reset(IZ_free);
} }


it("sets root to NULL") { it("sets root to NULL") {
@@ -47,6 +47,8 @@ spec("data") {
IZ_ListAppendNode(&list, &value1); IZ_ListAppendNode(&list, &value1);
IZ_ListAppendNode(&list, &value2); IZ_ListAppendNode(&list, &value2);
IZ_ListAppendNode(&list, &value3); IZ_ListAppendNode(&list, &value3);

mock_mode(IZ_free, IZ_FREE_CALLS_TRACKED);
} }


after_each() { after_each() {
@@ -93,10 +95,12 @@ spec("data") {
} }


after_each() { after_each() {
mock_mode(IZ_free, IZ_FREE_CALLS_UNTRACKED);
IZ_ListTeardown(&list); IZ_ListTeardown(&list);
} }


after_each() { after_each() {
mock_mode(IZ_free, IZ_FREE_CALLS_UNTRACKED);
IZ_ListTeardown(&list2); IZ_ListTeardown(&list2);
} }


@@ -139,6 +143,7 @@ spec("data") {
} }


after_each() { after_each() {
mock_mode(IZ_free, IZ_FREE_CALLS_UNTRACKED);
IZ_ListTeardown(&list); IZ_ListTeardown(&list);
} }


@@ -167,6 +172,8 @@ spec("data") {
IZ_ListAppendNode(&list, &value1); IZ_ListAppendNode(&list, &value1);
IZ_ListAppendNode(&list, &value2); IZ_ListAppendNode(&list, &value2);
IZ_ListAppendNode(&list, &value3); IZ_ListAppendNode(&list, &value3);

mock_mode(IZ_free, IZ_FREE_CALLS_TRACKED);
} }


after_each() { after_each() {


+ 4
- 1
src/packages/game/memory/IZ_pool.c View File

@@ -43,7 +43,10 @@ bool IZ_PoolGetSameItem(IZ_ListNode** node, u64 _index, IZ_List* list) {
} }


void IZ_PoolDeallocate(IZ_PoolItem* item) { void IZ_PoolDeallocate(IZ_PoolItem* item) {
IZ_ListDeleteNode(&item->pool->items, IZ_PoolGetSameItem);
IZ_ListNode** node = IZ_ListFindFirstNode(&item->pool->items, IZ_PoolGetSameItem);
if (node) {
IZ_ListDeleteNode(*node);
}
} }


void IZ_PoolTeardown(IZ_Pool* pool) { void IZ_PoolTeardown(IZ_Pool* pool) {


Loading…
Cancel
Save