I want to mock a function twice with same input but different outbound pointer. I try to write two mocker, but it always use the first one.How to solve this? Thank you all!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The method signature has to differ, so the compiler can distinguish them, so it is likely thatit won't work. Could you provide an example for your problem?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
mystruct mytest;
mystruct pmytest = &mytest;
int b;
void myfun(mystruct *mypointer);
MOCKER(myfun)
.stub()
.with(outBoundP(pmytest));
I want to use myfun twice. First time I want pmytest->a = NULL.
Second time I want pmytest->a = &b. How to distinguish the two
different invoke. THANK YOU !
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am still not sure if I understood your question correctly. But probably you need to subclass OutBound as you need to dereference the pointer. The available class would just change the pointer itself.
Something like this unverified piece of code:
template <typename T>
OutBoundPointered<T> : public OutBound<T>
{
virtual bool eval( const T &*arg ) const
{
if (returnObjects.hasMoreObjects())
{
T &*back_ref = const_cast<T&*>(arg);
*back_ref = returnObjects.nextReturnObject();
return true;
}
return false;
}
eval() would then copy all included class variables.
And of course myfun must be a class member.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I want to mock a function twice with same input but different outbound pointer. I try to write two mocker, but it always use the first one.How to solve this? Thank you all!
The method signature has to differ, so the compiler can distinguish them, so it is likely thatit won't work. Could you provide an example for your problem?
struct mystruct
{
int *a;
}
mystruct mytest;
mystruct pmytest = &mytest;
int b;
void myfun(mystruct *mypointer);
MOCKER(myfun)
.stub()
.with(outBoundP(pmytest));
I want to use myfun twice. First time I want pmytest->a = NULL.
Second time I want pmytest->a = &b. How to distinguish the two
different invoke. THANK YOU !
I am still not sure if I understood your question correctly. But probably you need to subclass OutBound as you need to dereference the pointer. The available class would just change the pointer itself.
Something like this unverified piece of code:
template <typename T>
OutBoundPointered<T> : public OutBound<T>
{
virtual bool eval( const T &*arg ) const
{
if (returnObjects.hasMoreObjects())
{
T &*back_ref = const_cast<T&*>(arg);
*back_ref = returnObjects.nextReturnObject();
return true;
}
return false;
}
eval() would then copy all included class variables.
And of course myfun must be a class member.