Starter project for SDL2.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IZ_config.c 3.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "bdd-for-c.h"
  2. #include "../../game/config/IZ_config.h"
  3. #define mock_call_count_t uint8_t
  4. #define mock(X) static mock_call_count_t calls_##X = 0;
  5. #define mock_return(X) calls_##X += 1; return
  6. #define mock_reset(X) calls_##X = 0
  7. #define mock_calls(X) ((mock_call_count_t) (calls_##X))
  8. mock(SDL_GetBasePath) char* SDL_GetBasePath() {
  9. mock_return(SDL_GetBasePath) "";
  10. }
  11. mock(SDL_GetKeyName) const char* SDL_GetKeyName (SDL_KeyCode code) {
  12. mock_return(SDL_GetKeyName) "";
  13. }
  14. mock(SDL_GetKeyFromName) SDL_KeyCode SDL_GetKeyFromName(const char* name) {
  15. mock_return(SDL_GetKeyFromName) 0;
  16. }
  17. mock(ini_gets) int ini_gets(
  18. const TCHAR *Section,
  19. const TCHAR *Key,
  20. const TCHAR *DefValue,
  21. char *Buffer,
  22. int BufferSize,
  23. const TCHAR *Filename
  24. ) {
  25. mock_return(ini_gets) 0;
  26. }
  27. mock(ini_getl) long ini_getl(
  28. const TCHAR *Section,
  29. const TCHAR *Key,
  30. long DefValue,
  31. const TCHAR *Filename
  32. ) {
  33. mock_return(ini_getl) DefValue;
  34. }
  35. spec("config") {
  36. describe("LoadConfig") {
  37. static IZ_Config config;
  38. after_each() {
  39. mock_reset(ini_getl);
  40. }
  41. after_each() {
  42. mock_reset(ini_gets);
  43. }
  44. after_each() {
  45. mock_reset(SDL_GetKeyFromName);
  46. }
  47. after_each() {
  48. mock_reset(SDL_GetKeyName);
  49. }
  50. after_each() {
  51. mock_reset(SDL_GetBasePath);
  52. }
  53. it("should load default config values") {
  54. IZ_LoadConfig(&config);
  55. check(
  56. mock_calls(SDL_GetBasePath) > 0,
  57. "SDL_GetBasePath() not called."
  58. );
  59. static const mock_call_count_t expected_calls_ini_getl =
  60. 3 // video params
  61. + 1 // input params
  62. + (12 * PLAYERS); // joystick controls
  63. check(
  64. mock_calls(ini_getl) == expected_calls_ini_getl,
  65. "Call count mismatch for ini_getl() (expected %u, received %u).",
  66. expected_calls_ini_getl,
  67. mock_calls(ini_getl)
  68. );
  69. check(
  70. config.video.width == 640,
  71. "Default value for Video.Width is not loaded."
  72. );
  73. check(
  74. config.video.height == 480,
  75. "Default value for Video.Height is not loaded."
  76. );
  77. check(
  78. config.video.max_fps == 30,
  79. "Default value for Video.MaxFps is not loaded."
  80. );
  81. check(
  82. config.input.gamepad_axis_threshold == 8000,
  83. "Default value for Input.GamepadAxisThreshold is not loaded."
  84. );
  85. static const mock_call_count_t expected_calls_ini_gets =
  86. (16 * PLAYERS); // keyboard controls
  87. check(
  88. mock_calls(ini_gets) == expected_calls_ini_gets,
  89. "Call count mismatch for ini_gets() (expected %u, received %u).",
  90. expected_calls_ini_gets,
  91. mock_calls(ini_gets)
  92. );
  93. static const mock_call_count_t expected_calls_SDL_GetKeyFromName =
  94. (16 * PLAYERS); // keyboard controls
  95. check(
  96. mock_calls(SDL_GetKeyFromName) == expected_calls_SDL_GetKeyFromName,
  97. "Call count mismatch for SDL_GetKeyFromName() (expected %u, received %u).",
  98. expected_calls_SDL_GetKeyFromName,
  99. mock_calls(SDL_GetKeyFromName)
  100. );
  101. static const mock_call_count_t expected_calls_SDL_GetKeyName =
  102. (16 * PLAYERS); // keyboard controls
  103. check(
  104. mock_calls(SDL_GetKeyName) == expected_calls_SDL_GetKeyName,
  105. "Call count mismatch for SDL_GetKeyName() (expected %u, received %u).",
  106. expected_calls_SDL_GetKeyName,
  107. mock_calls(SDL_GetKeyName)
  108. );
  109. }
  110. }
  111. }