Botan
1.11.15
|
00001 /* 00002 * Runtime assertion checking 00003 * (C) 2010 Jack Lloyd 00004 * 00005 * Botan is released under the Simplified BSD License (see license.txt) 00006 */ 00007 00008 #ifndef BOTAN_ASSERTION_CHECKING_H__ 00009 #define BOTAN_ASSERTION_CHECKING_H__ 00010 00011 #include <botan/build.h> 00012 00013 namespace Botan { 00014 00015 /** 00016 * Called when an assertion fails 00017 */ 00018 void BOTAN_DLL assertion_failure(const char* expr_str, 00019 const char* assertion_made, 00020 const char* func, 00021 const char* file, 00022 int line); 00023 00024 /** 00025 * Make an assertion 00026 */ 00027 #define BOTAN_ASSERT(expr, assertion_made) \ 00028 do { \ 00029 if(!(expr)) \ 00030 Botan::assertion_failure(#expr, \ 00031 assertion_made, \ 00032 BOTAN_CURRENT_FUNCTION, \ 00033 __FILE__, \ 00034 __LINE__); \ 00035 } while(0) 00036 00037 /** 00038 * Assert that value1 == value2 00039 */ 00040 #define BOTAN_ASSERT_EQUAL(expr1, expr2, assertion_made) \ 00041 do { \ 00042 if((expr1) != (expr2)) \ 00043 Botan::assertion_failure(#expr1 " == " #expr2, \ 00044 assertion_made, \ 00045 BOTAN_CURRENT_FUNCTION, \ 00046 __FILE__, \ 00047 __LINE__); \ 00048 } while(0) 00049 00050 /** 00051 * Assert that expr1 (if true) implies expr2 is also true 00052 */ 00053 #define BOTAN_ASSERT_IMPLICATION(expr1, expr2, msg) \ 00054 do { \ 00055 if((expr1) && !(expr2)) \ 00056 Botan::assertion_failure(#expr1 " implies " #expr2, \ 00057 msg, \ 00058 BOTAN_CURRENT_FUNCTION, \ 00059 __FILE__, \ 00060 __LINE__); \ 00061 } while(0) 00062 00063 /** 00064 * Assert that a pointer is not null 00065 */ 00066 #define BOTAN_ASSERT_NONNULL(ptr) \ 00067 do { \ 00068 if(static_cast<bool>(ptr) == false) \ 00069 Botan::assertion_failure(#ptr " is not null", \ 00070 "", \ 00071 BOTAN_CURRENT_FUNCTION, \ 00072 __FILE__, \ 00073 __LINE__); \ 00074 } while(0) 00075 00076 /** 00077 * Mark variable as unused 00078 */ 00079 #define BOTAN_UNUSED(v) static_cast<void>(v) 00080 00081 } 00082 00083 #endif