ucx/test.c

Thu, 16 Aug 2012 12:36:23 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 16 Aug 2012 12:36:23 +0200
changeset 37
ec296899d12f
parent 26
59f147baea31
child 83
3b552d7a9610
permissions
-rw-r--r--

replaced qsort with natural merge sort

/* 
 * File:   test.c
 * Author: Mike
 *
 * Created on 18. Februar 2012, 14:15
 */

#include "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) {
    ucx_list_free(suite->tests);
    free(suite);
}

void ucx_test_register(UcxTestSuite* suite, UcxTest test) {
    suite->tests = ucx_list_append(suite->tests, (void*) test);
}

void ucx_test_run(UcxTestSuite* suite, FILE* output) {
    suite->success = 0;
    suite->failure = 0;
    UCX_FOREACH (UcxList*, suite->tests, e) {
        UcxTest test = (UcxTest) (e->data);
        test(suite, output);
    }
    fwrite("\nAll test completed.\n", 1, 21, output);
    fprintf(output, "  Total:   %d\n  Success: %d\n  Failure: %d\n",
            suite->success+suite->failure, suite->success, suite->failure);
}

mercurial