How to casue a CppUnit test to fail - from C?

Posted by mawg on Stack Overflow See other posts from Stack Overflow or by mawg
Published on 2010-04-06T03:55:44Z Indexed on 2010/04/06 4:03 UTC
Read the original article Hit count: 460

Filed under:

I'd like to have an equivalent to CPPUNIT_ASSERT, CPPUNIT_ASSERT_MESSAGE or `CPPUNIT_FAIL' which I can call from some common C code.

Our code is a mix of C and C++. Some older apps and those with specific requirements are coded in C and most, especially newer, are coded in C++.

However, a lot of project-agnostic, common code, such as memory buffer pools, debug tracing, etc are coded in C.

When testing a C++ app in CppUnit, I'd to be able to sprinkle some ASSSERT()s which would cause any running CppUnit test to fail.

Maye something like:

if testing
  if running in debugger (Eclipse) then asm("int3");  // stop the debugger, even if no breakpoint at this line
  else
    if running CppUnit test - fail the test and move on to next
     else
       trace to log file

Most of that can be run by wrapping a macro around a few #ifdefs, but I am not sure how I would cause a CppUni test to fail from C code. Can it be done?

© Stack Overflow or respective owner

Related posts about cppunit