| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/* |
| 2 |
|
|
* Filename: /workspaces/our_rpg/tests/library/ECS/world_entity_tests.c |
| 3 |
|
|
* Path: /workspaces/our_rpg/tests/library/ECS |
| 4 |
|
|
* Created Date: Sunday, January 15th 2023, 3:59:16 pm |
| 5 |
|
|
* Author: osvegn |
| 6 |
|
|
* |
| 7 |
|
|
* Copyright (c) 2023 our_rpg |
| 8 |
|
|
*/ |
| 9 |
|
|
|
| 10 |
|
|
#include <criterion/criterion.h> |
| 11 |
|
|
#include "world.h" |
| 12 |
|
|
#include "world_entity.h" |
| 13 |
|
|
|
| 14 |
|
✗ |
Test(test, test) |
| 15 |
|
|
{ |
| 16 |
|
✗ |
cr_assert_eq(1, 1); |
| 17 |
|
|
} |
| 18 |
|
|
|
| 19 |
|
✗ |
Test(world_world_add_entity, world_world_add_entity) |
| 20 |
|
|
{ |
| 21 |
|
|
world_t world; |
| 22 |
|
|
entity_t entity; |
| 23 |
|
|
|
| 24 |
|
✗ |
entity.id = 0; |
| 25 |
|
✗ |
vector_constructor(&world.entity_list, sizeof(int), 0); |
| 26 |
|
✗ |
cr_assert_eq(world_add_entity(&world, &entity), 0); |
| 27 |
|
✗ |
cr_assert_eq(world.entity_list.size(&world.entity_list), 1); |
| 28 |
|
|
} |
| 29 |
|
|
|
| 30 |
|
✗ |
Test(world_world_add_entity, world_world_add_entity_failure) |
| 31 |
|
|
{ |
| 32 |
|
|
world_t world; |
| 33 |
|
|
entity_t entity; |
| 34 |
|
|
|
| 35 |
|
✗ |
entity.id = 0; |
| 36 |
|
✗ |
vector_constructor(&world.entity_list, sizeof(int), 0); |
| 37 |
|
✗ |
cr_assert_eq(world_add_entity(&world, &entity), 0); |
| 38 |
|
✗ |
cr_assert_eq(world_add_entity(&world, &entity), -1); |
| 39 |
|
✗ |
cr_assert_eq(world.entity_list.size(&world.entity_list), 1); |
| 40 |
|
|
} |
| 41 |
|
|
|
| 42 |
|
✗ |
Test(world_world_add_entity, world_world_add_entity_success_with_two_elements) |
| 43 |
|
|
{ |
| 44 |
|
|
world_t world; |
| 45 |
|
|
entity_t entity; |
| 46 |
|
|
|
| 47 |
|
✗ |
entity.id = 0; |
| 48 |
|
✗ |
vector_constructor(&world.entity_list, sizeof(int), 0); |
| 49 |
|
✗ |
cr_assert_eq(world_add_entity(&world, &entity), 0); |
| 50 |
|
✗ |
entity.id = 1; |
| 51 |
|
✗ |
cr_assert_eq(world_add_entity(&world, &entity), 0); |
| 52 |
|
✗ |
cr_assert_eq(world.entity_list.size(&world.entity_list), 2); |
| 53 |
|
|
} |
| 54 |
|
|
|
| 55 |
|
✗ |
Test(world_world_add_entity, world_world_remove_entity) |
| 56 |
|
|
{ |
| 57 |
|
|
world_t world; |
| 58 |
|
|
entity_t entity; |
| 59 |
|
|
|
| 60 |
|
✗ |
entity.id = 0; |
| 61 |
|
✗ |
vector_constructor(&world.entity_list, sizeof(int), 0); |
| 62 |
|
✗ |
cr_assert_eq(world_add_entity(&world, &entity), 0); |
| 63 |
|
✗ |
entity.id = 1; |
| 64 |
|
✗ |
cr_assert_eq(world_add_entity(&world, &entity), 0); |
| 65 |
|
✗ |
cr_assert_eq(world_remove_entity(&world, &entity), 0); |
| 66 |
|
✗ |
cr_assert_eq(world.entity_list.size(&world.entity_list), 1); |
| 67 |
|
|
} |
| 68 |
|
|
|
| 69 |
|
✗ |
Test(world_world_add_entity, world_world_remove_entity_failure) |
| 70 |
|
|
{ |
| 71 |
|
|
world_t world; |
| 72 |
|
|
entity_t entity; |
| 73 |
|
|
|
| 74 |
|
✗ |
entity.id = 0; |
| 75 |
|
✗ |
vector_constructor(&world.entity_list, sizeof(int), 0); |
| 76 |
|
✗ |
cr_assert_eq(world_add_entity(&world, &entity), 0); |
| 77 |
|
✗ |
entity.id = 1; |
| 78 |
|
✗ |
cr_assert_eq(world_add_entity(&world, &entity), 0); |
| 79 |
|
✗ |
cr_assert_eq(world_remove_entity(&world, &entity), 0); |
| 80 |
|
✗ |
cr_assert_eq(world_remove_entity(&world, &entity), -1); |
| 81 |
|
✗ |
cr_assert_eq(world.entity_list.size(&world.entity_list), 1); |
| 82 |
|
|
} |
| 83 |
|
|
|
| 84 |
|
✗ |
Test(world_world_contains_entity, world_world_contains_entity_success) |
| 85 |
|
|
{ |
| 86 |
|
|
world_t world; |
| 87 |
|
|
entity_t entity; |
| 88 |
|
|
|
| 89 |
|
✗ |
entity.id = 0; |
| 90 |
|
✗ |
world_constructor(&world, stdout); |
| 91 |
|
✗ |
world_add_entity(&world, &entity); |
| 92 |
|
✗ |
cr_assert_eq(world_contains_entity(&world, &entity), true); |
| 93 |
|
|
} |
| 94 |
|
|
|
| 95 |
|
✗ |
Test(world_world_contains_entity, world_world_contains_entity_failure) |
| 96 |
|
|
{ |
| 97 |
|
|
world_t world; |
| 98 |
|
|
entity_t entity; |
| 99 |
|
|
|
| 100 |
|
✗ |
entity.id = 0; |
| 101 |
|
✗ |
world_constructor(&world, stdout); |
| 102 |
|
✗ |
cr_assert_eq(world_contains_entity(&world, &entity), false); |
| 103 |
|
|
} |
| 104 |
|
|
|
| 105 |
|
✗ |
Test(world_world_join_entities, world_world_join_entities_1) |
| 106 |
|
|
{ |
| 107 |
|
|
world_t world; |
| 108 |
|
|
entity_t entity; |
| 109 |
|
|
vector_t vector; |
| 110 |
|
✗ |
component_t component = {.type=1, .data=0}; |
| 111 |
|
|
|
| 112 |
|
✗ |
world_constructor(&world, stdout); |
| 113 |
|
✗ |
entity_constructor(&entity); |
| 114 |
|
✗ |
entity_add_component(&entity, &component); |
| 115 |
|
✗ |
world_add_entity(&world, &entity); |
| 116 |
|
✗ |
cr_assert_eq(world_join_entities(&world, &vector, 1, 1), 1); |
| 117 |
|
|
} |
| 118 |
|
|
|
| 119 |
|
✗ |
Test(world_world_join_entities, world_world_join_entities_2) |
| 120 |
|
|
{ |
| 121 |
|
|
world_t world; |
| 122 |
|
|
vector_t vector; |
| 123 |
|
|
|
| 124 |
|
✗ |
world_constructor(&world, stdout); |
| 125 |
|
✗ |
cr_assert_eq(world_join_entities(&world, &vector, 0), -1); |
| 126 |
|
|
} |
| 127 |
|
|
|
| 128 |
|
✗ |
Test(world_world_join_entities, world_world_join_entities_3) |
| 129 |
|
|
{ |
| 130 |
|
|
world_t world; |
| 131 |
|
|
vector_t vector; |
| 132 |
|
|
entity_t entity; |
| 133 |
|
|
int expected_value = 2; |
| 134 |
|
✗ |
component_t component = {.type=1, .data=0}; |
| 135 |
|
|
|
| 136 |
|
✗ |
world_constructor(&world, stdout); |
| 137 |
|
✗ |
entity_constructor(&entity); |
| 138 |
|
✗ |
entity_add_component(&entity, &component); |
| 139 |
|
✗ |
world_add_entity(&world, &entity); |
| 140 |
|
✗ |
entity_constructor(&entity); |
| 141 |
|
✗ |
entity_add_component(&entity, &component); |
| 142 |
|
✗ |
world_add_entity(&world, &entity); |
| 143 |
|
✗ |
cr_assert_eq(world_join_entities(&world, &vector, 1, 1), expected_value); |
| 144 |
|
|
} |
| 145 |
|
|
|
| 146 |
|
✗ |
Test(world_world_join_entities, world_world_join_entities_4) |
| 147 |
|
|
{ |
| 148 |
|
|
world_t world; |
| 149 |
|
|
vector_t vector; |
| 150 |
|
|
entity_t entity; |
| 151 |
|
✗ |
component_t component = {.type=1, .data=0}; |
| 152 |
|
|
|
| 153 |
|
✗ |
world_constructor(&world, stdout); |
| 154 |
|
✗ |
entity_constructor(&entity); |
| 155 |
|
✗ |
entity_add_component(&entity, &component); |
| 156 |
|
✗ |
world_add_entity(&world, &entity); |
| 157 |
|
✗ |
entity_constructor(&entity); |
| 158 |
|
✗ |
component.type = 2; |
| 159 |
|
✗ |
entity_add_component(&entity, &component); |
| 160 |
|
✗ |
world_add_entity(&world, &entity); |
| 161 |
|
✗ |
cr_assert_eq(world_join_entities(&world, &vector, 2, 1, 2), 0); |
| 162 |
|
|
} |
| 163 |
|
|
|
| 164 |
|
✗ |
Test(world_world_join_entities, world_world_join_entities_5) |
| 165 |
|
|
{ |
| 166 |
|
|
world_t world; |
| 167 |
|
|
vector_t vector; |
| 168 |
|
|
entity_t entity; |
| 169 |
|
✗ |
component_t component = {.type=1, .data=0}; |
| 170 |
|
|
|
| 171 |
|
✗ |
world_constructor(&world, stdout); |
| 172 |
|
✗ |
entity_constructor(&entity); |
| 173 |
|
✗ |
entity_add_component(&entity, &component); |
| 174 |
|
✗ |
component.type = 2; |
| 175 |
|
✗ |
entity_add_component(&entity, &component); |
| 176 |
|
✗ |
world_add_entity(&world, &entity); |
| 177 |
|
✗ |
cr_assert_eq(world_join_entities(&world, &vector, 2, 1, 2), 1); |
| 178 |
|
|
} |
| 179 |
|
|
|
| 180 |
|
✗ |
Test(world_world_join_entities, world_world_join_entities_6) |
| 181 |
|
|
{ |
| 182 |
|
|
world_t world; |
| 183 |
|
|
vector_t vector; |
| 184 |
|
|
entity_t entity; |
| 185 |
|
|
vector_t *components; |
| 186 |
|
✗ |
component_t component = {.type=1, .data=0}; |
| 187 |
|
|
|
| 188 |
|
✗ |
world_constructor(&world, stdout); |
| 189 |
|
✗ |
entity_constructor(&entity); |
| 190 |
|
✗ |
entity_add_component(&entity, &component); |
| 191 |
|
✗ |
world_add_entity(&world, &entity); |
| 192 |
|
✗ |
world_join_entities(&world, &vector, 1, 1); |
| 193 |
|
✗ |
components = &(*(entity_t **)vector.at(&vector, 0))->components; |
| 194 |
|
✗ |
((component_t *)components->at(components, 0))->data = (void *)1; |
| 195 |
|
✗ |
cr_assert_eq(((component_t *)entity.components.at(&entity.components, 0))->data, 1); |
| 196 |
|
|
} |
| 197 |
|
|
|
| 198 |
|
✗ |
Test(world_world_join_entities, world_world_join_entities_7) |
| 199 |
|
|
{ |
| 200 |
|
|
world_t world; |
| 201 |
|
|
vector_t vector; |
| 202 |
|
|
entity_t entity; |
| 203 |
|
|
vector_t *components; |
| 204 |
|
✗ |
component_t component = {.type=1, .data=0}; |
| 205 |
|
|
|
| 206 |
|
✗ |
world_constructor(&world, stdout); |
| 207 |
|
✗ |
entity_constructor(&entity); |
| 208 |
|
✗ |
entity_add_component(&entity, &component); |
| 209 |
|
✗ |
world_add_entity(&world, &entity); |
| 210 |
|
✗ |
world_join_entities(&world, &vector, 1, 1); |
| 211 |
|
✗ |
component.type = 2; |
| 212 |
|
✗ |
entity_add_component(*(entity_t **)vector.at(&vector, 0), &component); |
| 213 |
|
✗ |
entity_t *ptr = world_get_entity_by_id(&world, 0); |
| 214 |
|
✗ |
cr_assert_eq(ptr->components.size(&ptr->components), 2); |
| 215 |
|
✗ |
components = &(*(entity_t **)vector.at(&vector, 0))->components; |
| 216 |
|
✗ |
cr_assert_eq(components->size(components), 2); |
| 217 |
|
|
} |
| 218 |
|
|
|