#include "bdd-for-c.h" #include "../../game/config/IZ_config.h" #define mock(X) static uint8_t calls_##X = 0; #define mock_return(X) calls_##X += 1; return #define mock_reset(X) calls_##X = 0 #define mock_calls(X) ((uint8_t) (calls_##X)) 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 char *Section, const char *Key, const char *DefValue, char *Buffer, int BufferSize, const char *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_LoadConfig(&config); check( mock_calls(SDL_GetBasePath) > 0, "SDL_GetBasePath() not called." ); static const int 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.gamepad_axis_threshold == 8000, "Default value for Input.GamepadAxisThreshold is not loaded." ); static const int 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 int 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 int 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) ); } } }