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

Re: [PATCH] cmocka: Allow to pass initial data to test cases

On Friday 12 June 2015 16:16:58 Pawel Szewczyk wrote:
> Hello
> On 06/11/2015 01:46 PM, Jakub Hrozek wrote:
> > On 09.06.2015 10:59, Pawel Szewczyk wrote:
> >> Just a ping to let you know about pending path.
> > 
> > Andreas is away on vacation for some time..
> > 
> > But in the meantime, this thread might be similar to what you propose..
> > https://cmocka.org/archive/cmocka/2014-06/0000000.html
> Thanks, i did not see this thread before.
> I think the problem Nick was trying to resolve is the same as mine, but
> I don't see solution in what Andreas proposed - testing multiple data
> sets in single unit test, ie.
> void my_test(void **state) {
> 	int array[] = { 1, 2, 17 };
> 	int i;
> 	for (i = 0; i < ARRAY_SIZE(array); i++) {
> 		my_prime_test(array[i]);
> 	}
> }
> For me it's far from ideal. When test fails I cannot tell exactly which
> data sets caused the failure and which not.
> With legacy unit tests there was no simple solution for that (except
> writing a lot of ugly setup functions), but since we define unit test as
> a structure, adding additional field in it is not a big deal.

You can still achieve that by creating a function you call at the beginning of 
the test which init's the state based on the function name or with a setup 

#define init_state(state) _init_state(state, __func__);
void _init_state(void **state, const char *function)
	if (strcmp(function, "mytest1") {
		*state = "my string";

void mytest1(**state) {

	do something;

The patch breaks the API. It would mean that all the projects using cmocka 
would break with a new release. I do not want to do that.

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

Re: [PATCH] cmocka: Allow to pass initial data to test casesPawel Szewczyk <p.szewczyk@xxxxxxxxxxx>