src/test.c

Sat, 28 Oct 2017 15:59:16 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 28 Oct 2017 15:59:16 +0200
changeset 260
a6184aff5108
parent 259
2f5dea574a75
permissions
-rw-r--r--

rename LICENSE to COPYING to be distributed by autoconf

universe@103 1 /*
universe@103 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
universe@26 3 *
universe@259 4 * Copyright 2017 Mike Becker, 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@251 29 #include "ucx/test.h"
universe@26 30
universe@26 31 UcxTestSuite* ucx_test_suite_new() {
universe@26 32 UcxTestSuite* suite = (UcxTestSuite*) malloc(sizeof(UcxTestSuite));
universe@26 33 if (suite != NULL) {
universe@26 34 suite->success = 0;
universe@26 35 suite->failure = 0;
universe@26 36 suite->tests = NULL;
universe@26 37 }
universe@134 38
universe@26 39 return suite;
universe@26 40 }
universe@26 41
universe@26 42 void ucx_test_suite_free(UcxTestSuite* suite) {
universe@83 43 UcxTestList *l = suite->tests;
universe@83 44 while (l != NULL) {
universe@83 45 UcxTestList *e = l;
universe@83 46 l = l->next;
universe@83 47 free(e);
universe@83 48 }
universe@26 49 free(suite);
universe@26 50 }
universe@26 51
universe@83 52 int ucx_test_register(UcxTestSuite* suite, UcxTest test) {
universe@83 53 if (suite->tests) {
universe@97 54 UcxTestList *newelem = (UcxTestList*) malloc(sizeof(UcxTestList));
universe@97 55 if (newelem) {
universe@97 56 newelem->test = test;
universe@97 57 newelem->next = NULL;
universe@97 58
universe@97 59 UcxTestList *last = suite->tests;
universe@97 60 while (last->next) {
universe@97 61 last = last->next;
universe@97 62 }
universe@97 63 last->next = newelem;
universe@83 64
universe@83 65 return EXIT_SUCCESS;
universe@83 66 } else {
universe@83 67 return EXIT_FAILURE;
universe@83 68 }
universe@83 69 } else {
universe@83 70 suite->tests = (UcxTestList*) malloc(sizeof(UcxTestList));
universe@83 71 if (suite->tests) {
universe@83 72 suite->tests->test = test;
universe@83 73 suite->tests->next = NULL;
universe@83 74
universe@83 75 return EXIT_SUCCESS;
universe@83 76 } else {
universe@83 77 return EXIT_FAILURE;
universe@83 78 }
universe@83 79 }
universe@26 80 }
universe@26 81
universe@26 82 void ucx_test_run(UcxTestSuite* suite, FILE* output) {
universe@26 83 suite->success = 0;
universe@26 84 suite->failure = 0;
universe@121 85 for (UcxTestList* elem = suite->tests ; elem ; elem = elem->next) {
universe@121 86 elem->test(suite, output);
universe@26 87 }
universe@26 88 fwrite("\nAll test completed.\n", 1, 21, output);
universe@247 89 fprintf(output, " Total: %u\n Success: %u\n Failure: %u\n",
universe@26 90 suite->success+suite->failure, suite->success, suite->failure);
universe@26 91 }

mercurial