ModAssert 1.1 available, an advanced assertion package

Do you like to promote your wxWidgets based application or component!? Post it here and let's see what the critics have to say. Also, if you found that ONE wx component the world needs to know about, put it here for future reference.
Post Reply
In need of some credit
In need of some credit
Posts: 3
Joined: Fri Jul 15, 2005 8:26 am

ModAssert 1.1 available, an advanced assertion package

Post by markvp » Fri Feb 03, 2006 10:23 am

If you like using assertions, or don't like them because you think they are not powerful enough, have a look at my open source ModAssert package on Sourceforge: The version 1.1 is just released. It has 24 assertion macros. They allow you to add expressions to show if the assertions fails. You can also add levels and groups, and an optional action.

On top of that, the condition can be replaced with a Rich Boolean, that gives an informative analysis of why the condition failed (e.g. to show which bits are different in two integers if you ask for a bitwise comparison, or which elements of two wxArrays are different). See to download the Rich Booleans (needed by ModAssert).

Using it can be as simple as

Code: Select all

Here rbEQUAL(a,b) is a Rich Boolean, a booleanlike expression that holds an analysis that would show e.g. "`a':<3> == `b':<4> nok", where the expressions are between ` and ', and their values are between < and >.

There is also MOD_VERIFY, that still evaluates its arguments if assertions are compiled out, and MOD_CHECK, which has a failure action that is exectuted if the condition fails (similar to wxCHECK2).

But you can add suffixes to them and give more arguments, so an assertion can be as advanced as

Code: Select all

MOD_ASSERT_PGO(b<<c, ModAssert::Fatal, return false, "return false", rbEQUAL(a,1));
where b and c are two expressions to be shown, ModAssert::Fatal is the level you assign to it, and return false is an optional action that the user of the application.

It is extensible in many ways:
- write your own dialog to display assertions (one for wxWidgets is already provided)
- write your own assertion logger (one for wxWidgets is already provided)
- write your own Rich Booleans (almost 60 already provided, for all common types of checks C++ programmers need)
- add your own infoproviders to have extra information displayed and logged when an assertion fails (e.g. the threadid, which is already provided for wxWidgets).

It allows you to compile out assertions per level, group, file or all at once. Displaying and logging of failed assertions can be controlled at runtime per level, group, file or all at once.

A small demo application that uses wxWidgets is provided. This also demonstrates how you can reroute wxWidgets assertion macros to ModAssert.

A manual in HTML of 126KB (or PDF, 114 KB) is included, that explains every detail (not generated from code).

It is released under the Boost license, so you can use it in closed source applications, even without mentioning that you use it.

Post Reply