main.cpp 828 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /////////////////////////////
  2. // In the header file
  3. #include <sstream>
  4. using namespace std;
  5. class Salutation
  6. {
  7. public:
  8. static string greet(const string& name);
  9. };
  10. ///////////////////////////////////////
  11. // In the class implementation file
  12. string Salutation::greet(const string& name) {
  13. ostringstream s;
  14. s << "Hello " << name << "!";
  15. return s.str();
  16. }
  17. ///////////////////////////////////////////
  18. // In the test file
  19. #include <gtest/gtest.h>
  20. TEST(SalutationTest, Static) {
  21. EXPECT_EQ(string("Hello World!"), Salutation::greet("World"));
  22. }
  23. int main(int argc, char **argv) {
  24. #if _MSC_VER
  25. _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
  26. //void *testWhetherMemoryLeakDetectionWorks = malloc(1);
  27. #endif
  28. ::testing::InitGoogleTest(&argc, argv);
  29. return RUN_ALL_TESTS();
  30. }