daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Jan 18th, 2018 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include  <stdexcept>
  2. #include  <iostream>
  3. #include  <memory>
  4.  
  5. #include "gtest/gtest.h"
  6.  
  7.  
  8. class FooTest: public ::testing::Test {
  9. public:
  10.  
  11.     void SetUp() {}
  12.  
  13.  
  14.     void TearDown() {
  15.         std::cout << mMsg << " deleted" << std::endl;
  16.         throw std::runtime_error(mMsg);
  17.     }
  18.  
  19.     void SetLog(std::string msg) {
  20.         mMsg = msg;
  21.     }
  22.  
  23.     void TestBody() {}
  24. private:
  25.     std::string mMsg;
  26. };
  27.  
  28.  
  29. TEST_F(FooTest, TestExistException) {
  30.     EXPECT_ANY_THROW(
  31.         {
  32.             std::shared_ptr<FooTest> shrPtr(new  FooTest());
  33.             shrPtr = std::make_shared<FooTest>();
  34.             shrPtr->SetLog("local object");
  35.         }
  36.  
  37.     );
  38. }
  39.  
  40. std::shared_ptr<FooTest> shrPtrOther(new  FooTest());
  41. TEST_F(FooTest, TestLogException) {
  42.     shrPtrOther = std::make_shared<FooTest>();
  43.     shrPtrOther->SetLog("other object");
  44.  
  45.     try {
  46.  
  47.         { // begin scope of shrPtr
  48.             std::shared_ptr<FooTest> shrPtr(new FooTest());
  49.             shrPtr = std::make_shared<FooTest>();
  50.             shrPtr->SetLog("local object");
  51.         } // end scope of shrPtr
  52.  
  53.     } catch (std::exception &e) {
  54.         EXPECT_EQ(e.what(), (std::string )"local object");
  55.     }
  56. }
RAW Paste Data
Top