Mock CTRE WPI_TalonFX

How can we mock (gmock) a WPI_TalonFX interface?

We are trying to take advantage of the testing capabilities of the build system.

In order to test on the desktop, we cannot directly use class like the WPI_FalconFX C++ class.
In order to mock the class we basically need an interface or implementation with a
default constructor (or other trivial constructor).

The class hierarchy for WPI_TalonFX is interestingly complex with many public virtual inheritance
classes. I narrowed the combination that devolves to no constructor and all interfaces to

  class ITalonFX
  : public virtual ctre::phoenix::motorcontrol::IMotorController
  , public virtual ctre::phoenix::motorcontrol::IMotorControllerEnhanced
  , public virtual frc::SpeedController
  , public frc::SendableBase
  {
  }

But I cannot assign to an instance of this class:

WPI_TalonFX realTalon{0};
ITalonFX* talonPtr{&realTalon};
error: cannot convert 'WPI_TalonFX* {aka ctre::phoenix::motorcontrol::can::WPI_TalonFX*}' to 'ITalonFX*' in initialization

Is there a magic incantation that will allow me to create a gmock instance for WPI_TalonFX?

Thanks!

I would prefer to use an interface class for mocking (there are plenty of them running around in CTRE).

But perhaps I could use the template method described in Mocking Non-virtual Methods.

A bit more work, but could prove more effective.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.