test/error_test.cc
author Akos Ladanyi <ladanyi@tmit.bme.hu>
Sun, 21 Sep 2008 18:23:07 +0100
changeset 274 2a33883915bb
parent 209 765619b7cbb2
child 277 7abfb55f1ecc
permissions -rw-r--r--
Use only a single (cached) variable to hold the version number.
alpar@209
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
kpeter@66
     2
 *
alpar@209
     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
alpar@223
    34
#ifdef NDEBUG
alpar@223
    35
#undef NDEBUG
alpar@223
    36
#endif
alpar@223
    37
deba@108
    38
//checking disabled asserts
deba@108
    39
#define LEMON_DISABLE_ASSERTS
deba@108
    40
#include <lemon/assert.h>
deba@108
    41
deba@108
    42
void no_assertion_text_disable() {
deba@108
    43
  LEMON_ASSERT(true, "This is a fault message");
kpeter@66
    44
}
kpeter@66
    45
deba@108
    46
void assertion_text_disable() {
deba@108
    47
  LEMON_ASSERT(false, "This is a fault message");
kpeter@66
    48
}
kpeter@66
    49
deba@108
    50
void fixme_disable() {
deba@108
    51
  LEMON_FIXME("fixme_disable() is fixme!");
deba@108
    52
}
deba@108
    53
deba@108
    54
void check_assertion_disable() {
deba@108
    55
  no_assertion_text_disable();
deba@108
    56
  assertion_text_disable();
deba@108
    57
  fixme_disable();
deba@108
    58
}
deba@108
    59
#undef LEMON_DISABLE_ASSERTS
deba@108
    60
kpeter@171
    61
//checking custom assert handler
deba@108
    62
#define LEMON_ASSERT_CUSTOM
deba@108
    63
deba@108
    64
static int cnt = 0;
alpar@209
    65
void my_assert_handler(const char*, int, const char*,
alpar@209
    66
                       const char*, const char*) {
deba@108
    67
  ++cnt;
deba@108
    68
}
deba@108
    69
deba@108
    70
#define LEMON_CUSTOM_ASSERT_HANDLER my_assert_handler
deba@108
    71
#include <lemon/assert.h>
deba@108
    72
deba@108
    73
void no_assertion_text_custom() {
deba@108
    74
  LEMON_ASSERT(true, "This is a fault message");
deba@108
    75
}
deba@108
    76
deba@108
    77
void assertion_text_custom() {
deba@108
    78
  LEMON_ASSERT(false, "This is a fault message");
deba@108
    79
}
deba@108
    80
deba@108
    81
void fixme_custom() {
deba@108
    82
  LEMON_FIXME("fixme_custom() is fixme!");
deba@108
    83
}
deba@108
    84
deba@108
    85
void check_assertion_custom() {
deba@108
    86
  no_assertion_text_custom();
deba@108
    87
  assertion_text_custom();
deba@108
    88
  fixme_custom();
deba@118
    89
  check(cnt == 2, "The custom assert handler does not work");
deba@108
    90
}
deba@108
    91
deba@108
    92
#undef LEMON_ASSERT_CUSTOM
deba@108
    93
deba@108
    94
deba@108
    95
int main() {
deba@108
    96
  check_assertion_disable();
deba@108
    97
  check_assertion_custom();
deba@108
    98
kpeter@66
    99
  return 0;
kpeter@66
   100
}