-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmtesting.h
132 lines (105 loc) · 3.95 KB
/
cmtesting.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Declarations for unit-test utilities for cryptmoumt
* (C)Copyright 2006-2024, RW Penney
*/
/*
This file is part of cryptmount
cryptmount 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 2 of the License, or
(at your option) any later version.
cryptmount 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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef _CMTEST_H
#define _CMTEST_H
#include "config.h"
/*! \addtogroup unit_tests
* @{ */
enum {
CM_TEST_PASSED = 0,
CM_TEST_FAILED,
CM_TEST_ABORTED,
CM_TEST_LAST
};
enum {
CM_READONLY = 0x001, /* Omit tests of key-creation */
CM_HASLEGACY = 0x002 /* Test against legacy key files */
};
typedef struct cm_testinfo {
const char *current; /* name of current test */
int tests_run; /* total number of tests initiated */
int test_stats[CM_TEST_LAST]; /* statistics of test outcomes */
const char *argconfigdir; /* adjustable config-directory */
} cm_testinfo_t;
extern cm_testinfo_t *test_ctxtptr;
#define CM_TEST_START(name) \
{ \
fprintf(stderr, "starting test \"%s\"...", name); \
++test_ctxtptr->tests_run; \
test_ctxtptr->current = NULL; \
}
#define CM_TEST_IDENT(ident) \
{ \
test_ctxtptr->current = (const char*)ident; \
}
#define CM_ASSERT_EQUAL(expected, actual) \
if ((expected) != (actual)) { \
fprintf(stderr, " test failed %s:%d (%s != %s)\n", \
__FILE__, __LINE__, #expected, #actual); \
if (test_ctxtptr->current != NULL) { \
fprintf(stderr, " [%s]\n", test_ctxtptr->current); } \
++test_ctxtptr->test_stats[CM_TEST_FAILED]; \
return CM_TEST_FAILED; \
}
#define CM_ASSERT_STR_EQUAL(expected, actual) \
if (strcmp(expected, actual) != 0) { \
fprintf(stderr, " test failed %s:%d (\"%s\" != \"%s\")\n", \
__FILE__, __LINE__, expected, actual); \
if (test_ctxtptr->current != NULL) { \
fprintf(stderr, " [%s]\n", test_ctxtptr->current); } \
++test_ctxtptr->test_stats[CM_TEST_FAILED]; \
return CM_TEST_FAILED; \
}
#define CM_ASSERT_DIFFERENT(expected, actual) \
if ((expected) == (actual)) { \
fprintf(stderr, " test failed %s:%d\n (%s == %s)", \
__FILE__, __LINE__, #expected, #actual); \
if (test_ctxtptr->current != NULL) { \
fprintf(stderr, " [%s]\n", test_ctxtptr->current); } \
++test_ctxtptr->test_stats[CM_TEST_FAILED]; \
return CM_TEST_FAILED; \
}
#define CM_TEST_OK(TI) \
{ \
fprintf(stderr, " ok\n"); \
++test_ctxtptr->test_stats[CM_TEST_PASSED]; \
return CM_TEST_PASSED; \
}
#define CM_TEST_FAIL(TI) \
{ \
fprintf(stderr, " FAILED at %s:%d\n", __FILE__, __LINE__); \
if (test_ctxtptr->current != NULL) { \
fprintf(stderr, " [%s]\n", test_ctxtptr->current); } \
++test_ctxtptr->test_stats[CM_TEST_FAILED]; \
return CM_TEST_FAILED; \
}
#define CM_TEST_ABORT(TI) \
{ \
fprintf(stderr, " ABORTED at %s:%d\n", __FILE__, __LINE__); \
if (test_ctxtptr->current != NULL) { \
fprintf(stderr, " [%s]\n", test_ctxtptr->current); } \
++test_ctxtptr->test_stats[CM_TEST_ABORTED]; \
return CM_TEST_ABORTED; \
}
int cm_run_tests();
/** @} */
#endif /* _CMTEST_H */
/*
* (C)Copyright 2006-2024, RW Penney
*/