ucx/test.c

Mon, 22 Jul 2013 11:39:06 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 22 Jul 2013 11:39:06 +0200
changeset 121
311cac04d079
parent 103
08018864fb91
child 134
4d320dc3a7af
permissions
-rw-r--r--

removal of single linked list implemenation - step 1: removal

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@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@26 38 return suite;
universe@26 39 }
universe@26 40
universe@26 41 void ucx_test_suite_free(UcxTestSuite* suite) {
universe@83 42 UcxTestList *l = suite->tests;
universe@83 43 while (l != NULL) {
universe@83 44 UcxTestList *e = l;
universe@83 45 l = l->next;
universe@83 46 free(e);
universe@83 47 }
universe@26 48 free(suite);
universe@26 49 }
universe@26 50
universe@83 51 int ucx_test_register(UcxTestSuite* suite, UcxTest test) {
universe@83 52 if (suite->tests) {
universe@97 53 UcxTestList *newelem = (UcxTestList*) malloc(sizeof(UcxTestList));
universe@97 54 if (newelem) {
universe@97 55 newelem->test = test;
universe@97 56 newelem->next = NULL;
universe@97 57
universe@97 58 UcxTestList *last = suite->tests;
universe@97 59 while (last->next) {
universe@97 60 last = last->next;
universe@97 61 }
universe@97 62 last->next = newelem;
universe@83 63
universe@83 64 return EXIT_SUCCESS;
universe@83 65 } else {
universe@83 66 return EXIT_FAILURE;
universe@83 67 }
universe@83 68 } else {
universe@83 69 suite->tests = (UcxTestList*) malloc(sizeof(UcxTestList));
universe@83 70 if (suite->tests) {
universe@83 71 suite->tests->test = test;
universe@83 72 suite->tests->next = NULL;
universe@83 73
universe@83 74 return EXIT_SUCCESS;
universe@83 75 } else {
universe@83 76 return EXIT_FAILURE;
universe@83 77 }
universe@83 78 }
universe@26 79 }
universe@26 80
universe@26 81 void ucx_test_run(UcxTestSuite* suite, FILE* output) {
universe@26 82 suite->success = 0;
universe@26 83 suite->failure = 0;
universe@121 84 for (UcxTestList* elem = suite->tests ; elem ; elem = elem->next) {
universe@121 85 elem->test(suite, output);
universe@26 86 }
universe@26 87 fwrite("\nAll test completed.\n", 1, 21, output);
universe@26 88 fprintf(output, " Total: %d\n Success: %d\n Failure: %d\n",
universe@26 89 suite->success+suite->failure, suite->success, suite->failure);
universe@26 90 }

mercurial