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 Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I try to use Isolator++ to fake global function like online document

typedef enum {
     good,
     great
} MyEnum;

void gfunc(MyEnum myenum, int test) {...}

FAKE_GLOBAL(gfunc);
WHEN_CALLED(gfunc(_, _)).DoStaticOrGlobalInstead(gfunc2, NULL);

But when compiling, it shows that "cannot convert parameter 1 from 'int' to 'MyEnum'".
doesn't '_' mean anything (any type argument) ?
Is this a bug ? And how could I avoid this issue ?

I also try other usage, ex: WHEN_CALLED(gfunc(static_cast<MyEnum>(_), _))
but it lead to exception in Isolator++ when executing

Thank you.
asked by mars.tsai (760 points)

9 Answers

0 votes
Hi,

Thank you for the feedback.
We reproduced this issue and this is a bug.

As a workaround, try to cast the enum to an int inside WHEN_CALLED.
Let me know if it helps.
answered by alex (17k points)
0 votes
Hi Alex,

Sorry for the late response.
I try the workaround like "WHEN_CALLED(gfunc(static_cast<int>(_), _)).DoStaticOrGlobalInstead(gfunc2, NULL);"
but it still shows that "cannot convert parameter 1 from 'int' to 'MyEnum'".
It seems not to work.
Have other workaround, or when the bug could be fixed ?
Thank a lot.

Have a nice day.
answered by mars.tsai (760 points)
0 votes
Hi,

Thank you for the feedback.
Please try the following, it fixed this issue in my reproduction.

Instead of:
WHEN_CALLED(gfunc(_)).Ignore();

The call needs to be changed to:
WHEN_CALLED(gfunc(ANY_VAL(MyEnum))).Ignore();

I think that ANY_VAL is not documented yet but it will be soon.
Let me know if it helps.
answered by alex (17k points)
0 votes
Hi Alex,

It works. but I must modify ALL parameters to ANY_VAL( ) style.
I ever tried the workaround, but it failed because I modified one parameter only.
Anyway, now my test can be compiled and run.
But it will leak memory when I try to fake a global function.

void MyGlobalFunc(void)
{}

BOOST_AUTO_TEST_CASE
{
     FAKE_GLOBAL(MyGlobalFunc);
     // WHEN_CALLED(......) , it is not yet used

     ISOLATOR_CLEANUP();
}


I search the articles about memory leak on this forum and online document, but I find nothing works to me.
It seems to be a bug. How do I avoid the memory leak?
Thank you.

Have a nice day
answered by mars.tsai (760 points)
0 votes
Hi,

Thank you for the feedback.
I'll look into the memory leak issue and update you.
answered by alex (17k points)
0 votes
Hi,

Please try this patch and let me know if it helps with the memory leaks.
answered by alex (17k points)
0 votes
No, it doesn't work.
Do you ever try the patch in above example and it works fine?
answered by mars.tsai (760 points)
0 votes
Hi,

We've made some improvements related to performance and memory leaks, so please try installing this patch.

Also, what is the indication for the memory leaks you found?
Can you send us a small project that reproduce this issue?
answered by NofarC (4k points)
0 votes
Hi,

The above patch still lead to memory leak.
I create another new project and try to simplify all the things.
Finally I found the key difference: "Use Multi-threaded Debug runtime library Or Multi-threaded Debug DLL"
Use /MTd will lead to memory leak, but /MDd(default) won't.
Hope this can help you to find the root cause.

Have a nice day.
answered by mars.tsai (760 points)
...