瀏覽代碼

Update video tests

Properly mock video function dependencies.
feature/data-structs
TheoryOfNekomata 2 年之前
父節點
當前提交
5caae74ebc
共有 10 個檔案被更改,包括 95 行新增10 行删除
  1. +2
    -0
      CMakeLists.txt
  2. +53
    -0
      __mocks__/SDL_render.mock.h
  3. +10
    -5
      src/packages/game/IZ_app.c
  4. +1
    -1
      src/packages/game/IZ_app.h
  5. +4
    -0
      src/packages/game/memory/IZ_pool.c
  6. +2
    -0
      src/packages/game/memory/IZ_pool.h
  7. +18
    -0
      src/packages/game/memory/memory.test.c
  8. +2
    -2
      src/packages/game/output/IZ_video.c
  9. +0
    -1
      src/packages/game/output/IZ_video.h
  10. +3
    -1
      src/packages/game/output/output.test.c

+ 2
- 0
CMakeLists.txt 查看文件

@@ -100,6 +100,8 @@ add_executable(
src/packages/test/IZ_test.h

__mocks__/minIni.mock.h
__mocks__/SDL_stdinc.mock.h
__mocks__/SDL_render.mock.h

src/packages/game/IZ_config.h



+ 53
- 0
__mocks__/SDL_render.mock.h 查看文件

@@ -0,0 +1,53 @@
#ifndef SDL_RENDER_MOCK_H
#define SDL_RENDER_MOCK_H

#include "../src/packages/test/IZ_test.h"

typedef struct SDL_Renderer SDL_Renderer;

typedef struct SDL_Window SDL_Window;

typedef struct SDL_FRect SDL_FRect;

mock(SDL_CreateWindow) SDL_Window* SDL_CreateWindow(
const char *title,
int x, int y, int w,
int h, unsigned int flags
) {
static SDL_Window* window = (SDL_Window*) 1;
mock_return(SDL_CreateWindow) window;
}

mock(SDL_CreateRenderer) SDL_Renderer* SDL_CreateRenderer(SDL_Window* window, int index, unsigned int flags) {
static SDL_Renderer* renderer = (SDL_Renderer*) 1;
mock_return(SDL_CreateRenderer) renderer;
}

mock(SDL_SetRenderDrawColor) int SDL_SetRenderDrawColor(
SDL_Renderer* renderer,
unsigned char r, unsigned char g, unsigned char b,
unsigned char a
) {
mock_return(SDL_SetRenderDrawColor) 0;
}

mock(SDL_RenderFillRectF) int SDL_RenderFillRectF(
SDL_Renderer* renderer,
const SDL_FRect* rect
) {
mock_return(SDL_RenderFillRectF) 0;
}

mock(SDL_RenderClear) int SDL_RenderClear(SDL_Renderer* renderer) {
mock_return(SDL_RenderClear) 0;
}

mock(SDL_RenderPresent) void SDL_RenderPresent(SDL_Renderer* renderer) {
mock_return(SDL_RenderPresent);
}

mock(SDL_DestroyWindow) void SDL_DestroyWindow(SDL_Window* window) {
mock_return(SDL_DestroyWindow);
}

#endif

+ 10
- 5
src/packages/game/IZ_app.c 查看文件

@@ -1,24 +1,26 @@
#include "IZ_app.h"

IZ_ProcedureResult IZ_AppInitialize(IZ_App* app) {
if (SDL_Init(
u32 flags = (
SDL_INIT_VIDEO
| SDL_INIT_GAMECONTROLLER
| SDL_INIT_EVENTS
) < 0) {
);

if (SDL_Init(flags) < 0) {
// TODO fix logging
fprintf_s(stderr, "SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
return 1;
}

char config_path[128];
IZ_ConfigGetPath(config_path, 128);

if (IZ_VideoInitialize(config_path, &app->video_state)) {
return 2;
}

IZ_InputInitialize(config_path, &app->input_state);
IZ_PoolInitialize(&app->memory_pool);
IZ_PoolInitialize(&app->pool);
// void* p1 = IZ_PoolAllocate(&app->memory_pool, sizeof(u16), 0)->pointer;
// void* p2 = IZ_PoolAllocate(&app->memory_pool, sizeof(u8), 0)->pointer;
// void* p3 = IZ_PoolAllocate(&app->memory_pool, sizeof(u64), 0)->pointer;
@@ -27,12 +29,15 @@ IZ_ProcedureResult IZ_AppInitialize(IZ_App* app) {
// IZ_PoolDeallocate(p1);
// void* p5 = IZ_PoolAllocate(&app->memory_pool, sizeof(u16), 0)->pointer;
// printf("\n%p\n", p5);
app->quit = false;

// TODO put into its timer module
app->ticks = 0;
app->quit = false;
return 0;
}

void IZ_AppTeardown(IZ_App* app) {
IZ_PoolTeardown(&app->pool);
IZ_InputTeardown(&app->input_state);
IZ_VideoTeardown(&app->video_state);
SDL_Quit();


+ 1
- 1
src/packages/game/IZ_app.h 查看文件

@@ -18,7 +18,7 @@ typedef struct {
IZ_InputState input_state;
IZ_VideoState video_state;

IZ_Pool memory_pool;
IZ_Pool pool;
u64 ticks;
bool quit;
} IZ_App;


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

@@ -46,3 +46,7 @@ void IZ_PoolDeallocate(IZ_PoolItem* item) {
return;
}
}

void IZ_PoolTeardown(IZ_Pool* pool) {
SDL_free(pool->memory);
}

+ 2
- 0
src/packages/game/memory/IZ_pool.h 查看文件

@@ -29,4 +29,6 @@ IZ_PoolItem* IZ_PoolAllocate(IZ_Pool*, size_t, u64);

void IZ_PoolDeallocate(IZ_PoolItem*);

void IZ_PoolTeardown(IZ_Pool*);

#endif

+ 18
- 0
src/packages/game/memory/memory.test.c 查看文件

@@ -0,0 +1,18 @@
#include "../../test/IZ_test.h"
#include "IZ_pool.h"

spec("memory") {
describe("pool") {
describe("PoolInitialize") {

}

describe("PoolAllocate") {

}

describe("PoolDeallocate") {

}
}
}

+ 2
- 2
src/packages/game/output/IZ_video.c 查看文件

@@ -25,7 +25,7 @@ IZ_ProcedureResult IZ_VideoInitialize(const char* config_path, IZ_VideoState* st

IZ_VideoLoadConfig(config_path, &state->config);
if (IZ_VideoSaveConfig(config_path, &state->config)) {
fprintf_s(stderr, "Error committing video config.\n");
// fprintf_s(stderr, "Error committing video config.\n");
}
state->last_update_at = 0u;

@@ -38,7 +38,7 @@ IZ_ProcedureResult IZ_VideoInitialize(const char* config_path, IZ_VideoState* st
SDL_WINDOW_SHOWN
);
if (window == NULL) {
fprintf_s(stderr, "Window could not be created! SDL_Error: %s\n", SDL_GetError());
// fprintf_s(stderr, "Window could not be created! SDL_Error: %s\n", SDL_GetError());
return 1;
}
state->window = window;


+ 0
- 1
src/packages/game/output/IZ_video.h 查看文件

@@ -3,7 +3,6 @@

#include <stdio.h>
#include <minIni.h>
#include <SDL_video.h>
#include <SDL_render.h>

// TODO move this out from video, refer to app's state instead


+ 3
- 1
src/packages/game/output/output.test.c 查看文件

@@ -1,9 +1,11 @@
#include "../../../__mocks__/minIni.mock.h"
#include "../../../__mocks__/SDL_stdinc.mock.h"
#include "../../../__mocks__/SDL_render.mock.h"
#include "IZ_video.h"

spec("output") {
describe("video") {
describe("SaveVideoConfig") {
describe("VideoSaveConfig") {
static IZ_VideoConfig config;

after_each() {


Loading…
取消
儲存