How to GoogleTest a private method/enum class inside a Normal or Singleton Class in c++
<p>I need to Gtest a Private Method of the singleton class. I tried by using Friend class of the singleton. but no help.
It says the Private cant be called. i added the class, Gtest tried, Output error. feel free to ask any more clarifcation, thanks in advance!!
Please ignore the Typos if any..</p>

<h1>Below Singleton Class to be Gtested:</h1>

<pre><code>class Listener: public CommonListen {
 public:
  friend class test_listener;
  Listener(task_id taskid, const string thread_name) :
    CommonListen(taskid, thread_name ) { }
  static Listener* GetInstance() {
     if (Listener_ptr_ == nullptr) {
       Listener_ptr_ = new
           Listener(LISTENER_ID, ListenerName);
     }
     return Listener_ptr_;
  }

 private:
  // Override the base's method
  void SetupPub();
  static Listener* Listener_ptr_;
};
</code></pre>

<h1>I tired GTest using Friend class like below:</h1>

<pre><code>class test_listener : public ::testing::Test {
 public:
  void call_private(void);
};

TEST_F(test_listener, create_listener) {
  call_private();
}
void test_listener::call_private() {
  (Listener::GetInstance())-&gt;SetupPub();
}
</code></pre>

<h1>Throws Error Like below:</h1>

<pre><code> error: 'virtual void Listener::SetupPub()' is private
   void SetupPub();
        ^
test_listener.cc:48:63: error: within this context
   (Listener::GetInstance())-&gt;SetupPub();
                                                               ^
make[2]: *** [test_listener.o] Error 1
</code></pre>

<p>Please share your view</p>

<p><strong>@@@@Not Working Case:@@@@</strong></p>

<pre><code>class xxx : public yyy {
  friend class test_xxx;

  enum class State : std::int8_t { SSS = 1,
        DDD, FFF};
  enum class AlignmentFlags : std::int8_t { ZZZ= 1,
        CCC= 2, VVV= 4, BBB= 8,
        NNN= 3, MMM= 12};

 public:
  // **********
}
</code></pre>

<p>While calling the above private enum class after "#define private public" used below erroroccurs:</p>

<pre><code>../src/qqq/xxx.h:189:14: error: 'enum class 
xxx::AlignmentFlags' is private
   enum class AlignmentFlags : std::int8_t { ZZZ = 1,
</code></pre>

<p><strong>Accessed Like :</strong></p>

<pre><code>xxx-&gt;SetAlignmentFlags(12);
</code></pre>