0

I am trying to learn google test framework, and I came across an example here. I have something similar to "accepted solution", but I wanted to test it while having class methods as protected.

class GTEST_static_class {
  protected:
    virtual void display() { std::cout << "inside the GTEST_static_class:: display\n"; }
    virtual ~GTEST_static_class() {}
};

class GTest_static_example : public ::testing::Test {
  public:
    void call_display(GTEST_static_class *instance) {
      instance->display();
      std::cout << "display called from GTest_static_example\n";
    }
};

How do I modify that piece of code (accepted solution) to make it work while having class like mentioned above?

273K
  • 29,503
  • 10
  • 41
  • 64
Anees
  • 49
  • 5

1 Answers1

1

Add a friend class GTest_static_example:

class GTEST_static_class {
  protected:
    virtual void display() { std::cout << "inside the GTEST_static_class:: display\n"; }
    virtual ~GTEST_static_class() {}
    friend class GTest_static_example;
};
273K
  • 29,503
  • 10
  • 41
  • 64