Exemple #1
0
TEST(PiperTest, test_piper) {
  EventLoopImpl* eventLoop = new EventLoopImpl();
  std::thread* thread = new std::thread(RunningEventLoop, eventLoop);

  Piper* piper = new Piper(eventLoop);
  Resource* resource = new Resource();
  resource->count = 0;

  auto cb = [resource](){ resource->count++; };

  piper->ExecuteInEventLoop(cb);
  sleep(1);
  EXPECT_EQ(resource->count, 1);

  piper->ExecuteInEventLoop(cb);
  sleep(1);
  EXPECT_EQ(resource->count, 2);

  eventLoop->loopExit();

  // Wait for the thread to terminate
  thread->join();

  delete piper;
  delete resource;
  delete eventLoop;
  delete thread;
}