Files
libakerror/tests/err_cleanup.c

50 lines
948 B
C
Raw Normal View History

#include "akerror.h"
#include "err_capture.h"
2025-07-21 07:19:41 -04:00
int x;
akerr_ErrorContext *func2(void)
2025-07-21 07:19:41 -04:00
{
PREPARE_ERROR(errctx);
ATTEMPT {
FAIL(errctx, AKERR_NULLPOINTER, "This is a failure in func2");
2025-07-21 07:19:41 -04:00
} CLEANUP {
} PROCESS(errctx) {
} FINISH(errctx, true);
SUCCEED_RETURN(errctx);
}
akerr_ErrorContext *func1(void)
2025-07-21 07:19:41 -04:00
{
PREPARE_ERROR(errctx);
ATTEMPT {
CATCH(errctx, func2());
} CLEANUP {
x = 0;
} PROCESS(errctx) {
} FINISH(errctx, true);
SUCCEED_RETURN(errctx);
}
int main(void)
{
x = 12345;
PREPARE_ERROR(errctx);
ATTEMPT {
CATCH(errctx, func1());
} CLEANUP {
} PROCESS(errctx) {
} HANDLE(errctx, AKERR_NULLPOINTER) {
AKERR_CHECK_STATUS(errctx, AKERR_NULLPOINTER);
2025-07-21 07:19:41 -04:00
if ( x == 0 ) {
akerr_log_method("Cleanup works\n");
} else {
return 1;
2025-07-21 07:19:41 -04:00
}
} FINISH_NORETURN(errctx);
AKERR_CHECK(akerr_slots_in_use() == 0);
fprintf(stderr, "err_cleanup ok\n");
return 0;
2025-07-21 07:19:41 -04:00
}