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.

127 lines
2.9 KiB

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