1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#ifndef __FRAMEWORK_MACROS_DEBUG_ASSERTION_HXX_
#define __FRAMEWORK_MACROS_DEBUG_ASSERTION_HXX_
//_________________________________________________________________________________________________________________
// includes
//_________________________________________________________________________________________________________________
#if defined( ENABLE_ASSERTIONS ) || defined( ENABLE_WARNINGS )
#ifndef _OSL_DIAGNOSE_H_
#include <osl/diagnose.h>
#endif
#ifndef _RTL_STRBUF_HXX_
#include <rtl/strbuf.hxx>
#endif
#endif
//*****************************************************************************************************************
// special macros for assertion handling
// 1) LOGTYPE use it to define the output of all assertions, errors, exception infos
// 2) LOGFILE_ASSERTIONS use it to define the file name to log assertions if LOGTYPE=LOGTYPE_FILE...
// 3) LOGFILE_WARNINGS use it to define the file name to log warnings if LOGTYPE=LOGTYPE_FILE...
//
// active for "non product":
//
// 4) LOG_ASSERT( BCONDITION, STEXT ) assert some critical errors wich depend from given condition
// 4a) LOG_ASSERT2( BCONDITION, SMETHOD, STEXT ) same like 4) + additional location of error
// 5) LOG_ERROR( SMETHOD, STEXT ) show errors without any condition
//
// active for debug only!
//
// 6) LOG_EXCEPTION( SMETHOD, SOWNMESSAGE, SEXCEPTIONMESSAGE ) show/log an exception for easier debug
// 7) LOG_WARNING( SMETHOD, STEXT ) should be used to detect leaks in algorithm, mechanism or operation handling
//*****************************************************************************************************************
//_________________________________________________________________________________________________________________
#if defined( ENABLE_ASSERTIONS ) || defined( ENABLE_WARNINGS )
/*_____________________________________________________________________________________________________________
LOGFILE_ASSERTIONS
For follow macros we need a special log file. If user forget to specify anyone, we must do it for him!
_____________________________________________________________________________________________________________*/
#ifndef LOGFILE_ASSERTIONS
#define LOGFILE_ASSERTIONS "_framework_assertions.log"
#endif
/*_____________________________________________________________________________________________________________
LOG_ASSERT ( BCONDITION, STEXT )
LOG_ASSERT2( BCONDITION, SMETHOD, STEXT )
Forward assertion to logfile (if condition is sal_False - like a DBG_ASSERT!) and continue with program.
Set LOGTYPE to LOGTYPE_FILECONTINUE to do this.
BCONDITION is inserted in "(...)" because user can call this macro with an complex expression!
_____________________________________________________________________________________________________________*/
#if LOGTYPE==LOGTYPE_FILECONTINUE
#define LOG_ASSERT( BCONDITION, STEXT ) \
if ( ( BCONDITION ) == sal_False ) \
{ \
WRITE_LOGFILE( LOGFILE_ASSERTIONS, STEXT ) \
}
#define LOG_ASSERT2( BCONDITION, SMETHOD, STEXT ) \
if ( ( BCONDITION ) == sal_True ) \
{ \
::rtl::OStringBuffer _sAssertBuffer( 256 ); \
_sAssertBuffer.append( "ASSERT:\n\t" ); \
_sAssertBuffer.append( SMETHOD ); \
_sAssertBuffer.append( "\n\t\"" ); \
_sAssertBuffer.append( STEXT ); \
_sAssertBuffer.append( "\"\n" ); \
WRITE_LOGFILE( LOGFILE_ASSERTIONS, _sAssertBuffer.makeStringAndClear() ) \
}
#endif
/*_____________________________________________________________________________________________________________
LOG_ASSERT ( BCONDITION, STEXT )
LOG_ASSERT2( BCONDITION, SMETHOD, STEXT )
Forward assertion to file and exit the program.
Set LOGTYPE to LOGTYPE_FILEEXIT to do this.
BCONDITION is inserted in "(...)" because user can call this macro with an complex expression!
_____________________________________________________________________________________________________________*/
#if LOGTYPE==LOGTYPE_FILEEXIT
#define LOG_ASSERT( BCONDITION, STEXT ) \
if ( ( BCONDITION ) == sal_False ) \
{ \
WRITE_LOGFILE( LOGFILE_ASSERTIONS, STEXT ) \
exit(-1); \
}
#define LOG_ASSERT2( BCONDITION, SMETHODE, STEXT ) \
if ( ( BCONDITION ) == sal_True ) \
{ \
::rtl::OStringBuffer _sAssertBuffer( 256 ); \
_sAssertBuffer.append( "ASSERT:\n\t" ); \
_sAssertBuffer.append( SMETHOD ); \
_sAssertBuffer.append( "\n\t\"" ); \
_sAssertBuffer.append( STEXT ); \
_sAssertBuffer.append( "\"\n" ); \
WRITE_LOGFILE( LOGFILE_ASSERTIONS, _sAssertBuffer.makeStringAndClear() ) \
exit(-1); \
}
#endif
/*_____________________________________________________________________________________________________________
LOG_ASSERT ( BCONDITION, STEXT )
LOG_ASSERT2( BCONDITION, SMETHOD, STEXT )
Forward assertions to messagebox. (We use OSL_ENSURE to do this.)
Set LOGTYPE to LOGTYPE_MESSAGEBOX to do this.
BCONDITION is inserted in "(...)" because user can call this macro with an complex expression!
_____________________________________________________________________________________________________________*/
#if LOGTYPE==LOGTYPE_MESSAGEBOX
#define LOG_ASSERT( BCONDITION, STEXT ) \
OSL_ENSURE( ( BCONDITION ), STEXT );
#define LOG_ASSERT2( BCONDITION, SMETHOD, STEXT ) \
{ \
::rtl::OStringBuffer _sAssertBuffer( 256 ); \
_sAssertBuffer.append( "ASSERT:\n\t" ); \
_sAssertBuffer.append( SMETHOD ); \
_sAssertBuffer.append( "\n\t\"" ); \
_sAssertBuffer.append( STEXT ); \
_sAssertBuffer.append( "\"\n" ); \
OSL_ENSURE( !( BCONDITION ), _sAssertBuffer.makeStringAndClear() ); \
}
#endif
/*_____________________________________________________________________________________________________________
LOG_ERROR( SMETHOD, STEXT )
Show an error by using current set output mode by define LOGTYPE!
_____________________________________________________________________________________________________________*/
#define LOG_ERROR( SMETHOD, STEXT ) \
LOG_ASSERT2( sal_True, SMETHOD, STEXT )
#else
// If right testmode is'nt set - implements these macros empty!
#undef LOGFILE_ASSERTIONS
#define LOG_ASSERT( BCONDITION, STEXT )
#define LOG_ASSERT2( BCONDITION, SMETHOD, STEXT )
#define LOG_ERROR( SMETHOD, STEXT )
#endif // ENABLE_ASSERTIONS
//_________________________________________________________________________________________________________________
#if defined( ENABLE_WARNINGS )
/*_____________________________________________________________________________________________________________
LOGFILE_WARNINGS
For follow macros we need a special log file. If user forget to specify anyone, we must do it for him!
_____________________________________________________________________________________________________________*/
#ifndef LOGFILE_WARNINGS
#define LOGFILE_WARNINGS "_framework_warnings.log"
#endif
/*_____________________________________________________________________________________________________________
LOG_EXCEPTION( SMETHOD, SOWNMESSAGE, SEXCEPTIONMESSAGE )
Show some exception info by using current set output mode by define LOGTYPE!
We use a seperated scope {} do protect us against multiple variable definitions.
_____________________________________________________________________________________________________________*/
#define LOG_EXCEPTION( SMETHOD, SOWNMESSAGE, SEXCEPTIONMESSAGE ) \
{ \
::rtl::OStringBuffer _sAssertBuffer2( 256 ); \
_sAssertBuffer2.append( SOWNMESSAGE ); \
_sAssertBuffer2.append( "\n" ); \
_sAssertBuffer2.append( U2B(SEXCEPTIONMESSAGE) ); \
LOG_ERROR( SMETHOD, _sAssertBuffer2.makeStringAndClear() ) \
}
/*_____________________________________________________________________________________________________________
LOG_WARNING( SMETHOD, STEXT )
Use it to show/log warnings for programmer for follow reasons:
- algorithm errors
- undefined states
- unknown errors from other modules ...
_____________________________________________________________________________________________________________*/
#define LOG_WARNING( SMETHOD, STEXT ) \
LOG_ERROR( SMETHOD, STEXT )
#else
// If right testmode is'nt set - implements these macros empty!
#undef LOGFILE_WARNINGS
#define LOG_EXCEPTION( SMETHOD, SOWNMESSAGE, SEXCEPTIONMESSAGE )
#define LOG_WARNING( SMETHOD, STEXT )
#endif // ENABLE_WARNINGS
#endif // #ifndef __FRAMEWORK_MACROS_DEBUG_ASSERTION_HXX_
|