~ubuntu-branches/ubuntu/maverick/ncbi-tools6/maverick

« back to all changes in this revision

Viewing changes to connect/test/test_assert.h

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef TEST_ASSERT__H
 
2
#define TEST_ASSERT__H
 
3
 
 
4
/*  $Id: test_assert.h,v 6.22 2004/06/10 19:20:27 ivanov 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
#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
static int _SuppressDiagPopupMessages(void)
 
61
{
 
62
    /* Check environment variable for silent abort app at error */
 
63
    const char* value = getenv("DIAG_SILENT_ABORT");
 
64
    if (value  &&  (*value == 'Y'  ||  *value == 'y')) {
 
65
        /* Windows GPF errors */
 
66
        SetErrorMode(SEM_NOGPFAULTERRORBOX);
 
67
 
 
68
        /* Runtime library */
 
69
        _set_error_mode(_OUT_TO_STDERR);
 
70
 
 
71
        /* Debug library */
 
72
        _CrtSetReportFile(_CRT_WARN,   stderr);
 
73
        _CrtSetReportMode(_CRT_WARN,   _CRTDBG_MODE_FILE);
 
74
        _CrtSetReportFile(_CRT_ERROR,  stderr);
 
75
        _CrtSetReportMode(_CRT_ERROR,  _CRTDBG_MODE_FILE);
 
76
        _CrtSetReportFile(_CRT_ASSERT, stderr);
 
77
        _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
 
78
    }
 
79
    return 0;
 
80
}
 
81
 
 
82
/* Put this function at startup init level 'V', far enough not to mess up with
 
83
 * base RTL init, which happens at preceding levels in alphabetical order.
 
84
 */
 
85
#  pragma data_seg(".CRT$XIV")
 
86
 
 
87
static int (*_SDPM)(void) = _SuppressDiagPopupMessages;
 
88
 
 
89
#  pragma data_seg()
 
90
 
 
91
#endif /*defined(NCBI_OS_...)*/
 
92
 
 
93
 
 
94
#ifdef   NDEBUG
 
95
#  undef NDEBUG
 
96
#endif
 
97
#ifdef   assert
 
98
#  undef assert
 
99
#endif
 
100
 
 
101
/* IRIX stdlib fix (MIPSpro compiler tested): assert.h already included above*/
 
102
#ifdef NCBI_OS_IRIX
 
103
#  ifdef   __ASSERT_H__
 
104
#    undef __ASSERT_H__
 
105
#  endif
 
106
#endif
 
107
 
 
108
/* Likewise on OSF/1 (at least with GCC 3, but this never hurts) */
 
109
#ifdef NCBI_OS_OSF1
 
110
#  ifdef   _ASSERT_H_
 
111
#    undef _ASSERT_H_
 
112
#  endif
 
113
#endif
 
114
 
 
115
/* ...and on Darwin (at least with GCC 3, but this never hurts) */
 
116
#ifdef NCBI_OS_DARWIN
 
117
#  ifdef   FIXINC_BROKEN_ASSERT_STDLIB_CHECK
 
118
#    undef FIXINC_BROKEN_ASSERT_STDLIB_CHECK
 
119
#  endif
 
120
#endif
 
121
 
 
122
#include <assert.h>
 
123
 
 
124
#ifdef   _ASSERT
 
125
#  undef _ASSERT
 
126
#endif
 
127
#define  _ASSERT assert
 
128
 
 
129
 
 
130
/*
 
131
 * --------------------------------------------------------------------------
 
132
 * $Log: test_assert.h,v $
 
133
 * Revision 6.22  2004/06/10 19:20:27  ivanov
 
134
 * _SuppressDiagPopupMessages() returns 'int' to avoid runtime errors on MSVC7
 
135
 *
 
136
 * Revision 6.21  2003/03/12 21:25:19  lavr
 
137
 * More elaborate conditional branch for Mac's Codewarrior
 
138
 *
 
139
 * Revision 6.20  2003/03/12 20:54:45  lavr
 
140
 * Add NCBI_OS_MAC branch and sync include/test and connect/test locations
 
141
 *
 
142
 * ===========================================================================
 
143
 */
 
144
 
 
145
#endif  /* TEST_ASSERT__H */