chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!
+1 vote
The test overrides the return value of STRUCTOBJ1 *Foo(LPCSTR,STRUCTOBJ2 **) but gets an error that param 2 cannot be converted from const char * to STRUCTOBJ2**

struct STRUCTOBJ1
{
    int x;
};
#define LPSTRUCTOBJ1 STRUCTOBJ1*

struct STRUCTOBJ2
{
    int y;
};
#define LPSTRUCTOBJ2 STRUCTOBJ2*
typedef const char *LPCSTR;

LPSTRUCTOBJ1 Foo(LPCSTR x, LPSTRUCTOBJ2* y)
{
    return nullptr;
}

TEST_METHOD(JimTest)
    {
        STRUCTOBJ1 my_obj;
        FAKE_GLOBAL(Foo);
        //WHEN_CALLED(Foo(ANY_VAL(LPCSTR), TYPEOF(STRUCTOBJ2**))).Return(&my_obj);
        //WHEN_CALLED(Foo(ANY_VAL(LPCSTR), TYPEOF(LPSTRUCTOBJ2*))).Return(&my_obj);
        //WHEN_CALLED(Foo(_, TYPEOF(LPSTRUCTOBJ2*))).Return(&my_obj);
        WHEN_CALLED(Foo(_, _)).Return(&my_obj);
        //all of the above produce error:
        //error C2664 : \\\\\\\'STRUCTOBJ1 *Foo(LPCSTR,STRUCTOBJ2 **)\\\\\\\' : cannot convert argument 2 from \\\\\\\'const char *\\\\\\\' to \\\\\\\'STRUCTOBJ2 **\\\\\\\'
    }
asked by (3.8k points)

1 Answer

0 votes

Hi,
Try using the ANY_REF macro:

WHEN_CALLED(Foo(ANY_REF(LPCSTR), ANY_REF(LPSTRUCTOBJ2*))).Return(&my_obj);

answered by (1.5k points)
...