Re: [Boost-users] boost test with assert()

Hmm. Sadly, RemoveSimulation() does other things that SimulationId knows nothing about ...
----- Original Message ----- From: "Gennadiy Rozental"
To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost test with assert() Date: Fri, 21 Nov 2008 23:45:59 +0000 (UTC) Hicham Mouline writes: Possibly, there is a nicer/cleaner way to test this?
Possible there is a nicer way to design this? Why not just call RemoveSimulation from SimulationId destructor?
Gennadiy

Hicham Mouline
Hmm. Sadly, RemoveSimulation() does other things that SimulationId knows nothing about ...
Why does it have to know anything about it? It's just call the function. How does it matter if you call it from outside - on function level, or from inside in destructor? Gennadiy
----- Original Message ----- From: "Gennadiy Rozental"
To: boost-users <at> lists.boost.org Subject: Re: [Boost-users] boost test with assert() Date: Fri, 21 Nov 2008 23:45:59 +0000 (UTC) Hicham Mouline writes: Possibly, there is a nicer/cleaner way to test this?
Possible there is a nicer way to design this? Why not just call RemoveSimulation from SimulationId destructor?
Gennadiy

Because RemoveSimulation(....) takes arguments which are not available
inside the SimulatonId
object/destructor.
I apologize for being misleading by not being clear about the args,
Regards,
-----Original Message-----
From: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of Gennadiy Rozental
Sent: 24 November 2008 05:01
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] boost test with assert()
Hicham Mouline
Hmm. Sadly, RemoveSimulation() does other things that SimulationId knows nothing about ...
Why does it have to know anything about it? It's just call the function. How does it matter if you call it from outside - on function level, or from inside in destructor? Gennadiy

From: Hicham Mouline
Because RemoveSimulation(....) takes arguments which are not available inside the SimulatonId object/destructor.
Hi Hicham,
In our test suites we deal with this problem by using an own special
implementation of the assert() function. In this assert, called
dynamicAssert() or runTimeAssert(), we call the real assert() only if
the application is not running under test application. If running under
test, we throw an special exception type instead, e.g. AssertionEx. This
exception can be caught by the UTF and tested by Test-Tools. The
exception instance can hold some information from the assert, like file
and line, which can be printed out by a special exception handler, that
must be registered for the UTF.
Some example code:
// runtimeAssert.h defines an own assertion macro for the user code
struct AssertionEx;
extern void runtimeAssert_( const char* exp, const char* file, unsigned
long nLineNo ) throw AssertionEx;
#define dynamicAssert ( exp ) \
(void)((exp) || (runtimeAssert_(#exp, __FILE__, __LINE__), 0 ) )
// runtimeassert.cpp with special assert() implementation
struct AssertionEx
{
const char* exp_;
const char* file_;
unsigned long lineNo_;
AssertionEx( const char* exp, const char* file, unsigned long line )
: exp_(exp), file_(file), lineNo_(line)
{}
};
static bool runningUnderTest = false;
void runUnderTest() // must be called once by your test application
main()
{
runningUnderTest = true;
}
extern "C" {
#include

Uwe Schuster
From: Hicham Mouline
Because RemoveSimulation(....) takes arguments which are not available inside the SimulatonId object/destructor.
Hi Hicham,
In our test suites we deal with this problem by using an own special implementation of the assert() function. In this assert, called dynamicAssert() or runTimeAssert(), we call the real assert() only if the application is not running under test application. If running under test, we throw an special exception type instead, e.g. AssertionEx. This exception can be caught by the UTF and tested by Test-Tools. The
He wants to perform check in destructor. Throwing an exception might cause problem. Maybe in conjunction with uncaught_exception() it can be made to work. Gennadiy

Well. I wish to trigger the destructor, which runs right before the
Test...() method returns,
and the destructor asserts false... Inside the destructor, all there is the
conditional assert()...
Maybe that's the same you are saying...
thanks
-----Original Message-----
From: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of Gennadiy Rozental
Sent: 24 November 2008 16:18
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] boost test with assert()
Uwe Schuster
From: Hicham Mouline
Because RemoveSimulation(....) takes arguments which are not available inside the SimulatonId object/destructor.
Hi Hicham,
In our test suites we deal with this problem by using an own special implementation of the assert() function. In this assert, called dynamicAssert() or runTimeAssert(), we call the real assert() only if the application is not running under test application. If running under test, we throw an special exception type instead, e.g. AssertionEx. This exception can be caught by the UTF and tested by Test-Tools. The
He wants to perform check in destructor. Throwing an exception might cause problem. Maybe in conjunction with uncaught_exception() it can be made to work. Gennadiy
participants (3)
-
Gennadiy Rozental
-
Hicham Mouline
-
Uwe Schuster