~ubuntu-branches/ubuntu/edgy/ncbi-tools6/edgy

« back to all changes in this revision

Viewing changes to connect/test/test_assert.h

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-07-19 23:28:07 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060719232807-et3cdmcjgmnyleyx
Tags: 6.1.20060507-3ubuntu1
Re-merge with Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#ifndef TEST_ASSERT__H
2
2
#define TEST_ASSERT__H
3
3
 
4
 
/*  $Id: test_assert.h,v 6.25 2005/04/07 16:27:30 ivanov Exp $
 
4
/*  $Id: test_assert.h,v 6.28 2006/03/07 19:55:43 lavr Exp $
5
5
 * ===========================================================================
6
6
 *
7
7
 *                            PUBLIC DOMAIN NOTICE
31
31
 * File Description:
32
32
 *   Setup #NDEBUG and #_DEBUG preprocessor macro in a way that ASSERTs
33
33
 *   will be active even in the "Release" mode (it's useful for test apps).
 
34
 *   Special wrapper for shared CONNECT library use in both C and C++ tkits.
34
35
 *
35
36
 */
36
37
 
37
38
#include "../ncbi_config.h"
38
 
 
39
 
 
40
 
#if defined(NCBI_OS_MAC) || \
41
 
   (defined(NCBI_OS_DARWIN) && defined(NCBI_COMPILER_METROWERKS))
42
 
#  include <stdio.h>
43
 
#  include <stdlib.h>
44
 
 
45
 
#elif defined(NCBI_OS_MSWIN)
46
 
#  ifdef   _ASSERT
47
 
#    undef _ASSERT
48
 
#  endif
49
 
#  define  Type aType
50
 
#  include <crtdbg.h>
51
 
#  include <stdio.h>
52
 
#  include <windows.h>
53
 
#  undef   Type
54
 
 
55
 
/* Suppress popup messages on execution errors.
56
 
 * NOTE: Windows-specific, suppresses all error message boxes in both runtime
57
 
 * and in debug libraries, as well as all General Protection Fault messages.
58
 
 * Environment variable DIAG_SILENT_ABORT must be set to "Y" or "y".
59
 
 */
60
 
 
61
 
/* Handler for "Unhandled" exceptions */
62
 
static LONG CALLBACK _SEH_Handler(EXCEPTION_POINTERS* ep)
63
 
{
64
 
    /* Always terminate a program */
65
 
    return EXCEPTION_EXECUTE_HANDLER;
66
 
}
67
 
 
68
 
static int _SuppressDiagPopupMessages(void)
69
 
{
70
 
    /* Check environment variable for silent abort app at error */
71
 
    const char* value = getenv("DIAG_SILENT_ABORT");
72
 
    if (value  &&  (*value == 'Y'  ||  *value == 'y')) {
73
 
        /* Windows GPF errors */
74
 
        SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
75
 
                     SEM_NOOPENFILEERRORBOX);
76
 
 
77
 
        /* Runtime library */
78
 
        _set_error_mode(_OUT_TO_STDERR);
79
 
 
80
 
        /* Debug library */
81
 
        _CrtSetReportFile(_CRT_WARN,   _CRTDBG_FILE_STDERR);
82
 
        _CrtSetReportMode(_CRT_WARN,   _CRTDBG_MODE_FILE);
83
 
        _CrtSetReportFile(_CRT_ERROR,  _CRTDBG_FILE_STDERR);
84
 
        _CrtSetReportMode(_CRT_ERROR,  _CRTDBG_MODE_FILE);
85
 
        _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
86
 
        _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
87
 
 
88
 
        /* Exceptions */
89
 
        SetUnhandledExceptionFilter(_SEH_Handler);
90
 
    }
91
 
    return 0;
92
 
}
93
 
 
94
 
/* Put this function at startup init level 'V', far enough not to mess up with
95
 
 * base RTL init, which happens at preceding levels in alphabetical order.
96
 
 */
97
 
#  pragma data_seg(".CRT$XIV")
98
 
 
99
 
static int (*_SDPM)(void) = _SuppressDiagPopupMessages;
100
 
 
101
 
#  pragma data_seg()
102
 
 
103
 
#endif /*defined(NCBI_OS_...)*/
104
 
 
105
 
 
106
 
#ifdef   NDEBUG
107
 
#  undef NDEBUG
108
 
#endif
109
 
#ifdef   assert
110
 
#  undef assert
111
 
#endif
112
 
 
113
 
/* IRIX stdlib fix (MIPSpro compiler tested): assert.h already included above*/
114
 
#ifdef NCBI_OS_IRIX
115
 
#  ifdef   __ASSERT_H__
116
 
#    undef __ASSERT_H__
117
 
#  endif
118
 
#endif
119
 
 
120
 
/* Likewise on OSF/1 (at least with GCC 3, but this never hurts) */
121
 
#ifdef NCBI_OS_OSF1
122
 
#  ifdef   _ASSERT_H_
123
 
#    undef _ASSERT_H_
124
 
#  endif
125
 
#endif
126
 
 
127
 
/* ...and on Darwin (at least with GCC 3, but this never hurts) */
128
 
#ifdef NCBI_OS_DARWIN
129
 
#  ifdef   FIXINC_BROKEN_ASSERT_STDLIB_CHECK
130
 
#    undef FIXINC_BROKEN_ASSERT_STDLIB_CHECK
131
 
#  endif
132
 
#endif
133
 
 
134
 
#include <assert.h>
135
 
 
136
 
#ifdef   _ASSERT
137
 
#  undef _ASSERT
138
 
#endif
139
 
#define  _ASSERT assert
140
 
 
141
 
 
142
 
/*
143
 
 * --------------------------------------------------------------------------
144
 
 * $Log: test_assert.h,v $
145
 
 * Revision 6.25  2005/04/07 16:27:30  ivanov
146
 
 * _SuppressDiagPopupMessages(): added handling of "Unhandled" exceptions
147
 
 *
148
 
 * Revision 6.24  2005/02/22 19:49:55  ivanov
149
 
 * Added more suppress modes for SetErrorMode()
150
 
 *
151
 
 * Revision 6.23  2004/12/21 03:44:42  lavr
152
 
 * Fix CRT report file destination, _CRTDBG_FILE_STDERR not stderr!
153
 
 *
154
 
 * Revision 6.22  2004/06/10 19:20:27  ivanov
155
 
 * _SuppressDiagPopupMessages() returns 'int' to avoid runtime errors on MSVC7
156
 
 *
157
 
 * Revision 6.21  2003/03/12 21:25:19  lavr
158
 
 * More elaborate conditional branch for Mac's Codewarrior
159
 
 *
160
 
 * Revision 6.20  2003/03/12 20:54:45  lavr
161
 
 * Add NCBI_OS_MAC branch and sync include/test and connect/test locations
162
 
 *
163
 
 * ===========================================================================
164
 
 */
 
39
#include "test_assert_impl.h"
165
40
 
166
41
#endif  /* TEST_ASSERT__H */