-1

I have a class as following:

class MyClass{
public:
    void my_method(Eigen::Tensor<double, 5> &param);
};

I would like to create a mock:

class MockMyClass {
public:
    MOCK_METHOD(void, my_method, (Eigen::Tensor<double, 5>), (override));
};

But I get the error

static assertion failed: This method does not take 2 arguments. Parenthesize all types with unproctected commas.

because of the comma in the Tensor type declaration <double, 5>. Is there a recommended way to deal with this problem?

Yes
  • 339
  • 3
  • 19

1 Answers1

0

As the documentation states, types can't have unprotected commas or else it won't compile (due to the way these macros are implemented). There are two options to work around that:

  1. Wrap each type with comma in another set of parentheses:
    MOCK_METHOD(void, my_method, ((Eigen::Tensor<double, 5>&)), (override));
  1. Use a type alias:
    using TensorType = Eigen::Tensor<double, 5>;
    MOCK_METHOD(void, my_method, (TensorType&), (override));
Yksisarvinen
  • 18,008
  • 2
  • 24
  • 52
  • When I try to use your suggestion with the double parenthesis, I now get the error `‘testing::internal::Function&)>::Result MockMyClass::my_method(testing::internal::ElemFromListImpl&, 0, 0>::type)’ marked ‘override’, but does not override` – Yes Apr 12 '23 at 16:25
  • @Yes Because your original function is not `virtual`. Compiler is very much right to warn you - you specifically asked it to check if function overrides, and it doesn't. – Yksisarvinen Apr 12 '23 at 17:05