1 #if !defined (__ASSERTION_HPP)
2 #define __ASSERTION_HPP
208 #if !defined IN_COMMON_HPP
209 #error Assertion.hpp is included by Common.hpp only.
216 DECLARE_CLASS( Assertion );
223 Long assertionFailed( AssertionCref rAssertion );
224 void assertLoopDebugFunction(
void );
230 static Long asstInvert = 0;
231 static Long asstResult = 0;
232 static Long asstEval = 0;
233 static Long asstShortCut = 0;
234 static Long asstZero = 0;
236 static struct AssertCt
240 asstInvert = asstResult = asstEval = asstShortCut = asstZero = 0;
251 #define paste(a,b) a##b
252 #define paste3(a,b,c) a##b##c
255 #if defined ALL_ASSERTIONS || defined ASSERT_REQUIRE
256 #define REQUIRE( exp ) \
258 asstResult = asstZero || exp, \
259 asstResult || assertionFailed( Assertion( Assertion::REQUIRE, \
265 #define REQUIRE( exp )
266 #endif // defined ALL_ASSERTIONS || ASSERT_REQUIRE
268 #if defined ALL_ASSERTIONS || defined ASSERT_ENSURE
269 #define ENSURE( exp ) \
271 asstResult = asstZero || exp, \
272 asstResult || assertionFailed( Assertion( Assertion::ENSURE, \
278 #define ENSURE( exp )
279 #endif // defined ALL_ASSERTIONS || ASSERT_ENSURE
281 #if defined ALL_ASSERTIONS || defined ASSERT_CHECK
282 #define CHECK( exp ) \
284 asstResult = asstZero || exp, \
285 asstResult || assertionFailed( Assertion( Assertion::CHECK, \
295 #endif // defined ALL_ASSERTIONS || ASSERT_CHECK
298 #define NEVER_GET_HERE \
299 assertionFailed( Assertion( Assertion::NEVERGETHERE, \
300 TEXT("NEVER_GET_HERE"), \
307 #if defined ALL_ASSERTIONS
310 virtual void invariant(void) const { Short executingInvariant = 1;
311 #define END_INVARIANT }
312 #define CHECK_INVARIANT invariant()
314 #define INVARIANT paste(/, *)
315 #define END_INVARIANT
316 #define CHECK_INVARIANT
327 #if defined ALL_ASSERTIONS
328 #define STDASSERT( exp ) \
329 if( executingInvariant ) \
331 asstResult = asstZero || exp, \
333 assertionFailed( Assertion( Assertion::ASSERT, \
340 TEXT("STDASSERT used outside of INVARIANT"), LOCATION ); \
343 #define STDASSERT( exp )
344 #endif // defined ALL_ASSERTIONS
346 #if defined ALL_ASSERTIONS
347 #define BASE_INVARIANT( ClassType ) \
348 if( executingInvariant ) \
350 ClassType::invariant(); \
355 TEXT("BASE_INVARIANT used outside of an INVARIANT"), \
357 Exception::ProcessTerminate); \
361 #define BASE_INVARIANT( ClassType )
368 #if defined ALL_ASSERTIONS || defined ASSERT_ENSURE
369 #define USES_OLD( Type ) Type old( clself )
371 #define USES_OLD( Type )
378 #define ASSERT_LOOP( asstFor, asstAll, asstCond ) \
383 if( asstDoEval( asstShortCut )) \
385 Long asstInvert = ::asstInvert; \
386 asstResult = asstAll; \
389 asstResult = x || asstCond; \
390 if( asstResult != asstAll ) break; \
392 if(asstInvert) asstResult = !asstResult; \
394 ::asstShortCut = asstShortCut; \
395 if( asstResult == 0 ) assertLoopDebugFunction(); \
397 asstResult = ::asstShortCut ? asstResult : asstResult
399 #if defined ALL_ASSERTIONS
400 #define FORALL(asstFor, asstCond ) ASSERT_LOOP( asstFor, 1, asstCond )
401 #define EXISTS(asstFor, asstCond ) ASSERT_LOOP( asstFor, 0, asstCond )
403 #define FORALL(asstFor, asstCond ) True
404 #define EXISTS(asstFor, asstCond ) True
512 inline AssertCt & anAssertCt(
void )
519 inline Long asstDoEval( Long & asstShortCut )
521 Long result = asstEval;
523 asstShortCut = !asstEval && asstResult;
530 inline const AssertCt & operator !(
const AssertCt & a )
532 asstInvert = !asstInvert;
536 inline Long operator &&( Long left,
const AssertCt & )
542 inline Long operator ||(
int left,
const AssertCt & )
550 #endif // !defined ASSERT_HPP
CHECK invariant state.
Definition: Assertion.hpp:439
ASSERT invariant state.
Definition: Assertion.hpp:440
Assertion(Type aType, CharPtr aReason, CharPtr aFile, LineNum aLine)
Assertion Constructor.
Definition: Assertion.cpp:48
AssertionRef operator=(AssertionCref)
Assignment operator overload.
Definition: Assertion.cpp:86
bool operator==(AssertionCref)
Comparisson operator overload.
virtual ~Assertion(void)
Virtual Destructor.
Definition: Assertion.cpp:77
Forward reference the various common classes.
Definition: AbstractAllocator.hpp:32
REQUIRE pre-condition state.
Definition: Assertion.hpp:437
Exception is the base exception class used in the CoreLinux++ libraries.
Definition: Exception.hpp:51
Assertion is-a Exception created when an assertion fails.
Definition: Assertion.hpp:423
Type
Assertion Types enum.
Definition: Assertion.hpp:434
ENSURE post-condition state.
Definition: Assertion.hpp:438
Assertion::Type getType(void) const
Accessor.
Definition: Assertion.cpp:104