Last active
February 7, 2017 16:35
-
-
Save wolf99/a89fa2714b0f412303345ec28ec89f16 to your computer and use it in GitHub Desktop.
An example showing how to use cmock's ReturnThrePtr mock type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This allows a mock of
foo()
to be used when testing bar and to inject data back intobar()
via the second argument tofoo()
.