TEST_F(INotifyTests, test_inotify_run) { // Assume event type is registered. event_pub_ = std::make_shared<INotifyEventPublisher>(); auto status = EventFactory::registerEventPublisher(event_pub_); EXPECT_TRUE(status.ok()); // Create a temporary file to watch, open writeable FILE* fd = fopen(kRealTestPath.c_str(), "w"); // Create a subscriber. auto sub = std::make_shared<TestINotifyEventSubscriber>(); EventFactory::registerEventSubscriber(sub); // Create a subscriptioning context auto mc = std::make_shared<INotifySubscriptionContext>(); mc->path = kRealTestPath; status = EventFactory::addSubscription( "inotify", Subscription::create("TestINotifyEventSubscriber", mc)); EXPECT_TRUE(status.ok()); // Create an event loop thread (similar to main) boost::thread temp_thread(EventFactory::run, "inotify"); EXPECT_TRUE(event_pub_->numEvents() == 0); // Cause an inotify event by writing to the watched path. fputs("inotify", fd); fclose(fd); // Wait for the thread's run loop to select. WaitForEvents(kMaxEventLatency); EXPECT_TRUE(event_pub_->numEvents() > 0); EventFactory::end(); temp_thread.join(); }
TEST_F(FSEventsTests, test_fsevents_run) { // Assume event type is registered. event_pub_ = std::make_shared<FSEventsEventPublisher>(); EventFactory::registerEventPublisher(event_pub_); // Create a subscriber. auto sub = std::make_shared<TestFSEventsEventSubscriber>(); EventFactory::registerEventSubscriber(sub); // Create a subscriptioning context auto mc = std::make_shared<FSEventsSubscriptionContext>(); mc->path = kRealTestPath; EventFactory::addSubscription("fsevents", Subscription::create("TestFSEventsEventSubscriber", mc)); // Create an event loop thread (similar to main) boost::thread temp_thread(EventFactory::run, "fsevents"); EXPECT_TRUE(event_pub_->numEvents() == 0); // Cause an fsevents event(s) by writing to the watched path. CreateEvents(); // Wait for the thread's run loop to select. WaitForEvents(kMaxEventLatency); EXPECT_TRUE(event_pub_->numEvents() > 0); EventFactory::end(); }