ucx/test.c

Fri, 09 Aug 2013 11:32:10 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 09 Aug 2013 11:32:10 +0200
changeset 134
4d320dc3a7af
parent 121
311cac04d079
child 138
7800811078b8
permissions
-rw-r--r--

documented test.h and removed duplicated implement/declare macros for UCX_TEST

universe@103 1 /*
universe@103 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
universe@26 3 *
universe@103 4 * Copyright 2013 Olaf Wintermann. All rights reserved.
universe@103 5 *
universe@103 6 * Redistribution and use in source and binary forms, with or without
universe@103 7 * modification, are permitted provided that the following conditions are met:
universe@103 8 *
universe@103 9 * 1. Redistributions of source code must retain the above copyright
universe@103 10 * notice, this list of conditions and the following disclaimer.
universe@103 11 *
universe@103 12 * 2. Redistributions in binary form must reproduce the above copyright
universe@103 13 * notice, this list of conditions and the following disclaimer in the
universe@103 14 * documentation and/or other materials provided with the distribution.
universe@103 15 *
universe@103 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@103 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@103 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
universe@103 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
universe@103 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
universe@103 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
universe@103 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
universe@103 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
universe@103 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
universe@103 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
universe@103 26 * POSSIBILITY OF SUCH DAMAGE.
universe@26 27 */
universe@26 28
universe@26 29 #include "test.h"
universe@26 30
universe@134 31
universe@134 32 struct UcxTestList{
universe@134 33 UcxTest test;
universe@134 34 UcxTestList *next;
universe@134 35 };
universe@134 36
universe@26 37 UcxTestSuite* ucx_test_suite_new() {
universe@26 38 UcxTestSuite* suite = (UcxTestSuite*) malloc(sizeof(UcxTestSuite));
universe@26 39 if (suite != NULL) {
universe@26 40 suite->success = 0;
universe@26 41 suite->failure = 0;
universe@26 42 suite->tests = NULL;
universe@26 43 }
universe@134 44
universe@26 45 return suite;
universe@26 46 }
universe@26 47
universe@26 48 void ucx_test_suite_free(UcxTestSuite* suite) {
universe@83 49 UcxTestList *l = suite->tests;
universe@83 50 while (l != NULL) {
universe@83 51 UcxTestList *e = l;
universe@83 52 l = l->next;
universe@83 53 free(e);
universe@83 54 }
universe@26 55 free(suite);
universe@26 56 }
universe@26 57
universe@83 58 int ucx_test_register(UcxTestSuite* suite, UcxTest test) {
universe@83 59 if (suite->tests) {
universe@97 60 UcxTestList *newelem = (UcxTestList*) malloc(sizeof(UcxTestList));
universe@97 61 if (newelem) {
universe@97 62 newelem->test = test;
universe@97 63 newelem->next = NULL;
universe@97 64
universe@97 65 UcxTestList *last = suite->tests;
universe@97 66 while (last->next) {
universe@97 67 last = last->next;
universe@97 68 }
universe@97 69 last->next = newelem;
universe@83 70
universe@83 71 return EXIT_SUCCESS;
universe@83 72 } else {
universe@83 73 return EXIT_FAILURE;
universe@83 74 }
universe@83 75 } else {
universe@83 76 suite->tests = (UcxTestList*) malloc(sizeof(UcxTestList));
universe@83 77 if (suite->tests) {
universe@83 78 suite->tests->test = test;
universe@83 79 suite->tests->next = NULL;
universe@83 80
universe@83 81 return EXIT_SUCCESS;
universe@83 82 } else {
universe@83 83 return EXIT_FAILURE;
universe@83 84 }
universe@83 85 }
universe@26 86 }
universe@26 87
universe@26 88 void ucx_test_run(UcxTestSuite* suite, FILE* output) {
universe@26 89 suite->success = 0;
universe@26 90 suite->failure = 0;
universe@121 91 for (UcxTestList* elem = suite->tests ; elem ; elem = elem->next) {
universe@121 92 elem->test(suite, output);
universe@26 93 }
universe@26 94 fwrite("\nAll test completed.\n", 1, 21, output);
universe@26 95 fprintf(output, " Total: %d\n Success: %d\n Failure: %d\n",
universe@26 96 suite->success+suite->failure, suite->success, suite->failure);
universe@26 97 }

mercurial