Skip to content

Instantly share code, notes, and snippets.

@wolf99
Last active February 7, 2017 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolf99/a89fa2714b0f412303345ec28ec89f16 to your computer and use it in GitHub Desktop.
Save wolf99/a89fa2714b0f412303345ec28ec89f16 to your computer and use it in GitHub Desktop.
An example showing how to use cmock's ReturnThrePtr mock type
/* bar.c */
#include foo.h
int bar (void)
{
int a = 5, b = 0;
e = foo(a, &b); /* Note b is local, thus test won't know its address. */
/* ... use b ... */
return e;
}
//~~~~~~~~~~~~~~
/* test_bar.c */
#include "unity.h"
#include "mock_foo.h"
#include "bar.h"
void test_bar (void)
{
int qux = 4, baz = 5;
foo_ExpectAndReturn(qux, &baz);
foo_IgnoreArg_b();
foo_ReturnThruPtr_b(&baz);
bar();
}
@wolf99
Copy link
Author

wolf99 commented Feb 7, 2017

This allows a mock of foo() to be used when testing bar and to inject data back into bar() via the second argument to foo().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment