[4523] | 1 | //rat.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5823] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2013 |
---|
[4523] | 5 | * |
---|
| 6 | * This file is part of rat a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * libroar is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
| 23 | * |
---|
| 24 | * NOTE for everyone want's to change something and send patches: |
---|
| 25 | * read README and HACKING! There a addition information on |
---|
| 26 | * the license of this document you need to read before you send |
---|
| 27 | * any patches. |
---|
| 28 | * |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | #include "rat.h" |
---|
| 32 | #include <string.h> |
---|
| 33 | |
---|
| 34 | struct rat_testgroup { |
---|
| 35 | unsigned int ok, fail; |
---|
| 36 | }; |
---|
| 37 | |
---|
| 38 | struct rat_tests { |
---|
| 39 | struct rat_testgroup all, subtests, cur_subtests; |
---|
| 40 | unsigned int testsc, subtestsc; |
---|
| 41 | }; |
---|
| 42 | |
---|
| 43 | static struct rat_tests inst; |
---|
| 44 | |
---|
| 45 | void rat_init(const char * name, const char * desc) { |
---|
| 46 | memset(&inst, 0, sizeof(inst)); |
---|
| 47 | |
---|
| 48 | printf("---[ %s ]---\n", name); |
---|
| 49 | printf("Description: %s\n", desc); |
---|
| 50 | printf("\n"); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | int rat_fin(void) { |
---|
| 54 | |
---|
| 55 | printf("\n"); |
---|
| 56 | printf("Summery:\n"); |
---|
| 57 | printf("%u of %u tests ok, %u tests failed.\n", inst.all.ok, inst.testsc, inst.all.fail); |
---|
| 58 | |
---|
| 59 | return inst.all.fail; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | void rat_test(const char * title, int res) { |
---|
| 63 | printf("Test %-32s: %s\n", title, res ? "ok" : "failed"); |
---|
| 64 | |
---|
| 65 | inst.testsc++; |
---|
| 66 | |
---|
| 67 | if ( res ) { |
---|
| 68 | inst.all.ok++; |
---|
| 69 | } else { |
---|
| 70 | inst.all.fail++; |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | void rat_test_zero(const char * title, int res) { |
---|
| 75 | rat_test(title, res == 0); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | void rat_test_with_subtests(const char * title) { |
---|
| 79 | memset(&(inst.cur_subtests), 0, sizeof(inst.cur_subtests)); |
---|
| 80 | printf("Test %-32s: ", title); |
---|
| 81 | fflush(stdout); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | void rat_subtests_fin(void) { |
---|
| 85 | printf(" %u ok, %u failed.\n", inst.cur_subtests.ok, inst.cur_subtests.fail); |
---|
| 86 | inst.subtests.ok += inst.cur_subtests.ok; |
---|
| 87 | inst.subtests.fail += inst.cur_subtests.fail; |
---|
| 88 | |
---|
| 89 | inst.testsc++; |
---|
| 90 | |
---|
| 91 | if ( inst.cur_subtests.fail ) { |
---|
| 92 | inst.all.fail++; |
---|
| 93 | } else { |
---|
| 94 | inst.all.ok++; |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | void rat_subtest(int res) { |
---|
| 99 | inst.subtestsc++; |
---|
| 100 | |
---|
| 101 | if ( res ) { |
---|
| 102 | printf("."); |
---|
| 103 | inst.cur_subtests.ok++; |
---|
| 104 | } else { |
---|
| 105 | printf("e"); |
---|
| 106 | inst.cur_subtests.fail++; |
---|
| 107 | } |
---|
| 108 | fflush(stdout); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | void rat_subtest_crit(int res) { |
---|
| 112 | inst.subtestsc++; |
---|
| 113 | |
---|
| 114 | if ( res ) { |
---|
| 115 | printf("."); |
---|
| 116 | inst.cur_subtests.ok++; |
---|
| 117 | } else { |
---|
| 118 | printf("E"); |
---|
| 119 | inst.cur_subtests.fail++; |
---|
| 120 | } |
---|
| 121 | fflush(stdout); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | //ll |
---|