g_assert_handler for unit-tests

hi hi,

we extensivly use g_assert() as API precondition checks in our project. Further
we have a bunch of unit tests based on check [1].
When one writes unit tests this included trying to misuse the API (e.g. passing
NULL pointers and the like). Now if there api entry that is checked is still
buggy, the tessts e.g. crash and therewith the unit-testing framework considers
this as a failed test. When the developer now fix the function by assing some
g_asserts() the unit test still fails, as the programm now exits().

Next I would like to outline a solution for the probelm. I don't have commit
regith to gnome CVS, so if there is agreement I will also provide a patch for it.

As a solution I suggest to introduce a g_assert_handler(). The default
g_assert_handler will call exit() and will be installed by  glib on init().
An application could then use a new API entry g_set_assert_handler() to install
a new handler and to store the old handle so that later it can be restored.
The assert_handler gets
a) the log-message as the only argument
b) file,line,func,expr,... as separate args.

In the unit test we could install our own assert-handler. That even allows to
verify wheter the tested module has handled the wrong arg (by checking func).

What do you thing about it? Is it all nonsesnse and is there an easier way? How
do you handle such things?

In hope to get some feedback - ciao


[1] http://check.sf.net
      \|/            Stefan Kost
     <@ @>           private            business
+-oOO-(_)-OOo------------------------------------------------------ - - -  -   -
|       __  Address  Simildenstr. 5     HTWK Leipzig, Fb IMN, Postfach 301166
|      ///           04277 Leipzig      04251 Leipzig
| __  ///            Germany            Germany
| \\\///    Phone    +49341 2253538     +49341 30766101
|  \__/     EMail    st_kost_at_gmx.net kost_at_imn.htwk-leipzig.de
|           WWW      www.sonicpulse.de  www.imn.htwk-leipzig.de/~kost/about.html
===-=-=--=---=---------------------------------- - - -  -    -
fn:Stefan Kost
org:HTWK Leipzig;FB. IMN
adr:;;Postfach 301166;Leipzig;;04251;Germany
email;internet:kost imn htwk-leipzig de
title:Dipl. Informatiker
tel;work:+49341 30766440
tel;home:+49341 2253538
tel;cell:+49178 3183742

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]