mardi 1 septembre 2020

How to mock a range-based operator using gmock?

I have a class that inherits from std::map

class LeMap : public std::map<int,int>
{
  ...
};

I have another class that is supposed to loop over its elments:

class LeMapUser {
  LeMap mMap;
  public:
  void printElements()
  { 
    for( auto& element : mMap ) { whatever(element); }
  }
  private:
  void whatever(int element){ ... }
};

Is it possible to mock LeMap in order to test whatever using gmock ? Briefly: what operator should I overload to execute the loop?

Aucun commentaire:

Enregistrer un commentaire