include/common/test_assert_impl.h

Go to the documentation of this file.
00001 #ifndef COMMON__TEST_ASSERT_IMPL__H
00002 #define COMMON__TEST_ASSERT_IMPL__H
00003 
00004 /* $Id: test_assert_impl.h 171076 2009-09-21 16:22:34Z ivanov $
00005  * ===========================================================================
00006  *
00007  *                            PUBLIC DOMAIN NOTICE
00008  *               National Center for Biotechnology Information
00009  *
00010  *  This software/database is a "United States Government Work" under the
00011  *  terms of the United States Copyright Act.  It was written as part of
00012  *  the author's official duties as a United States Government employee and
00013  *  thus cannot be copyrighted.  This software/database is freely available
00014  *  to the public for use. The National Library of Medicine and the U.S.
00015  *  Government have not placed any restriction on its use or reproduction.
00016  *
00017  *  Although all reasonable efforts have been taken to ensure the accuracy
00018  *  and reliability of the software and data, the NLM and the U.S.
00019  *  Government do not and cannot warrant the performance or results that
00020  *  may be obtained by using this software or data. The NLM and the U.S.
00021  *  Government disclaim all warranties, express or implied, including
00022  *  warranties of performance, merchantability or fitness for any particular
00023  *  purpose.
00024  *
00025  *  Please cite the author in any work or product based on this material.
00026  *
00027  * ===========================================================================
00028  *
00029  * Author:  Denis Vakatov
00030  *
00031  * File Description:
00032  *   Setup #NDEBUG and #_DEBUG preprocessor macro in a way that ASSERTs
00033  *   will be active even in the "Release" mode (it's useful for test apps).
00034  *
00035  */
00036 
00037 #ifndef TEST_ASSERT__H
00038 #  error "Must not use this header alone, but from a proper wrapper."
00039 #endif /*TEST_ASSERT__H*/
00040 
00041 #if defined(NCBI_OS_MSWIN)
00042 #  ifndef NCBI_MSWIN_NO_POPUP
00043 #    ifdef   _ASSERT
00044 #      undef _ASSERT
00045 #    endif
00046 #    define  Type aType
00047 #  endif
00048 #  include <crtdbg.h>
00049 #  include <stdio.h>
00050 #  include <windows.h>
00051 #  ifndef NCBI_MSWIN_NO_POPUP
00052 #    undef   Type
00053 #  endif
00054 
00055 /* Suppress popup messages on execution errors.
00056  * NOTE: Windows-specific, suppresses all error message boxes in both runtime
00057  * and in debug libraries, as well as all General Protection Fault messages.
00058  * Environment variable DIAG_SILENT_ABORT must be set to "Y" or "y".
00059  */
00060 
00061 /* Handler for "Unhandled" exceptions */
00062 static LONG CALLBACK _SEH_Handler(EXCEPTION_POINTERS* ep)
00063 {
00064     /* Always terminate a program */
00065     return EXCEPTION_EXECUTE_HANDLER;
00066 }
00067 
00068 static int _SuppressDiagPopupMessages(void)
00069 {
00070 #ifndef NCBI_MSWIN_NO_POPUP_EVER
00071     /* Check environment variable for silent abort app at error */
00072     const char* value = getenv("DIAG_SILENT_ABORT");
00073     if (value  &&  (*value == 'Y'  ||  *value == 'y')) {
00074 #endif
00075         /* Windows GPF errors */
00076         SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
00077                      SEM_NOOPENFILEERRORBOX);
00078 
00079         /* Runtime library */
00080         _set_error_mode(_OUT_TO_STDERR);
00081 
00082         /* Debug library */
00083         _CrtSetReportFile(_CRT_WARN,   _CRTDBG_FILE_STDERR);
00084         _CrtSetReportMode(_CRT_WARN,   _CRTDBG_MODE_FILE);
00085         _CrtSetReportFile(_CRT_ERROR,  _CRTDBG_FILE_STDERR);
00086         _CrtSetReportMode(_CRT_ERROR,  _CRTDBG_MODE_FILE);
00087         _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
00088         _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
00089 
00090         /* Exceptions */
00091         SetUnhandledExceptionFilter(_SEH_Handler);
00092 #ifndef NCBI_MSWIN_NO_POPUP_EVER
00093     }
00094 #endif
00095     return 0;
00096 }
00097 
00098 /* Put this function at startup init level 'V', far enough not to mess up with
00099  * base RTL init, which happens at preceding levels in alphabetical order.
00100  */
00101 #  if _MSC_VER >= 1400
00102 #    pragma section(".CRT$XIV", read)
00103 #  endif
00104 #  pragma data_seg(".CRT$XIV")
00105 static int (*_SDPM)(void) = _SuppressDiagPopupMessages;
00106 #  pragma data_seg()
00107 
00108 #endif /*defined(NCBI_OS_...)*/
00109 
00110 
00111 /* Emulate <corelib/mswin_no_popup.h> if specified
00112  */
00113 #ifndef NCBI_MSWIN_NO_POPUP
00114 
00115 #ifdef   NDEBUG
00116 #  undef NDEBUG
00117 #endif
00118 #ifdef   assert
00119 #  undef assert
00120 #endif
00121 
00122 /* IRIX stdlib fix (MIPSpro compiler tested): assert.h already included above*/
00123 #ifdef NCBI_OS_IRIX
00124 #  ifdef   __ASSERT_H__
00125 #    undef __ASSERT_H__
00126 #  endif
00127 #endif
00128 
00129 /* Likewise on OSF/1 (at least with GCC 3, but this never hurts) */
00130 #ifdef NCBI_OS_OSF1
00131 #  ifdef   _ASSERT_H_
00132 #    undef _ASSERT_H_
00133 #  endif
00134 #endif
00135 
00136 /* ...and on Darwin (at least with GCC 3, but this never hurts) */
00137 #ifdef NCBI_OS_DARWIN
00138 #  ifdef   FIXINC_BROKEN_ASSERT_STDLIB_CHECK
00139 #    undef FIXINC_BROKEN_ASSERT_STDLIB_CHECK
00140 #  endif
00141 #endif
00142 
00143 #include <assert.h>
00144 
00145 #ifdef   _ASSERT
00146 #  undef _ASSERT
00147 #endif
00148 #define  _ASSERT assert
00149 
00150 #ifdef   _TROUBLE
00151 #  undef _TROUBLE
00152 #endif
00153 #define  _TROUBLE assert(0)
00154 
00155 #endif /* NCBI_MSWIN_NO_POPUP */
00156 
00157 #endif /* COMMON__TEST_ASSERT_IMPL__H */
00158 
00159 

Generated on Sun Dec 6 21:58:26 2009 for NCBI C++ ToolKit by  doxygen 1.4.6
Modified on Mon Dec 07 16:20:34 2009 by modify_doxy.py rev. 173732