Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Filename: /workspaces/our_rpg/tests/library/ECS/entity_component_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 "entity.h" |
12 |
|
|
#include "component.h" |
13 |
|
|
|
14 |
|
✗ |
Test(entity_component, test_entity_constructor) |
15 |
|
|
{ |
16 |
|
|
entity_t entity; |
17 |
|
|
|
18 |
|
✗ |
cr_assert_eq(entity_constructor(&entity), 0); |
19 |
|
✗ |
entity_destructor(&entity); |
20 |
|
|
} |
21 |
|
|
|
22 |
|
✗ |
Test(entity_component, test_entity_entity_add_component_success) |
23 |
|
|
{ |
24 |
|
|
entity_t entity; |
25 |
|
✗ |
component_t component = {.type = 0, .data = 0}; |
26 |
|
|
|
27 |
|
✗ |
entity_constructor(&entity); |
28 |
|
✗ |
cr_assert_eq(entity_add_component(&entity, &component), 0); |
29 |
|
✗ |
entity_destructor(&entity); |
30 |
|
|
} |
31 |
|
|
|
32 |
|
✗ |
Test(entity_component, test_entity_entity_add_component_failure) |
33 |
|
|
{ |
34 |
|
|
entity_t entity; |
35 |
|
✗ |
component_t component = {.type = 0, .data = 0}; |
36 |
|
|
|
37 |
|
✗ |
entity_constructor(&entity); |
38 |
|
✗ |
entity_add_component(&entity, &component); |
39 |
|
✗ |
cr_assert_eq(entity_add_component(&entity, &component), -1); |
40 |
|
✗ |
entity_destructor(&entity); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
✗ |
Test(entity_component, test_entity_entity_remove_component_success) |
44 |
|
|
{ |
45 |
|
|
entity_t entity; |
46 |
|
✗ |
component_t component = {.type = 0, .data = 0}; |
47 |
|
|
|
48 |
|
✗ |
entity_constructor(&entity); |
49 |
|
✗ |
entity_add_component(&entity, &component); |
50 |
|
✗ |
cr_assert_eq(entity_remove_component(&entity, &component), 0); |
51 |
|
✗ |
entity_destructor(&entity); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
✗ |
Test(entity_component, test_entity_entity_remove_component_failure) |
55 |
|
|
{ |
56 |
|
|
entity_t entity; |
57 |
|
✗ |
component_t component = {.type = 0, .data = 0}; |
58 |
|
|
|
59 |
|
✗ |
entity_constructor(&entity); |
60 |
|
✗ |
entity_add_component(&entity, &component); |
61 |
|
✗ |
entity_remove_component(&entity, &component); |
62 |
|
✗ |
cr_assert_eq(entity_remove_component(&entity, &component), -1); |
63 |
|
✗ |
entity_destructor(&entity); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
✗ |
Test(entity_contains_component, test_entity_entity_contains_component_success) |
67 |
|
|
{ |
68 |
|
|
entity_t entity; |
69 |
|
✗ |
component_t component = {.type = 0, .data = 0}; |
70 |
|
|
|
71 |
|
✗ |
entity_constructor(&entity); |
72 |
|
✗ |
entity_add_component(&entity, &component); |
73 |
|
✗ |
cr_assert_eq(entity_contains_component(&entity, &component), true); |
74 |
|
✗ |
entity_destructor(&entity); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
✗ |
Test(entity_contains_component, test_entity_entity_contains_component_failure) |
78 |
|
|
{ |
79 |
|
|
entity_t entity; |
80 |
|
|
component_t component; |
81 |
|
|
|
82 |
|
✗ |
entity_constructor(&entity); |
83 |
|
✗ |
entity_add_component(&entity, &component); |
84 |
|
✗ |
component.type = 1; |
85 |
|
✗ |
cr_assert_eq(entity_contains_component(&entity, &component), false); |
86 |
|
✗ |
entity_destructor(&entity); |
87 |
|
|
} |
88 |
|
|
|
89 |
|
✗ |
Test(entity_get_component, test_entity_entity_get_component_success) |
90 |
|
|
{ |
91 |
|
|
entity_t entity; |
92 |
|
✗ |
component_t component = {.type = 0, .data = 0}; |
93 |
|
|
|
94 |
|
✗ |
entity_constructor(&entity); |
95 |
|
✗ |
entity_add_component(&entity, &component); |
96 |
|
✗ |
cr_assert_neq(entity_get_component(&entity, component.type), NULL); |
97 |
|
✗ |
entity_destructor(&entity); |
98 |
|
|
} |
99 |
|
|
|
100 |
|
✗ |
Test(entity_get_component, test_entity_entity_get_component_failure) |
101 |
|
|
{ |
102 |
|
|
entity_t entity; |
103 |
|
✗ |
component_t component = {.type = 0, .data = 0}; |
104 |
|
|
|
105 |
|
✗ |
entity_constructor(&entity); |
106 |
|
✗ |
entity_add_component(&entity, &component); |
107 |
|
✗ |
component.type = 1; |
108 |
|
✗ |
cr_assert_eq(entity_get_component(&entity, component.type), NULL); |
109 |
|
✗ |
entity_destructor(&entity); |
110 |
|
|
} |
111 |
|
|
|
112 |
|
✗ |
Test(entity_get_component, test_entity_entity_get_component_without_component) |
113 |
|
|
{ |
114 |
|
|
entity_t entity; |
115 |
|
|
component_t component = {.type = 0, .data = 0}; |
116 |
|
|
|
117 |
|
✗ |
entity_constructor(&entity); |
118 |
|
✗ |
cr_assert_eq(entity_get_component(&entity, component.type), NULL); |
119 |
|
✗ |
entity_destructor(&entity); |
120 |
|
|
} |
121 |
|
|
|