Botan
2.1.0
Crypto and TLS for C++11
Main Page
Namespaces
Classes
Files
File List
File Members
src
lib
utils
assert.h
Go to the documentation of this file.
1
/*
2
* Runtime assertion checking
3
* (C) 2010 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_ASSERTION_CHECKING_H__
9
#define BOTAN_ASSERTION_CHECKING_H__
10
11
#include <botan/build.h>
12
13
namespace
Botan
{
14
15
/**
16
* Called when an assertion fails
17
*/
18
BOTAN_NORETURN
void
BOTAN_DLL
assertion_failure
(
const
char
* expr_str,
19
const
char
* assertion_made,
20
const
char
* func,
21
const
char
* file,
22
int
line);
23
24
/**
25
* Make an assertion
26
*/
27
#define BOTAN_ASSERT(expr, assertion_made) \
28
do { \
29
if(!(expr)) \
30
Botan::assertion_failure(#expr, \
31
assertion_made, \
32
BOTAN_CURRENT_FUNCTION, \
33
__FILE__, \
34
__LINE__); \
35
} while(0)
36
37
/**
38
* Make an assertion
39
*/
40
#define BOTAN_ASSERT_NOMSG(expr) \
41
do { \
42
if(!(expr)) \
43
Botan::assertion_failure(#expr, \
44
"", \
45
BOTAN_CURRENT_FUNCTION, \
46
__FILE__, \
47
__LINE__); \
48
} while(0)
49
50
/**
51
* Assert that value1 == value2
52
*/
53
#define BOTAN_ASSERT_EQUAL(expr1, expr2, assertion_made) \
54
do { \
55
if((expr1) != (expr2)) \
56
Botan::assertion_failure(#expr1 " == " #expr2, \
57
assertion_made, \
58
BOTAN_CURRENT_FUNCTION, \
59
__FILE__, \
60
__LINE__); \
61
} while(0)
62
63
/**
64
* Assert that expr1 (if true) implies expr2 is also true
65
*/
66
#define BOTAN_ASSERT_IMPLICATION(expr1, expr2, msg) \
67
do { \
68
if((expr1) && !(expr2)) \
69
Botan::assertion_failure(#expr1 " implies " #expr2, \
70
msg, \
71
BOTAN_CURRENT_FUNCTION, \
72
__FILE__, \
73
__LINE__); \
74
} while(0)
75
76
/**
77
* Assert that a pointer is not null
78
*/
79
#define BOTAN_ASSERT_NONNULL(ptr) \
80
do { \
81
if((ptr) == nullptr) \
82
Botan::assertion_failure(#ptr " is not null", \
83
"", \
84
BOTAN_CURRENT_FUNCTION, \
85
__FILE__, \
86
__LINE__); \
87
} while(0)
88
89
/**
90
* Mark variable as unused
91
*/
92
#define BOTAN_UNUSED(v) static_cast<void>(v)
93
94
}
95
96
#endif
Botan::assertion_failure
void assertion_failure(const char *expr_str, const char *assertion_made, const char *func, const char *file, int line)
Definition:
assert.cpp:13
Botan
Definition:
alg_id.cpp:13
BOTAN_NORETURN
#define BOTAN_NORETURN
Definition:
compiler.h:94
Generated on Fri Aug 4 2017 19:29:39 for Botan by
1.8.9.1