COIN-OR::LEMON - Graph Library

source: lemon/test/error_test.cc @ 223:cfadfeef706f

Last change on this file since 223:cfadfeef706f was 223:cfadfeef706f, checked in by Alpar Juttner <alpar@…>, 16 years ago

Fix compilation error when NDEBUG is defined.

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