Unify the library on an akgl_ namespace
This commit is contained in:
146
tests/actor.c
146
tests/actor.c
@@ -32,20 +32,20 @@ void handle_unhandled_error_noexit(akerr_ErrorContext *errctx)
|
||||
}
|
||||
}
|
||||
|
||||
int actor_updated;
|
||||
akerr_ErrorContext *actor_update_noop(actor *obj)
|
||||
int akgl_actor_updated;
|
||||
akerr_ErrorContext *akgl_actor_update_noop(akgl_Actor *obj)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
actor_updated = 1;
|
||||
akgl_actor_updated = 1;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
// Currently the renderer assumes there is a global variable named `renderer`
|
||||
int actor_rendered;
|
||||
akerr_ErrorContext *actor_render_noop(actor *obj, SDL_Renderer *r)
|
||||
int akgl_actor_rendered;
|
||||
akerr_ErrorContext *akgl_actor_render_noop(akgl_Actor *obj, SDL_Renderer *r)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
actor_rendered = 1;
|
||||
akgl_actor_rendered = 1;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ akerr_ErrorContext *test_registry_actor_iterator_nullpointers(void)
|
||||
akerr_handler_unhandled_error = handle_unhandled_error_noexit;
|
||||
ATTEMPT {
|
||||
UNHANDLED_ERROR_BEHAVIOR = UNHANDLED_ERROR_SET;
|
||||
DETECT(unhandled_error_context, registry_iterate_actor(NULL, REGISTRY_ACTOR, ""));
|
||||
DETECT(unhandled_error_context, akgl_registry_iterate_actor(NULL, AKGL_REGISTRY_ACTOR, ""));
|
||||
} CLEANUP {
|
||||
UNHANDLED_ERROR_BEHAVIOR = UNHANDLED_ERROR_EXIT;
|
||||
} PROCESS(unhandled_error_context) {
|
||||
@@ -74,7 +74,7 @@ akerr_ErrorContext *test_registry_actor_iterator_missingactor(void)
|
||||
PREPARE_ERROR(errctx);
|
||||
akerr_ErrorUnhandledErrorHandler defaulthandler = akerr_handler_unhandled_error;
|
||||
|
||||
iterator iter = {
|
||||
akgl_Iterator iter = {
|
||||
.layerid = 0,
|
||||
.flags = 0
|
||||
};
|
||||
@@ -83,9 +83,9 @@ akerr_ErrorContext *test_registry_actor_iterator_missingactor(void)
|
||||
UNHANDLED_ERROR_BEHAVIOR = UNHANDLED_ERROR_SET;
|
||||
DETECT(
|
||||
unhandled_error_context,
|
||||
registry_iterate_actor(
|
||||
akgl_registry_iterate_actor(
|
||||
&iter,
|
||||
REGISTRY_ACTOR,
|
||||
AKGL_REGISTRY_ACTOR,
|
||||
"Actor who doesn't exist")
|
||||
);
|
||||
} CLEANUP {
|
||||
@@ -100,10 +100,10 @@ akerr_ErrorContext *test_registry_actor_iterator_missingactor(void)
|
||||
|
||||
akerr_ErrorContext *test_registry_actor_iterator_updaterender(void)
|
||||
{
|
||||
actor *testactor;
|
||||
iterator iter = {
|
||||
akgl_Actor *testactor;
|
||||
akgl_Iterator iter = {
|
||||
.layerid = 0,
|
||||
.flags = ITERATOR_OP_UPDATE | ITERATOR_OP_RENDER
|
||||
.flags = AKGL_ITERATOR_OP_UPDATE | AKGL_ITERATOR_OP_RENDER
|
||||
};
|
||||
akerr_ErrorUnhandledErrorHandler defaulthandler = akerr_handler_unhandled_error;
|
||||
|
||||
@@ -111,36 +111,36 @@ akerr_ErrorContext *test_registry_actor_iterator_updaterender(void)
|
||||
akerr_handler_unhandled_error = handle_unhandled_error_noexit;
|
||||
ATTEMPT {
|
||||
UNHANDLED_ERROR_BEHAVIOR = UNHANDLED_ERROR_SET;
|
||||
CATCH(unhandled_error_context, heap_next_actor(&testactor));
|
||||
CATCH(unhandled_error_context, actor_initialize(testactor, "test"));
|
||||
CATCH(unhandled_error_context, akgl_heap_next_actor(&testactor));
|
||||
CATCH(unhandled_error_context, akgl_actor_initialize(testactor, "test"));
|
||||
|
||||
testactor->layer = 0;
|
||||
testactor->updatefunc = &actor_update_noop;
|
||||
testactor->renderfunc = &actor_render_noop;
|
||||
testactor->updatefunc = &akgl_actor_update_noop;
|
||||
testactor->renderfunc = &akgl_actor_render_noop;
|
||||
|
||||
DETECT(
|
||||
unhandled_error_context,
|
||||
registry_iterate_actor(
|
||||
akgl_registry_iterate_actor(
|
||||
&iter,
|
||||
REGISTRY_ACTOR,
|
||||
AKGL_REGISTRY_ACTOR,
|
||||
"test")
|
||||
);
|
||||
|
||||
FAIL_ZERO_BREAK(
|
||||
unhandled_error_context,
|
||||
actor_updated,
|
||||
akgl_actor_updated,
|
||||
AKERR_BEHAVIOR,
|
||||
"actor->updatefunc not called by the iterator"
|
||||
);
|
||||
FAIL_ZERO_BREAK(
|
||||
unhandled_error_context,
|
||||
actor_rendered,
|
||||
akgl_actor_rendered,
|
||||
AKERR_BEHAVIOR,
|
||||
"actor->renderfunc not called by the iterator"
|
||||
);
|
||||
} CLEANUP {
|
||||
UNHANDLED_ERROR_BEHAVIOR = UNHANDLED_ERROR_EXIT;
|
||||
IGNORE(heap_release_actor(testactor));
|
||||
IGNORE(akgl_heap_release_actor(testactor));
|
||||
} PROCESS(unhandled_error_context) {
|
||||
} FINISH(unhandled_error_context, true);
|
||||
|
||||
@@ -149,15 +149,15 @@ akerr_ErrorContext *test_registry_actor_iterator_updaterender(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext *test_actor_set_character(void)
|
||||
akerr_ErrorContext *test_akgl_actor_set_character(void)
|
||||
{
|
||||
actor *testactor = NULL;
|
||||
character *testchar = NULL;
|
||||
akgl_Actor *testactor = NULL;
|
||||
akgl_Character *testchar = NULL;
|
||||
|
||||
PREPARE_ERROR(errctx);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, actor_set_character(NULL, "test"));
|
||||
CATCH(errctx, akgl_actor_set_character(NULL, "test"));
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
@@ -166,36 +166,36 @@ akerr_ErrorContext *test_actor_set_character(void)
|
||||
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, heap_next_actor(&testactor));
|
||||
CATCH(errctx, akgl_heap_next_actor(&testactor));
|
||||
|
||||
CATCH(errctx, actor_initialize(testactor, "test"));
|
||||
CATCH(errctx, akgl_actor_initialize(testactor, "test"));
|
||||
testactor->layer = 0;
|
||||
testactor->updatefunc = &actor_update_noop;
|
||||
testactor->renderfunc = &actor_render_noop;
|
||||
testactor->updatefunc = &akgl_actor_update_noop;
|
||||
testactor->renderfunc = &akgl_actor_render_noop;
|
||||
|
||||
CATCH(errctx, actor_set_character(testactor, "test"));
|
||||
CATCH(errctx, akgl_actor_set_character(testactor, "test"));
|
||||
} CLEANUP {
|
||||
IGNORE(heap_release_actor(testactor));
|
||||
IGNORE(akgl_heap_release_actor(testactor));
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
printf("Handled\n");
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, heap_next_actor(&testactor));
|
||||
CATCH(errctx, heap_next_character(&testchar));
|
||||
CATCH(errctx, akgl_heap_next_actor(&testactor));
|
||||
CATCH(errctx, akgl_heap_next_character(&testchar));
|
||||
|
||||
CATCH(errctx, actor_initialize(testactor, "test"));
|
||||
CATCH(errctx, akgl_actor_initialize(testactor, "test"));
|
||||
testactor->layer = 0;
|
||||
testactor->updatefunc = &actor_update_noop;
|
||||
testactor->renderfunc = &actor_render_noop;
|
||||
testactor->updatefunc = &akgl_actor_update_noop;
|
||||
testactor->renderfunc = &akgl_actor_render_noop;
|
||||
|
||||
CATCH(errctx, character_initialize(testchar, "test"));
|
||||
CATCH(errctx, akgl_character_initialize(testchar, "test"));
|
||||
|
||||
CATCH(errctx, actor_set_character(testactor, "test"));
|
||||
CATCH(errctx, akgl_actor_set_character(testactor, "test"));
|
||||
} CLEANUP {
|
||||
IGNORE(heap_release_actor(testactor));
|
||||
IGNORE(heap_release_character(testchar));
|
||||
IGNORE(akgl_heap_release_actor(testactor));
|
||||
IGNORE(akgl_heap_release_character(testchar));
|
||||
} PROCESS(errctx) {
|
||||
} FINISH(errctx, true);
|
||||
|
||||
@@ -204,28 +204,28 @@ akerr_ErrorContext *test_actor_set_character(void)
|
||||
|
||||
akerr_ErrorContext *test_actor_manage_children(void)
|
||||
{
|
||||
actor *parent = NULL;
|
||||
actor *child = NULL;
|
||||
string *tmpstring = NULL;
|
||||
akgl_Actor *parent = NULL;
|
||||
akgl_Actor *child = NULL;
|
||||
akgl_String *tmpstring = NULL;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
PREPARE_ERROR(errctx);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, heap_init());
|
||||
CATCH(errctx, heap_next_string(&tmpstring));
|
||||
CATCH(errctx, heap_next_actor(&parent));
|
||||
CATCH(errctx, actor_initialize(parent, "parent"));
|
||||
for ( i = 0 ; i < ACTOR_MAX_CHILDREN; i++ ) {
|
||||
CATCH(errctx, akgl_heap_init());
|
||||
CATCH(errctx, akgl_heap_next_string(&tmpstring));
|
||||
CATCH(errctx, akgl_heap_next_actor(&parent));
|
||||
CATCH(errctx, akgl_actor_initialize(parent, "parent"));
|
||||
for ( i = 0 ; i < AKGL_ACTOR_MAX_CHILDREN; i++ ) {
|
||||
sprintf((char *)&tmpstring->data, "child %d", i);
|
||||
CATCH(errctx, heap_next_actor(&child));
|
||||
CATCH(errctx, actor_initialize(child, (char *)&tmpstring->data));
|
||||
CATCH(errctx, akgl_heap_next_actor(&child));
|
||||
CATCH(errctx, akgl_actor_initialize(child, (char *)&tmpstring->data));
|
||||
CATCH(errctx, parent->addchild(parent, child));
|
||||
// Release our claim on the actor so the parent can own the child and kill it
|
||||
CATCH(errctx, heap_release_actor(child));
|
||||
CATCH(errctx, akgl_heap_release_actor(child));
|
||||
}
|
||||
} CLEANUP {
|
||||
IGNORE(heap_release_string(tmpstring));
|
||||
IGNORE(akgl_heap_release_string(tmpstring));
|
||||
} PROCESS(errctx) {
|
||||
} FINISH(errctx, true);
|
||||
|
||||
@@ -244,7 +244,7 @@ akerr_ErrorContext *test_actor_manage_children(void)
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, heap_next_actor(&child));
|
||||
CATCH(errctx, akgl_heap_next_actor(&child));
|
||||
CATCH(errctx, parent->addchild(parent, child));
|
||||
} CLEANUP {
|
||||
if ( errctx == NULL ) {
|
||||
@@ -257,23 +257,23 @@ akerr_ErrorContext *test_actor_manage_children(void)
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, heap_release_actor(parent));
|
||||
CATCH(errctx, akgl_heap_release_actor(parent));
|
||||
// All actor objects on the heap should be empty now
|
||||
for ( i = 0; i < MAX_HEAP_ACTOR; i++) {
|
||||
for ( i = 0; i < AKGL_MAX_HEAP_ACTOR; i++) {
|
||||
FAIL_NONZERO_BREAK(errctx, HEAP_ACTOR[i].refcount, AKERR_VALUE, "Actor not properly cleared");
|
||||
FAIL_NONZERO_BREAK(errctx, HEAP_ACTOR[i].parent, AKERR_VALUE, "Actor not properly cleared");
|
||||
for ( j = 0 ; j < ACTOR_MAX_CHILDREN; j++) {
|
||||
for ( j = 0 ; j < AKGL_ACTOR_MAX_CHILDREN; j++) {
|
||||
if ( HEAP_ACTOR[i].children[j] != NULL ) {
|
||||
FAIL(errctx, AKERR_VALUE, "Actor not properly cleared");
|
||||
goto _test_actor_addchild_heaprelease_cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
for ( j = 0; j < ACTOR_MAX_CHILDREN; j++) {
|
||||
for ( j = 0; j < AKGL_ACTOR_MAX_CHILDREN; j++) {
|
||||
sprintf((char *)&tmpstring->data, "child %d", i);
|
||||
FAIL_NONZERO_BREAK(
|
||||
errctx,
|
||||
SDL_GetPointerProperty(REGISTRY_ACTOR, (char *)&tmpstring->data, NULL),
|
||||
SDL_GetPointerProperty(AKGL_REGISTRY_ACTOR, (char *)&tmpstring->data, NULL),
|
||||
AKERR_KEY,
|
||||
"Child %s was not removed from the registry",
|
||||
(char *)&tmpstring->data);
|
||||
@@ -284,22 +284,22 @@ _test_actor_addchild_heaprelease_cleanup:
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, heap_next_actor(&parent));
|
||||
CATCH(errctx, actor_initialize(parent, "parent"));
|
||||
CATCH(errctx, heap_next_actor(&child));
|
||||
CATCH(errctx, actor_initialize(child, "child"));
|
||||
CATCH(errctx, akgl_heap_next_actor(&parent));
|
||||
CATCH(errctx, akgl_actor_initialize(parent, "parent"));
|
||||
CATCH(errctx, akgl_heap_next_actor(&child));
|
||||
CATCH(errctx, akgl_actor_initialize(child, "child"));
|
||||
// Don't release our claim on the child. The child should not be reclaimed.
|
||||
CATCH(errctx, heap_release_actor(parent));
|
||||
CATCH(errctx, akgl_heap_release_actor(parent));
|
||||
FAIL_NONZERO_BREAK(errctx, child->parent, AKERR_VALUE, "Child still references released parent");
|
||||
FAIL_ZERO_BREAK(errctx, child->refcount, AKERR_VALUE, "Child prematurely released");
|
||||
FAIL_NONZERO_BREAK(errctx, strcmp(child->name, "child"), AKERR_VALUE, "Child had identity erased");
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
(child == SDL_GetPointerProperty(REGISTRY_ACTOR, child->name, NULL)),
|
||||
(child == SDL_GetPointerProperty(AKGL_REGISTRY_ACTOR, child->name, NULL)),
|
||||
AKERR_KEY,
|
||||
"Child prematurely removed from the registry");
|
||||
// Now we can release the child
|
||||
CATCH(errctx, heap_release_actor(child));
|
||||
CATCH(errctx, akgl_heap_release_actor(child));
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} FINISH(errctx, true);
|
||||
@@ -309,20 +309,20 @@ _test_actor_addchild_heaprelease_cleanup:
|
||||
|
||||
int main(void)
|
||||
{
|
||||
actor_updated = 0;
|
||||
actor_rendered = 0;
|
||||
akgl_actor_updated = 0;
|
||||
akgl_actor_rendered = 0;
|
||||
UNHANDLED_ERROR_BEHAVIOR = UNHANDLED_ERROR_EXIT;
|
||||
PREPARE_ERROR(errctx);
|
||||
ATTEMPT {
|
||||
CATCH(errctx, registry_init_actor());
|
||||
CATCH(errctx, registry_init_sprite());
|
||||
CATCH(errctx, registry_init_spritesheet());
|
||||
CATCH(errctx, registry_init_character());
|
||||
CATCH(errctx, akgl_registry_init_actor());
|
||||
CATCH(errctx, akgl_registry_init_sprite());
|
||||
CATCH(errctx, akgl_registry_init_spritesheet());
|
||||
CATCH(errctx, akgl_registry_init_character());
|
||||
|
||||
CATCH(errctx, test_registry_actor_iterator_nullpointers());
|
||||
CATCH(errctx, test_registry_actor_iterator_missingactor());
|
||||
CATCH(errctx, test_registry_actor_iterator_updaterender());
|
||||
CATCH(errctx, test_actor_set_character());
|
||||
CATCH(errctx, test_akgl_actor_set_character());
|
||||
CATCH(errctx, test_actor_manage_children());
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
|
||||
Reference in New Issue
Block a user