Michocio Michocio - 1 month ago 16
C Question

cmocka free operation and catching exceptions

I started my adventure with cmocka library, and I have two questions.


  1. Is it possible to find out if free() operation was made correctly? I mean, I would like to test function which is cleaning up tree structure. I've read about test_free(), but honestly I don't understand idea behind that.

  2. The second thing is case of catching standard library exceptions. I know about function
    expect_assert_failure
    , but how to use it? For example I would to do something what will throw segmentation fault, but I would like to pass test anyway.


Answer

I'd suggest just doing an additonal test with valgrind.

valgrind --error-exitcode=1 ./test

Without the option valgrind would always return the same exit code returned by your test program. This way if your test program succeeds, but valgrind's memory check reveals errors, it will return 1 to indicate an error.