Menu

how to mock a function with diff out pointer

Help
asamya
2010-06-12
2013-04-24
  • asamya

    asamya - 2010-06-12

    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!

     
  • Ewald Arnold

    Ewald Arnold - 2010-06-12

    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?

     
  • asamya

    asamya - 2010-06-13

    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 !

     
  • Ewald Arnold

    Ewald Arnold - 2010-06-13

    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.

     

Log in to post a comment.

MongoDB Logo MongoDB