ucx/test.c

Fri, 08 Feb 2013 17:09:12 +0100

author
Mike Becker <universe@uap-core.de>
date
Fri, 08 Feb 2013 17:09:12 +0100
changeset 83
3b552d7a9610
parent 26
59f147baea31
child 97
499e1b465d77
permissions
-rw-r--r--

modified code to compile with -pedantic

     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 *list = (UcxTestList*) malloc(sizeof(UcxTestList));
    33         if (list) {
    34             list->test = test;
    35             list->next = suite->tests;
    36             suite->tests = list;
    38             return EXIT_SUCCESS;
    39         } else {
    40             return EXIT_FAILURE;
    41         }
    42     } else {
    43         suite->tests = (UcxTestList*) malloc(sizeof(UcxTestList));
    44         if (suite->tests) {
    45             suite->tests->test = test;
    46             suite->tests->next = NULL;
    48             return EXIT_SUCCESS;
    49         } else {
    50             return EXIT_FAILURE;
    51         }
    52     }
    53 }
    55 void ucx_test_run(UcxTestSuite* suite, FILE* output) {
    56     suite->success = 0;
    57     suite->failure = 0;
    58     UCX_FOREACH (UcxTestList*, suite->tests, e) {
    59         e->test(suite, output);
    60     }
    61     fwrite("\nAll test completed.\n", 1, 21, output);
    62     fprintf(output, "  Total:   %d\n  Success: %d\n  Failure: %d\n",
    63             suite->success+suite->failure, suite->success, suite->failure);
    64 }

mercurial