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.

134 lines
3.0 KiB

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