I want to create an Macro that will help in unit testing for c++. where i do not want to create a new object for only testing purposes. Is it possible to pass a class function reference like (ClassName::function) ?
#define TEST(func_ptr,X,Expercted) \
(__extension__ ( \
{ \
__typeof__(X) __x = (X); \
__typeof__(Expercted) __y = (Expercted); \
result= funct_ptr(__x);\
//------- do some testing stuffs-----\
} \
))
I have a Class A and its method square()
int main(){
TEST(&A::square,2,4);
return 0;
}
I want to test whether the square function returns the true value.
The Above codes gives error. How to solve the problem. Solution in other ways is appreciable
You are passing a non static member function pointer, which requires a class instance to call. If you change that to a static member or a free function, it should work OK.
or
Also your macro has a typo – func_ptr vs funct_ptr