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

« back to all changes in this revision

Viewing changes to connect/test/test_assert_impl.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
#ifndef TEST_ASSERT_IMPL__H
 
2
#define TEST_ASSERT_IMPL__H
 
3
 
 
4
/*  $Id: test_assert_impl.h,v 1.1 2006/03/07 18:22:09 lavr Exp $
 
5
 * ===========================================================================
 
6
 *
 
7
 *                            PUBLIC DOMAIN NOTICE
 
8
 *               National Center for Biotechnology Information
 
9
 *
 
10
 *  This software/database is a "United States Government Work" under the
 
11
 *  terms of the United States Copyright Act.  It was written as part of
 
12
 *  the author's official duties as a United States Government employee and
 
13
 *  thus cannot be copyrighted.  This software/database is freely available
 
14
 *  to the public for use. The National Library of Medicine and the U.S.
 
15
 *  Government have not placed any restriction on its use or reproduction.
 
16
 *
 
17
 *  Although all reasonable efforts have been taken to ensure the accuracy
 
18
 *  and reliability of the software and data, the NLM and the U.S.
 
19
 *  Government do not and cannot warrant the performance or results that
 
20
 *  may be obtained by using this software or data. The NLM and the U.S.
 
21
 *  Government disclaim all warranties, express or implied, including
 
22
 *  warranties of performance, merchantability or fitness for any particular
 
23
 *  purpose.
 
24
 *
 
25
 *  Please cite the author in any work or product based on this material.
 
26
 *
 
27
 * ===========================================================================
 
28
 *
 
29
 * Author:  Denis Vakatov
 
30
 *
 
31
 * File Description:
 
32
 *   Setup #NDEBUG and #_DEBUG preprocessor macro in a way that ASSERTs
 
33
 *   will be active even in the "Release" mode (it's useful for test apps).
 
34
 *
 
35
 */
 
36
 
 
37
#ifndef TEST_ASSERT__H
 
38
#  error "Must not use this header alone, but from a proper wrapper."
 
39
#endif /*TEST_ASSERT__H*/
 
40
 
 
41
#if defined(NCBI_OS_MAC) || \
 
42
   (defined(NCBI_OS_DARWIN) && defined(NCBI_COMPILER_METROWERKS))
 
43
#  include <stdio.h>
 
44
#  include <stdlib.h>
 
45
 
 
46
#elif defined(NCBI_OS_MSWIN)
 
47
#  ifdef   _ASSERT
 
48
#    undef _ASSERT
 
49
#  endif
 
50
#  define  Type aType
 
51
#  include <crtdbg.h>
 
52
#  include <stdio.h>
 
53
#  include <windows.h>
 
54
#  undef   Type
 
55
 
 
56
/* Suppress popup messages on execution errors.
 
57
 * NOTE: Windows-specific, suppresses all error message boxes in both runtime
 
58
 * and in debug libraries, as well as all General Protection Fault messages.
 
59
 * Environment variable DIAG_SILENT_ABORT must be set to "Y" or "y".
 
60
 */
 
61
 
 
62
/* Handler for "Unhandled" exceptions */
 
63
static LONG CALLBACK _SEH_Handler(EXCEPTION_POINTERS* ep)
 
64
{
 
65
    /* Always terminate a program */
 
66
    return EXCEPTION_EXECUTE_HANDLER;
 
67
}
 
68
 
 
69
static int _SuppressDiagPopupMessages(void)
 
70
{
 
71
    /* Check environment variable for silent abort app at error */
 
72
    const char* value = getenv("DIAG_SILENT_ABORT");
 
73
    if (value  &&  (*value == 'Y'  ||  *value == 'y')) {
 
74
        /* Windows GPF errors */
 
75
        SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
 
76
                     SEM_NOOPENFILEERRORBOX);
 
77
 
 
78
        /* Runtime library */
 
79
        _set_error_mode(_OUT_TO_STDERR);
 
80
 
 
81
        /* Debug library */
 
82
        _CrtSetReportFile(_CRT_WARN,   _CRTDBG_FILE_STDERR);
 
83
        _CrtSetReportMode(_CRT_WARN,   _CRTDBG_MODE_FILE);
 
84
        _CrtSetReportFile(_CRT_ERROR,  _CRTDBG_FILE_STDERR);
 
85
        _CrtSetReportMode(_CRT_ERROR,  _CRTDBG_MODE_FILE);
 
86
        _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
 
87
        _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
 
88
 
 
89
        /* Exceptions */
 
90
        SetUnhandledExceptionFilter(_SEH_Handler);
 
91
    }
 
92
    return 0;
 
93
}
 
94
 
 
95
/* Put this function at startup init level 'V', far enough not to mess up with
 
96
 * base RTL init, which happens at preceding levels in alphabetical order.
 
97
 */
 
98
#  if _MSC_VER >= 1400
 
99
#    pragma section( ".CRT$XIV", read)
 
100
#  endif
 
101
#  pragma data_seg(".CRT$XIV")
 
102
static int (*_SDPM)(void) = _SuppressDiagPopupMessages;
 
103
#  pragma data_seg()
 
104
 
 
105
#endif /*defined(NCBI_OS_...)*/
 
106
 
 
107
 
 
108
#ifdef   NDEBUG
 
109
#  undef NDEBUG
 
110
#endif
 
111
#ifdef   assert
 
112
#  undef assert
 
113
#endif
 
114
 
 
115
/* IRIX stdlib fix (MIPSpro compiler tested): assert.h already included above*/
 
116
#ifdef NCBI_OS_IRIX
 
117
#  ifdef   __ASSERT_H__
 
118
#    undef __ASSERT_H__
 
119
#  endif
 
120
#endif
 
121
 
 
122
/* Likewise on OSF/1 (at least with GCC 3, but this never hurts) */
 
123
#ifdef NCBI_OS_OSF1
 
124
#  ifdef   _ASSERT_H_
 
125
#    undef _ASSERT_H_
 
126
#  endif
 
127
#endif
 
128
 
 
129
/* ...and on Darwin (at least with GCC 3, but this never hurts) */
 
130
#ifdef NCBI_OS_DARWIN
 
131
#  ifdef   FIXINC_BROKEN_ASSERT_STDLIB_CHECK
 
132
#    undef FIXINC_BROKEN_ASSERT_STDLIB_CHECK
 
133
#  endif
 
134
#endif
 
135
 
 
136
#include <assert.h>
 
137
 
 
138
#ifdef   _ASSERT
 
139
#  undef _ASSERT
 
140
#endif
 
141
#define  _ASSERT assert
 
142
 
 
143
 
 
144
/*
 
145
 * --------------------------------------------------------------------------
 
146
 * $Log: test_assert_impl.h,v $
 
147
 * Revision 1.1  2006/03/07 18:22:09  lavr
 
148
 * Initial revision
 
149
 *
 
150
 * ===========================================================================
 
151
 */
 
152
 
 
153
#endif  /* TEST_ASSERT_IMPL__H */