alpar@209: /* -*- mode: C++; indent-tabs-mode: nil; -*-
kpeter@66:  *
alpar@209:  * This file is a part of LEMON, a generic C++ optimization library.
kpeter@66:  *
alpar@440:  * Copyright (C) 2003-2009
kpeter@66:  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
kpeter@66:  * (Egervary Research Group on Combinatorial Optimization, EGRES).
kpeter@66:  *
kpeter@66:  * Permission to use, modify and distribute this software is granted
kpeter@66:  * provided that this copyright notice appears in all copies. For
kpeter@66:  * precise terms see the accompanying LICENSE file.
kpeter@66:  *
kpeter@66:  * This software is provided "AS IS" with no warranty of any kind,
kpeter@66:  * express or implied, and with no claim as to its suitability for any
kpeter@66:  * purpose.
kpeter@66:  *
kpeter@66:  */
kpeter@66: 
kpeter@66: #include <iostream>
kpeter@66: 
kpeter@66: #include <lemon/error.h>
kpeter@66: #include "test_tools.h"
kpeter@66: 
kpeter@66: using namespace lemon;
kpeter@66: 
deba@108: #ifdef LEMON_ENABLE_ASSERTS
deba@108: #undef LEMON_ENABLE_ASSERTS
deba@108: #endif
deba@108: 
deba@108: #ifdef LEMON_DISABLE_ASSERTS
deba@108: #undef LEMON_DISABLE_ASSERTS
deba@108: #endif
deba@108: 
alpar@223: #ifdef NDEBUG
alpar@223: #undef NDEBUG
alpar@223: #endif
alpar@223: 
deba@108: //checking disabled asserts
deba@108: #define LEMON_DISABLE_ASSERTS
deba@108: #include <lemon/assert.h>
deba@108: 
deba@108: void no_assertion_text_disable() {
deba@108:   LEMON_ASSERT(true, "This is a fault message");
kpeter@66: }
kpeter@66: 
deba@108: void assertion_text_disable() {
deba@108:   LEMON_ASSERT(false, "This is a fault message");
kpeter@66: }
kpeter@66: 
deba@108: void check_assertion_disable() {
deba@108:   no_assertion_text_disable();
deba@108:   assertion_text_disable();
deba@108: }
deba@108: #undef LEMON_DISABLE_ASSERTS
deba@108: 
kpeter@171: //checking custom assert handler
deba@108: #define LEMON_ASSERT_CUSTOM
deba@108: 
deba@108: static int cnt = 0;
alpar@209: void my_assert_handler(const char*, int, const char*,
alpar@209:                        const char*, const char*) {
deba@108:   ++cnt;
deba@108: }
deba@108: 
deba@108: #define LEMON_CUSTOM_ASSERT_HANDLER my_assert_handler
deba@108: #include <lemon/assert.h>
deba@108: 
deba@108: void no_assertion_text_custom() {
deba@108:   LEMON_ASSERT(true, "This is a fault message");
deba@108: }
deba@108: 
deba@108: void assertion_text_custom() {
deba@108:   LEMON_ASSERT(false, "This is a fault message");
deba@108: }
deba@108: 
deba@108: void check_assertion_custom() {
deba@108:   no_assertion_text_custom();
deba@108:   assertion_text_custom();
deba@277:   check(cnt == 1, "The custom assert handler does not work");
deba@108: }
deba@108: 
deba@108: #undef LEMON_ASSERT_CUSTOM
deba@108: 
deba@108: 
deba@108: int main() {
deba@108:   check_assertion_disable();
deba@108:   check_assertion_custom();
deba@108: 
kpeter@66:   return 0;
kpeter@66: }