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

Re: unit_test_teardown


On Monday 28 October 2013 22:15:43 Jan Paesmans wrote:
> Hi,
> 
> I've updated my git repo and tried running my test.
> It fails now with the following message:
> 
> number_of_test_states
> /home/janp/src/cmocka/src/cmocka.c:1780: error: Failure!
> 
> I've traced the problem to the variable number_of_test_states. This
> variable is incremented for each setup for a test and decremented for
> each teardown of a test.
> In case of a unit_test_teardown, there is no setup and the assert at the
> indicated line is triggered.
> I've tried changed the macro to something line this:
> 
>  #define unit_test_teardown(test, teardown) \
> +    _unit_test_setup(test, NULL), \
>      unit_test(test), \
>      _unit_test_teardown(test, teardown)
> 
> 
> However, that resulted in the same problem. There is a check before the
> switch statement, to continue if the function is NULL.
> So I've resorted to this dirty hack:
> 
> diff --git a/include/cmocka.h b/include/cmocka.h
> index 0df2e90..e9138b8 100644
> --- a/include/cmocka.h
> +++ b/include/cmocka.h
> @@ -1310,8 +1310,11 @@ int run_test(#function);
>  #define _unit_test_teardown(test, teardown) \
>      { #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN }
> 
> +static void dummy(void **state) { (void)state; }
> +
>  /** Initializes a UnitTest structure with a teardown function. */
>  #define unit_test_teardown(test, teardown) \
> +    _unit_test_setup(test, dummy), \

This line isn't needed. I've added tests for these functions now.


See 
http://git.cryptomilk.org/projects/cmocka.git/commit/?id=5c8a0fb3a07912aad0121b948092cb108a958ec9

>      unit_test(test), \
>      _unit_test_teardown(test, teardown)
> 


	-- andreas

-- 
Andreas Schneider                   GPG-ID: CC014E3D
www.cryptomilk.org                asn@xxxxxxxxxxxxxx


References:
unit_test_teardownJan Paesmans <jan.paesmans@xxxxxxxxx>
Re: unit_test_teardownAndreas Schneider <asn@xxxxxxxxxxxxxx>
Re: unit_test_teardownJan Paesmans <jan.paesmans@xxxxxxxxx>