How to test input and output overloaded operator in C++ Gtest

前端 未结 2 1796
广开言路
广开言路 2021-01-26 04:48

I am using following example from here

Consider I have following class

#include 

class Distance {
private:
  int feet;             
  i         


        
2条回答
  •  情歌与酒
    2021-01-26 05:11

    What do you want to test about the operators?

    • That the stream is in a good state after writing to or reading from it.
      You can check for that.

    • That the output operator writes a particular string for a particular distance.
      You can do this by writing into a std::ostringstream and comparing the result of calling its str() member with your expectations.

    • That the input iterator reads a particular distance from a particular string.
      You can do this employing a std::istringstream initialized with the string, comparing the distance read from it with what you expect.

    • That the class eats its own dog food.
      Use a std::stringstream to write into, then read from it, and compare what you read with what you wrote.
      Note: This will currently fail.

提交回复
热议问题