cvariablescunit

Display content of an ASSERTed variable


Simple question here : is it possible to show the content of a variable freshly tested by a CUnit test? Printf() is not displayed during tests, and anyway I don't want to use it. For example, I would like CUnit to output the result of

(MQUEUE_PRI_MASK & flag)

Is it possible? Below is the current output of CUnit:

Suite: Message Queue Test
  Test: mqueue_init ...passed
  Test: mqueue : Test send & rcv functions ...passed
  Test: mqueue : Test mqueue priority ...passed
  Test: mqueue : Test mqueue flags ...0FAILED
    1. utils/test_mqueue.c:117  - CU_ASSERT_EQUAL((MQUEUE_PRI_MASK & flag ),MQUEUE_PRI_HIGH)
  Test: mqueue_free ...passed

Expected result :

Suite: Message Queue Test
  Test: mqueue_init ...passed
  Test: mqueue : Test send & rcv functions ...passed
  Test: mqueue : Test mqueue priority ...passed
  Test: mqueue : Test mqueue flags ...0FAILED
    1. utils/test_mqueue.c:117  - CU_ASSERT_EQUAL(5 ,MQUEUE_PRI_HIGH)
  Test: mqueue_free ...passed

Thanks!


Solution

  • It's not possible with the built-in assert macros but it's not very difficult to write your own. Have a look at the macro definitions in <CUnit/CUnit.h>. You will probably have to write your own variant of CU_assertImplementation(). Use the original source as a template.