2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

375 líneas
11 KiB

  1. #include <SDL.h>
  2. #include <bdd-for-c.h>
  3. #include <stdinc/IZ_stdlib.mock.h>
  4. #include <common/IZ_common.h>
  5. #include <game/data/IZ_list.h>
  6. bool NodeExists(IZ_ListNode** node, u64 _index, IZ_List* list) {
  7. return *((u64*) (*node)->value) == 42069;
  8. }
  9. bool NodeExists2(IZ_ListNode** node, u64 _index, IZ_List* list) {
  10. return *((u64*) (*node)->value) == 69420;
  11. }
  12. bool NodeExists3(IZ_ListNode** node, u64 _index, IZ_List* list) {
  13. return *((u64*) (*node)->value) == 69069;
  14. }
  15. bool NodeDoesNotExist(IZ_ListNode** node, u64 _index, IZ_List* list) {
  16. return *((u64*) (*node)->value) == 55555;
  17. }
  18. bool NodeHasOddValue(IZ_ListNode** node, u64 _index, IZ_List* list) {
  19. return *((u64*) (*node)->value) % 2 == 1;
  20. }
  21. spec("data") {
  22. describe("list") {
  23. describe("Initialize") {
  24. static IZ_List list;
  25. after_each() {
  26. mock_mode(IZ_free, IZ_FREE_CALLS_UNTRACKED);
  27. IZ_ListTeardown(&list);
  28. }
  29. it("sets root to NULL") {
  30. IZ_ListInitialize(&list);
  31. check(
  32. list.root == NULL,
  33. "List not properly initialized. Root: %p", list.root
  34. );
  35. }
  36. }
  37. describe("Teardown") {
  38. static IZ_List list;
  39. before_each() {
  40. static u64 value1 = 69420u;
  41. static u64 value2 = 42069u;
  42. static u64 value3 = 69069u;
  43. IZ_ListInitialize(&list);
  44. IZ_ListAppendNode(&list, &value1, NULL);
  45. IZ_ListAppendNode(&list, &value2, NULL);
  46. IZ_ListAppendNode(&list, &value3, NULL);
  47. mock_mode(IZ_free, IZ_FREE_CALLS_TRACKED);
  48. }
  49. after_each() {
  50. mock_reset(IZ_free);
  51. }
  52. it("removes all nodes from the list") {
  53. mock_set_expected_calls(IZ_free, 3);
  54. IZ_ListTeardown(&list);
  55. unsigned int expected_calls = mock_get_expected_calls(IZ_free);
  56. unsigned int actual_calls = mock_get_actual_calls(IZ_free);
  57. check(
  58. expected_calls == actual_calls,
  59. "Deallocator function call count mismatch. Expected %u, got %u.", expected_calls, actual_calls
  60. );
  61. }
  62. }
  63. describe("AppendNode") {
  64. static IZ_List list;
  65. static IZ_List list2;
  66. before_each() {
  67. IZ_ListInitialize(&list);
  68. }
  69. before_each() {
  70. IZ_ListInitialize(&list2);
  71. static u64 existing_value = 69420u;
  72. static IZ_ListNode* existing_node;
  73. existing_node = IZ_malloc(sizeof(IZ_ListNode));
  74. existing_node->list = &list2;
  75. existing_node->previous = NULL;
  76. existing_node->value = &existing_value;
  77. existing_node->next = NULL;
  78. list2.root = existing_node;
  79. list2.length = 1;
  80. }
  81. after_each() {
  82. mock_reset(IZ_malloc);
  83. }
  84. after_each() {
  85. mock_mode(IZ_free, IZ_FREE_CALLS_UNTRACKED);
  86. IZ_ListTeardown(&list);
  87. }
  88. after_each() {
  89. mock_mode(IZ_free, IZ_FREE_CALLS_UNTRACKED);
  90. IZ_ListTeardown(&list2);
  91. }
  92. it("appends new node to empty list and sets it as root") {
  93. static u64 value = 69420u;
  94. static IZ_ListNode* check_inserted_node;
  95. IZ_ListAppendNode(&list, &value, &check_inserted_node);
  96. u64 added_value = *((u64*) list.root->value);
  97. check(added_value == 69420u, "Node not properly appended. Value: %u", added_value);
  98. check(*((u64*) check_inserted_node->value) == added_value, "Node value not properly set. Value: %u", added_value);
  99. check(
  100. mock_is_called(IZ_malloc),
  101. "Allocator function not called."
  102. );
  103. check(list.length == 1, "Length mismatch.");
  104. }
  105. it("appends new node to non-empty list") {
  106. static u64 value1 = 42069u;
  107. static IZ_ListNode* check_inserted_node;
  108. IZ_ListAppendNode(&list2, &value1, &check_inserted_node);
  109. check(*((u64*) check_inserted_node->value) == value1, "Node value not properly set. Value: %u", value1);
  110. check(*((u64*) list2.root->next->value) == 42069u, "Node not properly appended.");
  111. check(
  112. mock_is_called(IZ_malloc),
  113. "Allocator function not called."
  114. );
  115. check(list2.length == 2, "Length mismatch. Length: %u", list2.length);
  116. }
  117. }
  118. describe("FindFirstNode") {
  119. static IZ_List list;
  120. static u64 value1 = 69420u;
  121. static u64 value2 = 42069u;
  122. before_each() {
  123. IZ_ListInitialize(&list);
  124. IZ_ListAppendNode(&list, &value1, NULL);
  125. IZ_ListAppendNode(&list, &value2, NULL);
  126. }
  127. after_each() {
  128. mock_mode(IZ_free, IZ_FREE_CALLS_UNTRACKED);
  129. IZ_ListTeardown(&list);
  130. }
  131. it("retrieves first node satisfying the filter condition") {
  132. static IZ_ListNode* node;
  133. list.iterator = &list.root;
  134. IZ_ListFindFirstNode(&list, NodeExists, &node);
  135. check(*((u64*) node->value) == 42069u, "Existing node not found.");
  136. }
  137. it("returns NULL when all nodes do not satisfy the filter condition") {
  138. static IZ_ListNode* node;
  139. list.iterator = &list.root;
  140. IZ_ListFindFirstNode(&list, NodeDoesNotExist, &node);
  141. check(node == NULL, "Non-existing node found.");
  142. }
  143. }
  144. describe("DeleteNode") {
  145. static IZ_List list;
  146. before_each() {
  147. static u64 value1 = 69420u;
  148. static u64 value2 = 42069u;
  149. static u64 value3 = 69069u;
  150. IZ_ListInitialize(&list);
  151. IZ_ListAppendNode(&list, &value1, NULL);
  152. IZ_ListAppendNode(&list, &value2, NULL);
  153. IZ_ListAppendNode(&list, &value3, NULL);
  154. mock_mode(IZ_free, IZ_FREE_CALLS_TRACKED);
  155. }
  156. after_each() {
  157. mock_reset(IZ_free);
  158. }
  159. it("removes first node satisfying the filter condition") {
  160. list.iterator = &list.root;
  161. static IZ_ListNode* existing_node;
  162. static IZ_ListNode* check_node;
  163. IZ_ListFindFirstNode(&list, NodeExists, &existing_node);
  164. IZ_ListDeleteNode(existing_node);
  165. check(
  166. mock_is_called(IZ_free),
  167. "Deallocator function not called."
  168. );
  169. check_node = NULL;
  170. list.iterator = &list.root;
  171. IZ_ListFindFirstNode(&list, NodeExists2, &check_node);
  172. check(check_node, "Node supposed to be present in list is absent.");
  173. list.iterator = &list.root;
  174. check_node = NULL;
  175. IZ_ListFindFirstNode(&list, NodeExists, &check_node);
  176. check(!check_node, "Deleted node still present in list.");
  177. check(list.length == 2, "Length mismatch.");
  178. }
  179. }
  180. describe("FindAllNodes") {
  181. static IZ_List list;
  182. static IZ_List out;
  183. before_each() {
  184. static u64 value1 = 69420u;
  185. static u64 value2 = 42069u;
  186. static u64 value3 = 69069u;
  187. IZ_ListInitialize(&list);
  188. IZ_ListAppendNode(&list, &value1, NULL);
  189. IZ_ListAppendNode(&list, &value2, NULL);
  190. IZ_ListAppendNode(&list, &value3, NULL);
  191. mock_mode(IZ_free, IZ_FREE_CALLS_UNTRACKED);
  192. }
  193. before_each() {
  194. IZ_ListInitialize(&out);
  195. }
  196. after_each() {
  197. IZ_ListTeardown(&out);
  198. }
  199. after_each() {
  200. IZ_ListTeardown(&list);
  201. }
  202. it("finds all nodes satisfying the filter condition") {
  203. list.iterator = &list.root;
  204. IZ_ListFindAllNodes(&list, NodeHasOddValue, &out);
  205. check(out.length == 2, "Length mismatch. Length: %u", out.length);
  206. out.iterator = &out.root;
  207. static IZ_ListNode* check_node;
  208. check_node = NULL;
  209. IZ_ListFindFirstNode(&out, NodeExists, &check_node);
  210. check(check_node, "Node supposed to be present in list is absent.");
  211. out.iterator = &out.root;
  212. check_node = NULL;
  213. IZ_ListFindFirstNode(&out, NodeExists3, &check_node);
  214. check(check_node, "Node supposed to be present in list is absent.");
  215. out.iterator = &out.root;
  216. check_node = NULL;
  217. IZ_ListFindFirstNode(&out, NodeExists2, &check_node);
  218. check(!check_node, "Node not supposed to be present in list is present.");
  219. }
  220. }
  221. describe("InsertNodeAtIndex") {
  222. static IZ_List list;
  223. before_each() {
  224. static u64 value1 = 69420u;
  225. static u64 value2 = 42069u;
  226. static u64 value3 = 69069u;
  227. IZ_ListInitialize(&list);
  228. IZ_ListAppendNode(&list, &value1, NULL);
  229. IZ_ListAppendNode(&list, &value2, NULL);
  230. IZ_ListAppendNode(&list, &value3, NULL);
  231. mock_mode(IZ_free, IZ_FREE_CALLS_UNTRACKED);
  232. }
  233. after_each() {
  234. IZ_ListTeardown(&list);
  235. }
  236. it("inserts node at the beginning of the list") {
  237. static u64 value = 1337u;
  238. static IZ_ListNode* check_node;
  239. IZ_ListInsertNodeAtIndex(&list, &value, 0, &check_node);
  240. check(*((u64*) check_node->value) == value, "Incorrect value of inserted node.");
  241. static IZ_ListNode* check_other_node;
  242. list.iterator = &list.root;
  243. check_other_node = NULL;
  244. IZ_ListFindFirstNode(&list, NodeExists, &check_other_node);
  245. check(check_other_node, "Node supposed to be present in list is absent.");
  246. list.iterator = &list.root;
  247. check_other_node = NULL;
  248. IZ_ListFindFirstNode(&list, NodeExists2, &check_other_node);
  249. check(check_other_node, "Node supposed to be present in list is absent.");
  250. list.iterator = &list.root;
  251. check_other_node = NULL;
  252. IZ_ListFindFirstNode(&list, NodeExists3, &check_other_node);
  253. check(check_other_node, "Node supposed to be present in list is absent.");
  254. check(list.length == 4, "Length mismatch.");
  255. //IZ_ListPrintNodeValues(&list);
  256. }
  257. it("inserts node at the end of the list") {
  258. static u64 value = 1337u;
  259. static IZ_ListNode* check_node;
  260. IZ_ListInsertNodeAtIndex(&list, &value, 3, &check_node);
  261. check(*((u64*) check_node->value) == value, "Incorrect value of inserted node.");
  262. static IZ_ListNode* check_other_node;
  263. list.iterator = &list.root;
  264. check_other_node = NULL;
  265. IZ_ListFindFirstNode(&list, NodeExists, &check_other_node);
  266. check(check_other_node, "Node supposed to be present in list is absent.");
  267. list.iterator = &list.root;
  268. check_other_node = NULL;
  269. IZ_ListFindFirstNode(&list, NodeExists2, &check_other_node);
  270. check(check_other_node, "Node supposed to be present in list is absent.");
  271. list.iterator = &list.root;
  272. check_other_node = NULL;
  273. IZ_ListFindFirstNode(&list, NodeExists3, &check_other_node);
  274. check(check_other_node, "Node supposed to be present in list is absent.");
  275. check(list.length == 4, "Length mismatch.");
  276. //IZ_ListPrintNodeValues(&list);
  277. }
  278. it("inserts node in the middle of the list") {
  279. static u64 value = 1337u;
  280. static IZ_ListNode* check_node;
  281. IZ_ListInsertNodeAtIndex(&list, &value, 1, &check_node);
  282. check(*((u64*) check_node->value) == value, "Incorrect value of inserted node.");
  283. static IZ_ListNode* check_other_node;
  284. list.iterator = &list.root;
  285. check_other_node = NULL;
  286. IZ_ListFindFirstNode(&list, NodeExists, &check_other_node);
  287. check(check_other_node, "Node supposed to be present in list is absent.");
  288. list.iterator = &list.root;
  289. check_other_node = NULL;
  290. IZ_ListFindFirstNode(&list, NodeExists2, &check_other_node);
  291. check(check_other_node, "Node supposed to be present in list is absent.");
  292. list.iterator = &list.root;
  293. check_other_node = NULL;
  294. IZ_ListFindFirstNode(&list, NodeExists3, &check_other_node);
  295. check(check_other_node, "Node supposed to be present in list is absent.");
  296. check(list.length == 4, "Length mismatch.");
  297. //IZ_ListPrintNodeValues(&list);
  298. }
  299. }
  300. }
  301. }