SHARE
TWEET

Untitled

a guest Jul 17th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. std::thread ServiceMessagesTestHelper::spawnFansServiceInNewThread()
  2. {
  3.     std::mutex mtx;
  4.     std::condition_variable cv;
  5.     bool FanServiceCreated = false;
  6.  
  7.     EXPECT_CALL(*TimerMsgStub::instance(), CTor(_)).Times(AnyNumber());
  8.     EXPECT_CALL(*TimerMsgStub::instance(), start(_, _, _)).Times(AnyNumber());
  9.     EXPECT_CALL(*TimerMsgStub::instance(), DTor()).Times(AnyNumber());
  10.     EXPECT_CALL(*TimerMsgStub::instance(), stop()).Times(AnyNumber());
  11.  
  12.     std::thread serviceThread([&]() {
  13.         {
  14.             std::unique_lock<std::mutex> lock(mtx);
  15.             std::cout << __FUNCTION__ << 1 <<std::endl;
  16.             service.reset(
  17.                 new FansServiceMock(constants::fanService, sf::InitialConf{}, constants::testAddr.cpId, config));
  18.             FanServiceCreated = true;
  19.             cv.notify_one();
  20.         }
  21.         auto serviceMock = std::dynamic_pointer_cast<FansServiceMock>(service);
  22.  
  23.         EXPECT_CALL(*serviceMock, createRpmMonitor()).Times(1);
  24.         EXPECT_CALL(*serviceMock, createDetectionMonitor()).Times(1);
  25.         EXPECT_CALL(*serviceMock, createFanStatusMonitor()).Times(1);
  26.         EXPECT_CALL(*serviceMock, createRpmControlLoop()).Times(1);
  27.         EXPECT_CALL(*serviceMock, createDefaultPwmFanStatus(_)).Times(AnyNumber());
  28.         EXPECT_CALL(*serviceMock, createDefaultFsFanStatus(_)).Times(AnyNumber());
  29.         EXPECT_CALL(*serviceMock, createDefaultFsRpmFanStatus(_)).Times(AnyNumber());
  30.         EXPECT_CALL(*serviceMock, setChanelPeriods()).Times(1);
  31.         // EXPECT_CALL(*serviceMock, setPulsesPerRev()).Times(1);
  32.  
  33.         service->start();
  34.     });
  35.  
  36.     std::unique_lock<std::mutex> lock(mtx);
  37.     cv.wait(lock, [&]() { return FanServiceCreated == true; });
  38.  
  39.     return serviceThread;
  40. }
  41.  
  42. std::thread ServiceMessagesTestHelper::spawnFansServiceWithFakesInNewThread()
  43. {
  44.     std::mutex mtx;
  45.     std::condition_variable cv;
  46.     bool FanServiceCreated = false;
  47.  
  48.     EXPECT_CALL(*TimerMsgStub::instance(), CTor(_)).Times(AnyNumber());
  49.     EXPECT_CALL(*TimerMsgStub::instance(), start(_, _, _)).Times(AnyNumber());
  50.     EXPECT_CALL(*TimerMsgStub::instance(), DTor()).Times(AnyNumber());
  51.     EXPECT_CALL(*TimerMsgStub::instance(), stop()).Times(AnyNumber());
  52.  
  53.     std::thread serviceThread([&]() {
  54.         {
  55.             std::unique_lock<std::mutex> lock(mtx);
  56.             std::cout << __FUNCTION__ << 1 <<std::endl;
  57.             service.reset(
  58.                 new FansServiceMock(constants::fanService, sf::InitialConf{}, constants::testAddr.cpId, config));
  59.             FanServiceCreated = true;
  60.             cv.notify_one();
  61.         }
  62.         auto serviceMock = std::dynamic_pointer_cast<FansServiceMock>(service);
  63.  
  64.         serviceMock->initDetectionMonitorFake();
  65.  
  66.         EXPECT_CALL(*serviceMock, createRpmMonitor()).Times(1);
  67.         EXPECT_CALL(*serviceMock, createDetectionMonitor()).Times(1);
  68.         EXPECT_CALL(*serviceMock, createFanStatusMonitor()).Times(1);
  69.         EXPECT_CALL(*serviceMock, createRpmControlLoop()).Times(1);
  70.         EXPECT_CALL(*serviceMock, createDefaultPwmFanStatus(_)).Times(AnyNumber());
  71.         EXPECT_CALL(*serviceMock, createDefaultFsFanStatus(_)).Times(AnyNumber());
  72.         EXPECT_CALL(*serviceMock, createDefaultFsRpmFanStatus(_)).Times(AnyNumber());
  73.         EXPECT_CALL(*serviceMock, setChanelPeriods()).Times(1);
  74.         // EXPECT_CALL(*serviceMock, setPulsesPerRev()).Times(1);
  75.  
  76.         service->start();
  77.     });
  78.  
  79.     std::unique_lock<std::mutex> lock(mtx);
  80.     cv.wait(lock, [&]() { return FanServiceCreated == true; });
  81.  
  82.     return serviceThread;
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top