瀏覽代碼

Update memory and data tests

Use modes for list teardown calls to prevent pollution of the tracked
calls.
master
TheoryOfNekomata 1 年之前
父節點
當前提交
0ad985b4f0
共有 4 個文件被更改,包括 23 次插入4 次删除
  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 查看文件

@@ -9,7 +9,7 @@ mock_modes(IZ_LogInfo) {
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_return(IZ_LogInfo);
} else mock_mode_if(IZ_LogInfo, IZ_LOG_INFO_LOG) {


+ 10
- 1
__mocks__/src/packages/stdinc/IZ_stdlib.mock.h 查看文件

@@ -8,8 +8,17 @@ mock(IZ_malloc) void* IZ_malloc(size_t 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_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) {


+ 8
- 1
src/packages/game/data/data.test.c 查看文件

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

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

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

mock_mode(IZ_free, IZ_FREE_CALLS_TRACKED);
}

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

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

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

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

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

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

mock_mode(IZ_free, IZ_FREE_CALLS_TRACKED);
}

after_each() {


+ 4
- 1
src/packages/game/memory/IZ_pool.c 查看文件

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

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) {


Loading…
取消
儲存