ucx/test.c

Sat, 18 Feb 2012 15:50:43 +0100

author
Mike Becker <universe@uap-core.de>
date
Sat, 18 Feb 2012 15:50:43 +0100
changeset 26
59f147baea31
child 83
3b552d7a9610
permissions
-rw-r--r--

added test framework and foreach macro

     1 /* 
     2  * File:   test.c
     3  * Author: Mike
     4  *
     5  * Created on 18. Februar 2012, 14:15
     6  */
     8 #include "test.h"
    10 UcxTestSuite* ucx_test_suite_new() {
    11     UcxTestSuite* suite = (UcxTestSuite*) malloc(sizeof(UcxTestSuite));
    12     if (suite != NULL) {
    13         suite->success = 0;
    14         suite->failure = 0;
    15         suite->tests = NULL;
    16     }
    17     return suite;
    18 }
    20 void ucx_test_suite_free(UcxTestSuite* suite) {
    21     ucx_list_free(suite->tests);
    22     free(suite);
    23 }
    25 void ucx_test_register(UcxTestSuite* suite, UcxTest test) {
    26     suite->tests = ucx_list_append(suite->tests, (void*) test);
    27 }
    29 void ucx_test_run(UcxTestSuite* suite, FILE* output) {
    30     suite->success = 0;
    31     suite->failure = 0;
    32     UCX_FOREACH (UcxList*, suite->tests, e) {
    33         UcxTest test = (UcxTest) (e->data);
    34         test(suite, output);
    35     }
    36     fwrite("\nAll test completed.\n", 1, 21, output);
    37     fprintf(output, "  Total:   %d\n  Success: %d\n  Failure: %d\n",
    38             suite->success+suite->failure, suite->success, suite->failure);
    39 }

mercurial