| 1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
| 2 | 2 |
* |
| 3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
| 4 | 4 |
* |
| 5 | 5 |
* Copyright (C) 2003-2008 |
| 6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
| 7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
| 8 | 8 |
* |
| 9 | 9 |
* Permission to use, modify and distribute this software is granted |
| 10 | 10 |
* provided that this copyright notice appears in all copies. For |
| 11 | 11 |
* precise terms see the accompanying LICENSE file. |
| 12 | 12 |
* |
| 13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
| 14 | 14 |
* express or implied, and with no claim as to its suitability for any |
| 15 | 15 |
* purpose. |
| 16 | 16 |
* |
| 17 | 17 |
*/ |
| 18 | 18 |
|
| 19 | 19 |
#include <iostream> |
| 20 | 20 |
|
| 21 | 21 |
#include <lemon/error.h> |
| 22 | 22 |
#include "test_tools.h" |
| 23 | 23 |
|
| 24 | 24 |
using namespace lemon; |
| 25 | 25 |
|
| 26 | 26 |
#ifdef LEMON_ENABLE_ASSERTS |
| 27 | 27 |
#undef LEMON_ENABLE_ASSERTS |
| 28 | 28 |
#endif |
| 29 | 29 |
|
| 30 | 30 |
#ifdef LEMON_DISABLE_ASSERTS |
| 31 | 31 |
#undef LEMON_DISABLE_ASSERTS |
| 32 | 32 |
#endif |
| 33 | 33 |
|
| 34 |
#ifdef NDEBUG |
|
| 35 |
#undef NDEBUG |
|
| 36 |
#endif |
|
| 37 |
|
|
| 34 | 38 |
//checking disabled asserts |
| 35 | 39 |
#define LEMON_DISABLE_ASSERTS |
| 36 | 40 |
#include <lemon/assert.h> |
| 37 | 41 |
|
| 38 | 42 |
void no_assertion_text_disable() {
|
| 39 | 43 |
LEMON_ASSERT(true, "This is a fault message"); |
| 40 | 44 |
} |
| 41 | 45 |
|
| 42 | 46 |
void assertion_text_disable() {
|
| 43 | 47 |
LEMON_ASSERT(false, "This is a fault message"); |
| 44 | 48 |
} |
| 45 | 49 |
|
| 46 | 50 |
void fixme_disable() {
|
| 47 | 51 |
LEMON_FIXME("fixme_disable() is fixme!");
|
| 48 | 52 |
} |
| 49 | 53 |
|
| 50 | 54 |
void check_assertion_disable() {
|
| 51 | 55 |
no_assertion_text_disable(); |
| 52 | 56 |
assertion_text_disable(); |
| 53 | 57 |
fixme_disable(); |
| 54 | 58 |
} |
| 55 | 59 |
#undef LEMON_DISABLE_ASSERTS |
| 56 | 60 |
|
| 57 | 61 |
//checking custom assert handler |
| 58 | 62 |
#define LEMON_ASSERT_CUSTOM |
| 59 | 63 |
|
| 60 | 64 |
static int cnt = 0; |
| 61 | 65 |
void my_assert_handler(const char*, int, const char*, |
| 62 | 66 |
const char*, const char*) {
|
| 63 | 67 |
++cnt; |
| 64 | 68 |
} |
| 65 | 69 |
|
| 66 | 70 |
#define LEMON_CUSTOM_ASSERT_HANDLER my_assert_handler |
| 67 | 71 |
#include <lemon/assert.h> |
| 68 | 72 |
|
| 69 | 73 |
void no_assertion_text_custom() {
|
| 70 | 74 |
LEMON_ASSERT(true, "This is a fault message"); |
| 71 | 75 |
} |
| 72 | 76 |
|
| 73 | 77 |
void assertion_text_custom() {
|
| 74 | 78 |
LEMON_ASSERT(false, "This is a fault message"); |
| 75 | 79 |
} |
| 76 | 80 |
|
| 77 | 81 |
void fixme_custom() {
|
| 78 | 82 |
LEMON_FIXME("fixme_custom() is fixme!");
|
| 79 | 83 |
} |
| 80 | 84 |
|
| 81 | 85 |
void check_assertion_custom() {
|
| 82 | 86 |
no_assertion_text_custom(); |
| 83 | 87 |
assertion_text_custom(); |
| 84 | 88 |
fixme_custom(); |
| 85 | 89 |
check(cnt == 2, "The custom assert handler does not work"); |
| 86 | 90 |
} |
| 87 | 91 |
|
| 88 | 92 |
#undef LEMON_ASSERT_CUSTOM |
| 89 | 93 |
|
| 90 | 94 |
|
| 91 | 95 |
int main() {
|
| 92 | 96 |
check_assertion_disable(); |
| 93 | 97 |
check_assertion_custom(); |
| 94 | 98 |
|
| 95 | 99 |
return 0; |
| 96 | 100 |
} |
0 comments (0 inline)