You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EMOCK should also work under *nix(UNIX, Android, MacOS and iOS), or maybe need minor adaptation.
Quick view
Global function
// function to be testedinttarget_func(int x);
// how to mockEMOCK(target_func)
.stubs()
.with(any())
.will(returnValue(1));
// assert return 1ASSERT_EQ(target_func(0), 1);
Member functions
// member functions to be testedclassFoo
{
public:voidbar1(int);
virtualvoidbar2(double);
staticintbar3();
};
////////////////////////////////////// mock functions specified to be calledvoid EMOCK_API mock_bar1(Foo* obj, int) {
// ...
}
void EMOCK_API mock_bar2(Foo* obj, double) {
// ...
}
// how to mock kinds of member functionsEMOCK(&Foo::bar1)
.stubs()
.will(invoke(mock_bar1)); // invoke user denfined mocker instead of return valueEMOCK(&Foo::bar2) // virtual mem_fun isn't special
.stubs()
.will(invoke(mock_bar2));
EMOCK(Foo::bar3) // static mem_fun is like global function
.stubs()
.will(returnValue(1));
Overloaded member functions
// overloaded function to be testedintfoobar(int x) {
return x;
}
doublefoobar(double x) {
return x;
}
// how to mock overloaded functionsEMOCK((int (*)(int))foobar)
.stubs()
.will(returnValue(1));
EMOCK(static_cast<double (*)(double)>(foobar))
.stubs()
.will(returnValue(1.0));
// overloaded member functions to be testedclassFoo
{
public:voidbar(int);
voidbar(double);
};
// how to mock overloaded member functionsEMOCK((void (Foo::*)(int))&Foo::bar)
.expects(once()); // call only onceEMOCK(static_cast<void (Foo::*)(double)>(&Foo::bar))
.expects(never()); // won't be called