#include "ucx/test.h"
UcxTestSuite* ucx_test_suite_new() {
UcxTestSuite* suite = (UcxTestSuite*) malloc(
sizeof(UcxTestSuite));
if (suite !=
NULL) {
suite->success =
0;
suite->failure =
0;
suite->tests =
NULL;
}
return suite;
}
void ucx_test_suite_free(UcxTestSuite* suite) {
UcxTestList *l = suite->tests;
while (l !=
NULL) {
UcxTestList *e = l;
l = l->next;
free(e);
}
free(suite);
}
int ucx_test_register(UcxTestSuite* suite, UcxTest test) {
if (suite->tests) {
UcxTestList *newelem = (UcxTestList*) malloc(
sizeof(UcxTestList));
if (newelem) {
newelem->test = test;
newelem->next =
NULL;
UcxTestList *last = suite->tests;
while (last->next) {
last = last->next;
}
last->next = newelem;
return EXIT_SUCCESS;
}
else {
return EXIT_FAILURE;
}
}
else {
suite->tests = (UcxTestList*) malloc(
sizeof(UcxTestList));
if (suite->tests) {
suite->tests->test = test;
suite->tests->next =
NULL;
return EXIT_SUCCESS;
}
else {
return EXIT_FAILURE;
}
}
}
void ucx_test_run(UcxTestSuite* suite,
FILE* output) {
suite->success =
0;
suite->failure =
0;
for (UcxTestList* elem = suite->tests ; elem ; elem = elem->next) {
elem->test(suite, output);
}
fwrite(
"\nAll test completed.\n",
1,
21, output);
fprintf(output,
" Total: %u\n Success: %u\n Failure: %u\n",
suite->success+suite->failure, suite->success, suite->failure);
}