2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
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.
 
 
 
 
 
 

172 lines
4.1 KiB

  1. #include "../../test/IZ_test.h"
  2. #include "../../common/IZ_common.h"
  3. #include "../../../__mocks__/SDL_stdinc.mock.h"
  4. #include "IZ_list.h"
  5. IZ_ListFilterFunctionArgs(IZ_ListNode* __current_item_NodeExists) bool NodeExists(IZ_ListNode* node, u64 _index) {
  6. return *((u64*) node->value) == 42069;
  7. }
  8. IZ_ListFilterFunctionArgs(IZ_ListNode* __current_item_NodeExists2) bool NodeExists2(IZ_ListNode* node, u64 _index) {
  9. return *((u64*) node->value) == 69420;
  10. }
  11. IZ_ListFilterFunctionArgs(IZ_ListNode* __current_item_NodeDoesNotExist) bool NodeDoesNotExist(IZ_ListNode* node, u64 _index) {
  12. return *((u64*) node->value) == 55555;
  13. }
  14. spec("data") {
  15. describe("list") {
  16. describe("Initialize") {
  17. static IZ_List list;
  18. it("sets root to NULL") {
  19. IZ_ListInitialize(&list);
  20. check(list.root == NULL, "List not properly initialized.");
  21. }
  22. }
  23. describe("Teardown") {
  24. static IZ_List list;
  25. before_each() {
  26. static u64 value1 = 69420u;
  27. static u64 value2 = 42069u;
  28. static u64 value3 = 69069u;
  29. IZ_ListInitialize(&list);
  30. IZ_ListAppendNode(&list, &value1);
  31. IZ_ListAppendNode(&list, &value2);
  32. IZ_ListAppendNode(&list, &value3);
  33. }
  34. after_each() {
  35. mock_reset(SDL_free);
  36. }
  37. it("removes all nodes from the list") {
  38. mock_set_expected_calls(SDL_free, 3);
  39. IZ_ListTeardown(&list);
  40. check(
  41. mock_get_expected_calls(SDL_free) == mock_get_actual_calls(SDL_free),
  42. "Deallocator function call count mismatch."
  43. );
  44. }
  45. }
  46. describe("AppendNode") {
  47. static IZ_List list;
  48. static IZ_List list2;
  49. before_each() {
  50. IZ_ListInitialize(&list);
  51. }
  52. before_each() {
  53. IZ_ListInitialize(&list2);
  54. static u64 existing_value = 69420u;
  55. static IZ_ListNode existing_node = {
  56. .value = &existing_value,
  57. .next = NULL,
  58. };
  59. list2.root = &existing_node;
  60. list2.length = 1;
  61. }
  62. after_each() {
  63. mock_reset(SDL_malloc);
  64. }
  65. it("appends new node to empty list and sets it as root") {
  66. static u64 value = 69420u;
  67. IZ_ListAppendNode(&list, &value);
  68. check(*((u64*) list.root->value) == 69420u, "Node not properly appended.");
  69. check(
  70. mock_is_called(SDL_malloc),
  71. "Allocator function not called."
  72. );
  73. check(list.length == 1, "Length mismatch.");
  74. }
  75. it("appends new node to non-empty list") {
  76. static u64 value1 = 42069u;
  77. IZ_ListAppendNode(&list2, &value1);
  78. check(*((u64*) list2.root->next->value) == 42069u, "Node not properly appended.");
  79. check(
  80. mock_is_called(SDL_malloc),
  81. "Allocator function not called."
  82. );
  83. check(list2.length == 2, "Length mismatch.");
  84. }
  85. }
  86. describe("FindFirstNode") {
  87. static IZ_List list;
  88. static u64 value1 = 69420u;
  89. static u64 value2 = 42069u;
  90. before_each() {
  91. IZ_ListInitialize(&list);
  92. IZ_ListAppendNode(&list, &value1);
  93. IZ_ListAppendNode(&list, &value2);
  94. }
  95. it("retrieves first node satisfying the filter condition") {
  96. static IZ_ListNode* node;
  97. node = _IZ_ListFindFirstNode(&list, NodeExists);
  98. check(*((u64*) node->value) == 42069u, "Existing node not found.");
  99. }
  100. it("returns NULL when all nodes do not satisfy the filter condition") {
  101. static IZ_ListNode* node;
  102. node = _IZ_ListFindFirstNode(&list, NodeDoesNotExist);
  103. check(node == NULL, "Non-existing node found.");
  104. }
  105. }
  106. describe("DeleteFirstNode") {
  107. static IZ_List list;
  108. before_each() {
  109. static u64 value1 = 69420u;
  110. static u64 value2 = 42069u;
  111. static u64 value3 = 69069u;
  112. IZ_ListInitialize(&list);
  113. IZ_ListAppendNode(&list, &value1);
  114. IZ_ListAppendNode(&list, &value2);
  115. IZ_ListAppendNode(&list, &value3);
  116. }
  117. after_each() {
  118. mock_reset(SDL_free);
  119. }
  120. it("removes first node satisfying the filter condition") {
  121. _IZ_ListDeleteFirstNode(&list, NodeExists);
  122. check(
  123. mock_is_called(SDL_free),
  124. "Deallocator function not called."
  125. );
  126. check(
  127. _IZ_ListFindFirstNode(&list, NodeExists2),
  128. "Node supposed to be present in list is absent."
  129. );
  130. check(
  131. !_IZ_ListFindFirstNode(&list, NodeExists),
  132. "Deleted node still present in list."
  133. );
  134. check(list.length == 2, "Length mismatch.");
  135. }
  136. }
  137. }
  138. }