test/error_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Tue, 24 Feb 2009 06:52:17 +0000
changeset 536 97674155c135
parent 277 7abfb55f1ecc
permissions -rw-r--r--
Merge
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
 *
alpar@440
     5
 * Copyright (C) 2003-2009
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 check_assertion_disable() {
deba@108
    51
  no_assertion_text_disable();
deba@108
    52
  assertion_text_disable();
deba@108
    53
}
deba@108
    54
#undef LEMON_DISABLE_ASSERTS
deba@108
    55
kpeter@171
    56
//checking custom assert handler
deba@108
    57
#define LEMON_ASSERT_CUSTOM
deba@108
    58
deba@108
    59
static int cnt = 0;
alpar@209
    60
void my_assert_handler(const char*, int, const char*,
alpar@209
    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 check_assertion_custom() {
deba@108
    77
  no_assertion_text_custom();
deba@108
    78
  assertion_text_custom();
deba@277
    79
  check(cnt == 1, "The custom assert handler does not work");
deba@108
    80
}
deba@108
    81
deba@108
    82
#undef LEMON_ASSERT_CUSTOM
deba@108
    83
deba@108
    84
deba@108
    85
int main() {
deba@108
    86
  check_assertion_disable();
deba@108
    87
  check_assertion_custom();
deba@108
    88
kpeter@66
    89
  return 0;
kpeter@66
    90
}