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.

136 lines
2.9 KiB

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