ucx/test.c

Thu, 28 Feb 2013 08:15:15 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 28 Feb 2013 08:15:15 +0100
changeset 101
bfd620e092c3
parent 97
499e1b465d77
child 103
08018864fb91
permissions
-rw-r--r--

regained support for microsoft c++ compiler

     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     UcxTestList *l = suite->tests;
    22     while (l != NULL) {
    23         UcxTestList *e = l;
    24         l = l->next;
    25         free(e);
    26     }
    27     free(suite);
    28 }
    30 int ucx_test_register(UcxTestSuite* suite, UcxTest test) {
    31     if (suite->tests) {
    32         UcxTestList *newelem = (UcxTestList*) malloc(sizeof(UcxTestList));
    33         if (newelem) {
    34             newelem->test = test;
    35             newelem->next = NULL;
    37             UcxTestList *last = suite->tests;
    38             while (last->next) {
    39                 last = last->next;
    40             }
    41             last->next = newelem;
    43             return EXIT_SUCCESS;
    44         } else {
    45             return EXIT_FAILURE;
    46         }
    47     } else {
    48         suite->tests = (UcxTestList*) malloc(sizeof(UcxTestList));
    49         if (suite->tests) {
    50             suite->tests->test = test;
    51             suite->tests->next = NULL;
    53             return EXIT_SUCCESS;
    54         } else {
    55             return EXIT_FAILURE;
    56         }
    57     }
    58 }
    60 void ucx_test_run(UcxTestSuite* suite, FILE* output) {
    61     suite->success = 0;
    62     suite->failure = 0;
    63     UCX_FOREACH (UcxTestList*, suite->tests, e) {
    64         e->test(suite, output);
    65     }
    66     fwrite("\nAll test completed.\n", 1, 21, output);
    67     fprintf(output, "  Total:   %d\n  Success: %d\n  Failure: %d\n",
    68             suite->success+suite->failure, suite->success, suite->failure);
    69 }

mercurial