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

Annotation of /trunk/test/assertimpl.c

Parent Directory Parent Directory | Revision Log Revision Log


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

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