diff options
Diffstat (limited to 'test/src/Unit.c')
| -rw-r--r-- | test/src/Unit.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/test/src/Unit.c b/test/src/Unit.c new file mode 100644 index 0000000..dd7123a --- /dev/null +++ b/test/src/Unit.c @@ -0,0 +1,80 @@ +#include <BH/Unit.h> +#include <stdlib.h> + + +typedef struct BH_Unit +{ + struct BH_Unit *next; + const char *name; + BH_UnitCallback cb; +} BH_Unit; + + +static BH_Unit *root = NULL; + + +static void cleanup(void) +{ + BH_Unit *current; + + current = root; + while (current) + { + BH_Unit *next = current->next; + + free(current); + current = next; + } +} + + +void BH_UnitAdd(const char *name, BH_UnitCallback cb) +{ + BH_Unit *unit, *current; + + /* Allocate and fill new unit test entry */ + unit = malloc(sizeof(*unit)); + if (!unit) + return; + + unit->next = NULL; + unit->name = name; + unit->cb = cb; + + /* Append unit test entry */ + current = root; + while (current && current->next) + current = current->next; + + if (current) + current->next = unit; + else + root = unit; +} + + +int BH_UnitRun(void) +{ + BH_Unit *current; + int result = 0; + printf("Running tests...\n"); + + current = root; + while (current) + { + printf("%s\n", current->name); + if (current->cb()) + { + printf("\tFAIL\n"); + result = -1; + } + else + printf("\tPASS\n"); + + fflush(stdout); + current = current->next; + } + + cleanup(); + return result; +} |
