Restore ECS
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "dusktest.h"
|
||||
#include "util/memory.h"
|
||||
#include "entity/entitymanager.h"
|
||||
#include "entity/component/display/entityposition.h"
|
||||
|
||||
static void test_entityManagerAddIsolatesEntities(void **state) {
|
||||
entitymanager_t mgr;
|
||||
entityManagerInit(&mgr);
|
||||
|
||||
entityid_t a = entityManagerAdd(&mgr);
|
||||
entityid_t b = entityManagerAdd(&mgr);
|
||||
|
||||
assert_true(a != ENTITY_ID_INVALID);
|
||||
assert_true(b != ENTITY_ID_INVALID);
|
||||
assert_true(a != b);
|
||||
|
||||
entityManagerDispose(&mgr);
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_entityManagerFullAsserts(void **state) {
|
||||
entitymanager_t mgr;
|
||||
entityManagerInit(&mgr);
|
||||
|
||||
for(entityid_t i = 0; i < ENTITY_COUNT_MAX; i++) {
|
||||
assert_true(entityManagerAdd(&mgr) != ENTITY_ID_INVALID);
|
||||
}
|
||||
|
||||
expect_assert_failure(entityManagerAdd(&mgr));
|
||||
|
||||
entityManagerDispose(&mgr);
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_entityAddGetDisposeComponent(void **state) {
|
||||
entitymanager_t mgr;
|
||||
entityManagerInit(&mgr);
|
||||
|
||||
entityid_t entity = entityManagerAdd(&mgr);
|
||||
assert_int_equal(
|
||||
entityGetComponent(&mgr, entity, COMPONENT_TYPE_POSITION),
|
||||
COMPONENT_ID_INVALID
|
||||
);
|
||||
|
||||
componentid_t posComp = entityAddComponent(
|
||||
&mgr, entity, COMPONENT_TYPE_POSITION
|
||||
);
|
||||
assert_true(posComp != COMPONENT_ID_INVALID);
|
||||
assert_int_equal(
|
||||
entityGetComponent(&mgr, entity, COMPONENT_TYPE_POSITION), posComp
|
||||
);
|
||||
|
||||
entityposition_t *pos = entityPositionGet(&mgr, entity, posComp);
|
||||
assert_non_null(pos);
|
||||
|
||||
entityDispose(&mgr, entity);
|
||||
assert_int_equal(
|
||||
entityGetComponent(&mgr, entity, COMPONENT_TYPE_POSITION),
|
||||
COMPONENT_ID_INVALID
|
||||
);
|
||||
assert_true((mgr.entities[entity].state & ENTITY_STATE_ACTIVE) == 0);
|
||||
|
||||
entityManagerDispose(&mgr);
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
static void test_entityAddDuplicateComponentAsserts(void **state) {
|
||||
entitymanager_t mgr;
|
||||
entityManagerInit(&mgr);
|
||||
|
||||
entityid_t entity = entityManagerAdd(&mgr);
|
||||
entityAddComponent(&mgr, entity, COMPONENT_TYPE_POSITION);
|
||||
expect_assert_failure(
|
||||
entityAddComponent(&mgr, entity, COMPONENT_TYPE_POSITION)
|
||||
);
|
||||
|
||||
entityManagerDispose(&mgr);
|
||||
assert_int_equal(memoryGetAllocatedCount(), 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_entityManagerAddIsolatesEntities),
|
||||
cmocka_unit_test(test_entityManagerFullAsserts),
|
||||
cmocka_unit_test(test_entityAddGetDisposeComponent),
|
||||
cmocka_unit_test(test_entityAddDuplicateComponentAsserts),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user