#include #include "../../test/IZ_mock.h" #include "IZ_video.h" mock(SDL_GetBasePath) char* SDL_GetBasePath() { mock_return(SDL_GetBasePath) ""; } mock(SDL_GetKeyName) const char* SDL_GetKeyName (SDL_KeyCode code) { mock_return(SDL_GetKeyName) ""; } mock(SDL_GetKeyFromName) SDL_KeyCode SDL_GetKeyFromName(const char* name) { mock_return(SDL_GetKeyFromName) 0; } mock(ini_gets) int ini_gets( const TCHAR *Section, const TCHAR *Key, const TCHAR *DefValue, char *Buffer, int BufferSize, const TCHAR *Filename ) { mock_return(ini_gets) 0; } mock(ini_getl) long ini_getl( const TCHAR *Section, const TCHAR *Key, long DefValue, const TCHAR *Filename ) { mock_return(ini_getl) DefValue; } spec("config") { describe("LoadConfig") { static IZ_Config config; after_each() { mock_reset(ini_getl); } after_each() { mock_reset(ini_gets); } after_each() { mock_reset(SDL_GetKeyFromName); } after_each() { mock_reset(SDL_GetKeyName); } after_each() { mock_reset(SDL_GetBasePath); } it("should load default config values") { IZ_LoadVideoConfig(&config); check( mock_calls(SDL_GetBasePath) > 0, "SDL_GetBasePath() not called." ); static const mock_call_count_t expected_calls_ini_getl = 3 // video params + 1 // input params + (12 * PLAYERS); // joystick controls check( mock_calls(ini_getl) == expected_calls_ini_getl, "Call count mismatch for ini_getl() (expected %u, received %u).", expected_calls_ini_getl, mock_calls(ini_getl) ); check( config.video.width == 640, "Default value for Video.Width is not loaded." ); check( config.video.height == 480, "Default value for Video.Height is not loaded." ); check( config.video.max_fps == 30, "Default value for Video.MaxFps is not loaded." ); check( config.input.axis_threshold == 8000, "Default value for Input.GamepadAxisThreshold is not loaded." ); static const mock_call_count_t expected_calls_ini_gets = (16 * PLAYERS); // keyboard controls check( mock_calls(ini_gets) == expected_calls_ini_gets, "Call count mismatch for ini_gets() (expected %u, received %u).", expected_calls_ini_gets, mock_calls(ini_gets) ); static const mock_call_count_t expected_calls_SDL_GetKeyFromName = (16 * PLAYERS); // keyboard controls check( mock_calls(SDL_GetKeyFromName) == expected_calls_SDL_GetKeyFromName, "Call count mismatch for SDL_GetKeyFromName() (expected %u, received %u).", expected_calls_SDL_GetKeyFromName, mock_calls(SDL_GetKeyFromName) ); static const mock_call_count_t expected_calls_SDL_GetKeyName = (16 * PLAYERS); // keyboard controls check( mock_calls(SDL_GetKeyName) == expected_calls_SDL_GetKeyName, "Call count mismatch for SDL_GetKeyName() (expected %u, received %u).", expected_calls_SDL_GetKeyName, mock_calls(SDL_GetKeyName) ); } } }