GCC Code Coverage Report


Directory: ./
File: submodules/ECS/tests/library/ECS/world_resource_tests.c
Date: 2023-09-29 04:53:15
Exec Total Coverage
Lines: 0 92 0.0%
Branches: 0 340 0.0%

Line Branch Exec Source
1 /*
2 * Filename: /workspaces/our_rpg/tests/library/ECS/world_resource_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_resource.h"
13
14 Test(world_world_add_resource, world_world_add_resource)
15 {
16 world_t world;
17 resource_t resource;
18
19 resource.type = 0;
20 vector_constructor(&world.resource_list, sizeof(int), 0);
21 cr_assert_eq(world_add_resource(&world, &resource), 0);
22 cr_assert_eq(world.resource_list.size(&world.resource_list), 1);
23 }
24
25 Test(world_world_add_resource, world_world_add_resource_failure)
26 {
27 world_t world;
28 resource_t resource;
29
30 resource.type = 0;
31 vector_constructor(&world.resource_list, sizeof(int), 0);
32 cr_assert_eq(world_add_resource(&world, &resource), 0);
33 cr_assert_eq(world_add_resource(&world, &resource), -1);
34 cr_assert_eq(world.resource_list.size(&world.resource_list), 1);
35 }
36
37 Test(world_world_add_resource, world_world_add_resource_success_with_two_elements)
38 {
39 world_t world;
40 resource_t resource;
41
42 resource.type = 0;
43 vector_constructor(&world.resource_list, sizeof(int), 0);
44 cr_assert_eq(world_add_resource(&world, &resource), 0);
45 resource.type = 1;
46 cr_assert_eq(world_add_resource(&world, &resource), 0);
47 cr_assert_eq(world.resource_list.size(&world.resource_list), 2);
48 }
49
50 Test(world_world_remove_resource, world_world_remove_resource)
51 {
52 world_t world;
53 resource_t resource;
54
55 resource.type = 0;
56 vector_constructor(&world.resource_list, sizeof(int), 0);
57 cr_assert_eq(world_add_resource(&world, &resource), 0);
58 resource.type = 1;
59 cr_assert_eq(world_add_resource(&world, &resource), 0);
60 cr_assert_eq(world_remove_resource(&world, &resource), 0);
61 cr_assert_eq(world.resource_list.size(&world.resource_list), 1);
62 }
63
64 Test(world_world_remove_resource, world_world_remove_resource_failure)
65 {
66 world_t world;
67 resource_t resource;
68
69 resource.type = 0;
70 vector_constructor(&world.resource_list, sizeof(int), 0);
71 cr_assert_eq(world_add_resource(&world, &resource), 0);
72 resource.type = 1;
73 cr_assert_eq(world_add_resource(&world, &resource), 0);
74 cr_assert_eq(world_remove_resource(&world, &resource), 0);
75 cr_assert_eq(world_remove_resource(&world, &resource), -1);
76 cr_assert_eq(world.resource_list.size(&world.resource_list), 1);
77 }
78
79 Test(world_world_remove_resource, world_world_remove_resource_by_type)
80 {
81 world_t world;
82 resource_t resource;
83
84 resource.type = 0;
85 vector_constructor(&world.resource_list, sizeof(int), 0);
86 cr_assert_eq(world_add_resource(&world, &resource), 0);
87 resource.type = 1;
88 cr_assert_eq(world_add_resource(&world, &resource), 0);
89 cr_assert_eq(world_remove_resource_by_type(&world, 0), 0);
90 cr_assert_eq(world.resource_list.size(&world.resource_list), 1);
91 }
92
93 Test(world_world_remove_resource, world_world_remove_resource_by_type_failure)
94 {
95 world_t world;
96 resource_t resource;
97
98 resource.type = 0;
99 vector_constructor(&world.resource_list, sizeof(int), 0);
100 cr_assert_eq(world_add_resource(&world, &resource), 0);
101 resource.type = 1;
102 cr_assert_eq(world_add_resource(&world, &resource), 0);
103 cr_assert_eq(world_remove_resource_by_type(&world, 0), 0);
104 cr_assert_eq(world_remove_resource_by_type(&world, 0), -1);
105 cr_assert_eq(world.resource_list.size(&world.resource_list), 1);
106 }
107
108 Test(world_world_contains_resource, world_world_contains_resource_success)
109 {
110 world_t world;
111 resource_t resource;
112
113 resource.type = 0;
114 world_constructor(&world, stdout);
115 world_add_resource(&world, &resource);
116 cr_assert_eq(world_contains_resource(&world, &resource), true);
117 }
118
119 Test(world_world_contains_resource, world_world_contains_resource_failure)
120 {
121 world_t world;
122 resource_t resource;
123
124 resource.type = 0;
125 world_constructor(&world, stdout);
126 cr_assert_eq(world_contains_resource(&world, &resource), false);
127 }
128
129 Test(world_world_contains_resource, world_world_contains_resource_by_type_success)
130 {
131 world_t world;
132 resource_t resource;
133
134 resource.type = 0;
135 world_constructor(&world, stdout);
136 world_add_resource(&world, &resource);
137 cr_assert_eq(world_contains_resource_by_type(&world, 0), true);
138 }
139
140 Test(world_world_contains_resource, world_world_contains_resource_by_type_failure)
141 {
142 world_t world;
143 resource_t resource;
144
145 resource.type = 0;
146 world_constructor(&world, stdout);
147 world_add_resource(&world, &resource);
148 cr_assert_eq(world_contains_resource_by_type(&world, 1), false);
149 }
150
151 Test(world_world_get_resource, world_world_get_resource_success)
152 {
153 world_t world;
154 resource_t resource;
155
156 resource.type = 0;
157 world_constructor(&world, stdout);
158 world_add_resource(&world, &resource);
159 cr_assert_neq(world_get_resource(&world, &resource), 0);
160 }
161
162 Test(world_world_get_resource, world_world_get_resource_failure)
163 {
164 world_t world;
165 resource_t resource;
166
167 resource.type = 0;
168 world_constructor(&world, stdout);
169 world_add_resource(&world, &resource);
170 resource.type = 1;
171 cr_assert_eq(world_get_resource(&world, &resource), 0);
172 }
173
174 Test(world_world_get_resource, world_world_get_resource_by_id_success)
175 {
176 world_t world;
177 resource_t resource;
178
179 resource.type = 0;
180 world_constructor(&world, stdout);
181 world_add_resource(&world, &resource);
182 cr_assert_neq(world_get_resource_by_type(&world, 0), 0);
183 }
184
185 Test(world_world_get_resource, world_world_get_resource_by_id_failure)
186 {
187 world_t world;
188 resource_t resource;
189
190 resource.type = 0;
191 world_constructor(&world, stdout);
192 world_add_resource(&world, &resource);
193 cr_assert_eq(world_get_resource_by_type(&world, 1), 0);
194 }
195