test/error_test.cc
author Balazs Dezso <deba@inf.elte.hu>
Thu, 10 Jul 2008 16:05:56 +0200
changeset 200 c0e2c043c060
parent 118 407c08a0eae9
child 209 765619b7cbb2
permissions -rw-r--r--
Porting graph_copy_test.cc from SVN 3498
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
kpeter@171
    57
//checking custom assert handler
deba@108
    58
#define LEMON_ASSERT_CUSTOM
deba@108
    59
deba@108
    60
static int cnt = 0;
deba@108
    61
void my_assert_handler(const char*, int, const char*, 
deba@108
    62
		       const char*, const char*) {
deba@108
    63
  ++cnt;
deba@108
    64
}
deba@108
    65
deba@108
    66
#define LEMON_CUSTOM_ASSERT_HANDLER my_assert_handler
deba@108
    67
#include <lemon/assert.h>
deba@108
    68
deba@108
    69
void no_assertion_text_custom() {
deba@108
    70
  LEMON_ASSERT(true, "This is a fault message");
deba@108
    71
}
deba@108
    72
deba@108
    73
void assertion_text_custom() {
deba@108
    74
  LEMON_ASSERT(false, "This is a fault message");
deba@108
    75
}
deba@108
    76
deba@108
    77
void fixme_custom() {
deba@108
    78
  LEMON_FIXME("fixme_custom() is fixme!");
deba@108
    79
}
deba@108
    80
deba@108
    81
void check_assertion_custom() {
deba@108
    82
  no_assertion_text_custom();
deba@108
    83
  assertion_text_custom();
deba@108
    84
  fixme_custom();
deba@118
    85
  check(cnt == 2, "The custom assert handler does not work");
deba@108
    86
}
deba@108
    87
deba@108
    88
#undef LEMON_ASSERT_CUSTOM
deba@108
    89
deba@108
    90
deba@108
    91
int main() {
deba@108
    92
  check_assertion_disable();
deba@108
    93
  check_assertion_custom();
deba@108
    94
kpeter@66
    95
  return 0;
kpeter@66
    96
}