NetBurner 3.1
CppUTestConfig.h
1 /*
2  * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the <organization> nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef CPPUTESTCONFIG_H_
29 #define CPPUTESTCONFIG_H_
30 
31 #include "config.h"
32 
33 #ifndef CPPUTEST_USE_OWN_CONFIGURATION
34 #include "CppUTestGeneratedConfig.h"
35 #endif
36 
37 /*
38  * This file is added for some specific CppUTest configurations that earlier were spread out into multiple files.
39  *
40  * The goal of this file is to stay really small and not to include other things, but mainly to remove duplication
41  * from other files and resolve dependencies in #includes.
42  *
43  */
44 
45 #ifdef __clang__
46  #pragma clang diagnostic push
47  #if __clang_major__ >= 3 && __clang_minor__ >= 6
48  #pragma clang diagnostic ignored "-Wreserved-id-macro"
49  #endif
50 #endif
51 
52 /*
53  * Lib C dependencies that are currently still left:
54  *
55  * stdarg.h -> We use formatting functions and va_list requires to include stdarg.h in SimpleString
56  * stdlib.h -> The TestHarness_c.h includes this to try to avoid conflicts in its malloc #define. This dependency can
57  * easily be removed by not enabling the MALLOC overrides.
58  *
59  * Lib C++ dependencies are all under the CPPUTEST_USE_STD_CPP_LIB.
60  * The only dependency is to <new> which has the bad_alloc struct
61  *
62  */
63 
64 /* Do we use Standard C or not? When doing Kernel development, standard C usage is out. */
65 #ifndef CPPUTEST_USE_STD_C_LIB
66  #ifdef CPPUTEST_STD_C_LIB_DISABLED
67  #define CPPUTEST_USE_STD_C_LIB 0
68  #else
69  #define CPPUTEST_USE_STD_C_LIB 1
70  #endif
71 #endif
72 
73 
74 /* Do we use Standard C++ or not? */
75 #ifndef CPPUTEST_USE_STD_CPP_LIB
76  #ifdef CPPUTEST_STD_CPP_LIB_DISABLED
77  #define CPPUTEST_USE_STD_CPP_LIB 0
78  #else
79  #define CPPUTEST_USE_STD_CPP_LIB 1
80  #endif
81 #endif
82 
83 /* Is memory leak detection enabled?
84  * Controls the override of the global operator new/deleted and malloc/free.
85  * Without this, there will be no memory leak detection in C/C++.
86 */
87 
88 #ifndef CPPUTEST_USE_MEM_LEAK_DETECTION
89  #ifdef CPPUTEST_MEM_LEAK_DETECTION_DISABLED
90  #define CPPUTEST_USE_MEM_LEAK_DETECTION 0
91  #else
92  #define CPPUTEST_USE_MEM_LEAK_DETECTION 1
93  #endif
94 #endif
95 
96 /* Should be the only #include here. Standard C library wrappers */
97 #include "StandardCLibrary.h"
98 
99 /* Create a __no_return__ macro, which is used to flag a function as not returning.
100  * Used for functions that always throws for instance.
101  *
102  * This is needed for compiling with clang, without breaking other compilers.
103  */
104 #ifndef __has_attribute
105  #define __has_attribute(x) 0
106 #endif
107 
108 #if __has_attribute(noreturn)
109  #define __no_return__ __attribute__((noreturn))
110 #else
111  #define __no_return__
112 #endif
113 
114 #if __has_attribute(format)
115  #define __check_format__(type, format_parameter, other_parameters) __attribute__ ((format (type, format_parameter, other_parameters)))
116 #else
117  #define __check_format__(type, format_parameter, other_parameters) /* type, format_parameter, other_parameters */
118 #endif
119 
120 /*
121  * When we don't link Standard C++, then we won't throw exceptions as we assume the compiler might not support that!
122  */
123 
124 #if CPPUTEST_USE_STD_CPP_LIB
125  #if defined(__cplusplus) && __cplusplus >= 201103L
126  #define UT_THROW(exception)
127  #define UT_NOTHROW noexcept
128  #else
129  #define UT_THROW(exception) throw (exception)
130  #define UT_NOTHROW throw()
131  #endif
132 #else
133  #define UT_THROW(exception)
134  #ifdef __clang__
135  #define UT_NOTHROW throw()
136  #else
137  #define UT_NOTHROW
138  #endif
139 #endif
140 
141 /*
142  * Visual C++ doesn't define __cplusplus as C++11 yet (201103), however it doesn't want the throw(exception) either, but
143  * it does want throw().
144  */
145 
146 #ifdef _MSC_VER
147  #undef UT_THROW
148  #define UT_THROW(exception)
149 #endif
150 
151 #if defined(__cplusplus) && __cplusplus >= 201103L
152  #define DEFAULT_COPY_CONSTRUCTOR(classname) classname(const classname &) = default;
153 #else
154  #define DEFAULT_COPY_CONSTRUCTOR(classname)
155 #endif
156 
157 /*
158  * g++-4.7 with stdc++11 enabled On MacOSX! will have a different exception specifier for operator new (and thank you!)
159  * I assume they'll fix this in the future, but for now, we'll change that here.
160  * (This should perhaps also be done in the configure.ac)
161  */
162 
163 #ifdef __GXX_EXPERIMENTAL_CXX0X__
164 #ifdef __APPLE__
165 #ifdef _GLIBCXX_THROW
166 #undef UT_THROW
167 #define UT_THROW(exception) _GLIBCXX_THROW(exception)
168 #endif
169 #endif
170 #endif
171 
172 /*
173  * Handling of IEEE754 floating point exceptions via fenv.h
174  * Works on non-Visual C++ compilers and Visual C++ 2008 and newer
175  */
176 
177 #if CPPUTEST_USE_STD_C_LIB && (!defined(_MSC_VER) || (_MSC_VER >= 1800))
178 #define CPPUTEST_HAVE_FENV
179 #if defined(__WATCOMC__) || defined(__ARMEL__) || defined(__m68k__)
180 #define CPPUTEST_FENV_IS_WORKING_PROPERLY 0
181 #else
182 #define CPPUTEST_FENV_IS_WORKING_PROPERLY 1
183 #endif
184 #endif
185 
186 #undef CPPUTEST_HAVE_FENV // Not used by NetBurner
187 
188 /*
189  * Detection of different 64 bit environments
190  */
191 
192 #if defined(__LP64__) || defined(_LP64) || (defined(__WORDSIZE) && (__WORDSIZE == 64 )) || defined(__x86_64) || defined(_WIN64)
193 #define CPPUTEST_64BIT
194 #if defined(_WIN64)
195 #define CPPUTEST_64BIT_32BIT_LONGS
196 #endif
197 #endif
198 
199 /* Handling of systems with a different byte-width (e.g. 16 bit).
200  * Since CHAR_BIT is defined in limits.h (ANSI C), use default of 8 when building without Std C library.
201  */
202 #if CPPUTEST_USE_STD_C_LIB
203 #define CPPUTEST_CHAR_BIT CHAR_BIT
204 #else
205 #define CPPUTEST_CHAR_BIT 8
206 #endif
207 
208 /* Handling of systems with a different int-width (e.g. 16 bit).
209  */
210 #if CPPUTEST_USE_STD_C_LIB && (INT_MAX == 0x7fff)
211 #define CPPUTEST_16BIT_INTS
212 #endif
213 
214 /*
215  * Support for "long long" type.
216  *
217  * Not supported when CPUTEST_LONG_LONG_DISABLED is set.
218  * Can be overridden by using CPPUTEST_USE_LONG_LONG
219  *
220  * CPPUTEST_HAVE_LONG_LONG_INT is set by configure
221  * LLONG_MAX is set in limits.h. This is a crude attempt to detect long long support when no configure is used
222  *
223  */
224 
225 #if !defined(CPPUTEST_LONG_LONG_DISABLED) && !defined(CPPUTEST_USE_LONG_LONG)
226 #if defined(CPPUTEST_HAVE_LONG_LONG_INT) || defined(LLONG_MAX)
227 #define CPPUTEST_USE_LONG_LONG 1
228 #endif
229 #endif
230 
231 #ifdef CPPUTEST_USE_LONG_LONG
232 typedef long long cpputest_longlong;
233 typedef unsigned long long cpputest_ulonglong;
234 #else
235 /* Define some placeholders to disable the overloaded methods.
236  * It's not required to have these match the size of the "real" type, but it's occasionally convenient.
237  */
238 
239 #if defined(CPPUTEST_64BIT) && !defined(CPPUTEST_64BIT_32BIT_LONGS)
240 #define CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE 16
241 #else
242 #define CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE 8
243 #endif
244 
245 struct cpputest_longlong
246 {
247 #if defined(__cplusplus)
248  cpputest_longlong() {}
249  cpputest_longlong(int) {}
250 #endif
251  char dummy[CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE];
252 };
253 
254 struct cpputest_ulonglong
255 {
256 #if defined(__cplusplus)
257  cpputest_ulonglong() {}
258  cpputest_ulonglong(int) {}
259 #endif
260  char dummy[CPPUTEST_SIZE_OF_FAKE_LONG_LONG_TYPE];
261 };
262 
263 #if !defined(__cplusplus)
264 typedef struct cpputest_longlong cpputest_longlong;
265 typedef struct cpputest_ulonglong cpputest_ulonglong;
266 #endif
267 
268 #endif
269 
270 /* Visual C++ 10.0+ (2010+) supports the override keyword, but doesn't define the C++ version as C++11 */
271 #if defined(__cplusplus) && ((__cplusplus >= 201103L) || (defined(_MSC_VER) && (_MSC_VER >= 1600)))
272 #define CPPUTEST_COMPILER_FULLY_SUPPORTS_CXX11
273 #define _override override
274 #else
275 #define _override
276 #endif
277 
278 /* MinGW-w64 prefers to act like Visual C++, but we want the ANSI behaviors instead */
279 #undef __USE_MINGW_ANSI_STDIO
280 #define __USE_MINGW_ANSI_STDIO 1
281 
282 #ifdef __clang__
283  #pragma clang diagnostic pop
284 #endif
285 
286 #endif