-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcutt.h
103 lines (91 loc) · 5.16 KB
/
cutt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* INFO ************************************************************************
** **
** cutils **
** ====== **
** **
** Modern and Lightweight C Utilities **
** Version: 0.8.72.556 (20140718) **
** **
** File: cutt.h **
** **
** For more information about the project, visit <http://www.cutils.org>. **
** Copyright (C) 2014 Peter Varo **
** **
** This program is free software: you can redistribute it and/or modify it **
** under the terms of the GNU General Public License as published by the **
** Free Software Foundation, either version 3 of the License, or **
** (at your option) any later version. **
** **
** This program is distributed in the hope that it will be useful, but **
** WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. **
** See the GNU General Public License for more details. **
** **
** You should have received a copy of the GNU General Public License **
** along with this program, most likely a file in the root directory, **
** called 'LICENSE'. If not, see <http://www.gnu.org/licenses>. **
** **
************************************************************************ INFO */
#ifndef _C_UNIT_TEST_TOOLS_H_3818217702141947_
#define _C_UNIT_TEST_TOOLS_H_3818217702141947_
#include <stdio.h> /* fprintf(), stderr, stdout */
#include <stdlib.h> /* malloc(), free(), exit(), EXIT_FAILURE */
#undef __str
#undef _str
#undef cutils_cutt_try
#undef cutils_cutt_report
#define __str(value) #value
#define _str(value) __str(value)
/*----------------------------------------------------------------------------*/
typedef struct
{
size_t fail;
size_t size;
char *info[];
} cutils_cutt_Tester;
/*----------------------------------------------------------------------------*/
static inline void
cutils_cutt_Tester_new(cutils_cutt_Tester **tester,
size_t count)
{
cutils_cutt_Tester *_tester = malloc(sizeof(cutils_cutt_Tester) +
count*sizeof(char *));
if (!_tester)
{
fprintf(stderr, "CUTT: Internal allocation failed\n");
exit(EXIT_FAILURE);
}
_tester->fail = 0;
_tester->size = count;
*tester = _tester;
}
/*----------------------------------------------------------------------------*/
static inline void
cutils_cutt_Tester_del(cutils_cutt_Tester *tester)
{
free(tester);
}
/*----------------------------------------------------------------------------*/
#define cutils_cutt_Tester_try(tester, expression) \
do { \
if (!(expression)) \
tester->info[tester->fail++] = "CUTT: in file: '" __FILE__ \
"', at line: "_str(__LINE__) \
": '"#expression"'"; \
} while (0)
/*----------------------------------------------------------------------------*/
#define cutils_cutt_Tester_report(tester) \
do { \
size_t fail = tester->fail, size = tester->size; \
if (fail) \
{ \
fprintf(stderr, "CUTT: Some tests " \
"(%zu / %zu) failed:\n", size-fail, size); \
for (size_t i=0; i<fail; i++) \
fprintf(stderr, "%s\n", tester->info[i]); \
} \
else \
fprintf(stderr, "CUTT: All tests " \
"(%zu / %zu) passed.\n", size, size); \
} while (0)
#endif /* _C_UNIT_TEST_TOOLS_H_3818217702141947_ */