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

Re: chef_wrap run issue, VS2010


On Wednesday 24 February 2016 10:48:06 Daniel Miller wrote:
> Right, the crashing itself isn't the real issue here; that was caused by me
> mis-understanding how data was being passed around.  The core issue,
> though, is that with VS, the wrapper function was not getting called, but
> the original chef_cook() was called instead; in other words, mocking was
> not occurring.

Mocking can still be done with #define, but the --wrap feature of the linker 
is much more elegant.

Example:

#ifdef UNIT_TESTING
char *mock_strdup(const char *p);

#define strdup mock_strdup

char *test_strdup(const char *p)
{
	static int count = 0;
	char *x;
	size_t len;

	count++;
	if (count % 10 == 0) {
		errno = EINVAL;
		return NULL;
	}

	x = calloc(1, len + 1);
	if (x == NULL) {
		return NULL;
	}
	memcpy(x, p, len);

	return x;
}

#endif


I think we need an example in the code for this.



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

References:
chef_wrap run issue, VS2010Daniel Miller <dmiller@xxxxxxxxxxxxxxxx>
Re: chef_wrap run issue, VS2010"James Grenning" <james@xxxxxxxxxxxx>
Re: chef_wrap run issue, VS2010Daniel Miller <dmiller@xxxxxxxxxxxxxxxx>