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