/[ascend]/trunk/test/assertimpl.c
ViewVC logotype

Annotation of /trunk/test/assertimpl.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 216 - (hide annotations) (download) (as text)
Wed Jan 25 02:12:20 2006 UTC (18 years, 4 months ago) by jds
File MIME type: text/x-csrc
File size: 3516 byte(s)
Minor rework of jam system to stop relinking of libraries when sources not modified.
Minor tweaks to stem the tide of compiler warnings.
1 jds 59 /*
2     * Assert implementation override for ASCEND unit tests
3     *
4     * Copyright (C) 2005 Jerry St.Clair
5     *
6     * This file is part of the Ascend Environment.
7     *
8     * The Ascend Environment is free software; you can redistribute it
9     * and/or modify it under the terms of the GNU General Public License as
10     * published by the Free Software Foundation; either version 2 of the
11     * License, or (at your option) any later version.
12     *
13     * The Ascend Environment is distributed in hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16     * General Public License for more details.
17     *
18     * You should have received a copy of the GNU General Public License
19     * along with the program; if not, write to the Free Software Foundation,
20     * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
21     * COPYING.
22     */
23    
24     #include <stdio.h>
25     #include <stdlib.h>
26     #include <setjmp.h>
27     #include <assert.h>
28     #include "utilities/ascConfig.h"
29     #include "utilities/ascPanic.h"
30     #include "assertimpl.h"
31    
32     enum assert_status_t g_assert_status = ast_passed;
33     jmp_buf g_asc_test_env;
34     static int f_use_longjump = FALSE;
35    
36     void enable_assert_longjmp(int TRUE_or_FALSE)
37     {
38     f_use_longjump = TRUE_or_FALSE;
39     }
40    
41     /* Override implementation of assert using the signature of the relevant compiler */
42 jds 60 #ifdef __WIN32__
43 jds 101 # if defined(__GNUC__) || defined(__MINGW32_VERSION)
44 jds 59 _CRTIMP void __cdecl _assert(const char *cond, const char *file, int line)
45 jds 101 {
46 jds 59
47 jds 101 # elif defined(_MSC_VER)
48 jds 216 # if _MSC_VER < 1400 /* Visual C versions below 14 */
49 jds 59 _CRTIMP void __cdecl _assert(const char *cond, const char *file, unsigned line)
50 jds 101 {
51 jds 216 # else
52     void __cdecl _wassert(__in_z const wchar_t * cond, __in_z const wchar_t *file, __in unsigned line)
53     {
54     # endif /* Visual C version */
55 jds 59
56 jds 101 # elif defined(__BORLANDC__)
57     # ifdef __cplusplus
58 jds 59 namespace std {
59 jds 101 # endif
60 jds 59 void _RTLENTRY _EXPFUNC _assert(char *cond, char *file, int line)
61 jds 101 {
62 jds 59
63 jds 101 # else
64 jds 216 # error Unrecognized Windows compiler.
65 jds 59
66 jds 101 # endif
67 jds 60 #else /* !__WIN32__ */
68 jds 101 # if defined(__GNUC__)
69 jds 60 void __assert_fail (const char *cond, const char *file,
70     unsigned int line, const char *__function)
71     /* __THROW __attribute__ ((__noreturn__)) */
72 jds 101 {
73     UNUSED_PARAMETER(__function);
74    
75     # else
76     # error Unrecognized compiler.
77     # endif
78 jds 60 #endif /* __WIN32__ */
79 jds 101
80 jds 59 g_assert_status = ast_failed;
81     if (TRUE == f_use_longjump) {
82     longjmp(g_asc_test_env, -1);
83     }
84     else {
85     fprintf(stderr, "\nAssertion failed: %s, file %s, line %d\n", cond, file, line);
86     abort();
87     }
88     }
89    
90     #if defined(__BORLANDC__)
91 jds 101 # ifdef __cplusplus
92 jds 59 }
93 jds 101 # endif
94 jds 59 #endif
95    
96     static int f_asc_assert_failed = FALSE;
97    
98     static int assert_callback(int status)
99     {
100     if (ASCERR_ASSERTION_FAILED == status) {
101     f_asc_assert_failed = TRUE;
102     longjmp(g_asc_test_env, -1);
103     }
104     return -1;
105     }
106    
107     int asc_assert_failed()
108     {
109     return f_asc_assert_failed;
110     }
111    
112     void asc_assert_reset()
113     {
114     f_asc_assert_failed = FALSE;
115     }
116    
117     void asc_assert_catch(int TRUE_or_FALSE)
118     {
119     static PanicCallbackFunc old_callback = NULL;
120    
121     if (FALSE == TRUE_or_FALSE) {
122     (void)Asc_PanicSetCallback(old_callback);
123     Asc_PanicDisplayMessageBox(TRUE);
124     old_callback = NULL;
125     f_asc_assert_failed = FALSE;
126     }
127     else {
128     old_callback = Asc_PanicSetCallback(assert_callback);
129     Asc_PanicDisplayMessageBox(FALSE);
130     f_asc_assert_failed = FALSE;
131     }
132     }
133    

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22