31 # include <netinet/in.h>
33 # include <sys/socket.h>
36 # include <winsock2.h>
37 # include <ws2tcpip.h>
38 typedef unsigned long int nfds_t;
41 #include <sys/types.h>
48 #include <gtest/gtest.h>
57 int __wrap_poll(
struct pollfd *fds, nfds_t nfds,
int timeout) {
72 int mock_poll(
struct pollfd *fds, nfds_t nfds,
int timeout) {
79 for(nfds_t i=0; i<nfds && i<
poll_fds.size(); i++) {
80 EXPECT_EQ(
poll_fds[i].fd, fds[i].fd);
81 EXPECT_EQ(
poll_fds[i].events, fds[i].events);
82 fds[i].revents =
poll_fds[i].revents;
92 ts.tv_sec = timeout / 1000;
93 ts.tv_nsec = (timeout % 1000) * 1000000;
99 ret = nanosleep(&ts, &ts);
103 }
while( ret != 0 && errno == EINTR);
110 void Expect_poll(std::vector<pollfd> fds,
int timeout,
int _errno,
int ret) {
111 EXPECT_EQ(0,
poll_calls) <<
"Test bug: Cannot expect more than one call to poll";
124 : handleEvent_calls(0), last_event(0), event_result(0),
close_calls(0) {
133 last_event = eventType;
149 #define EXPECT_CLOSE_CALLS(n) \
151 EXPECT_EQ(m.close_calls, n); \
155 #define EXPECT_EVENTS(n) \
157 EXPECT_EQ(m.handleEvent_calls, n); \
158 m.handleEvent_calls = 0; \
161 #define EXPECT_EVENT(event) \
163 EXPECT_EQ(m.last_event, event); \
164 EXPECT_EQ(m.handleEvent_calls, 1); \
165 m.handleEvent_calls = 0; \
172 pollfd f = { .fd = 4, .events = 0, .revents = 0 };
231 EXPECT_EQ(dispatch._sources.size(), 1u);
234 fds[0].events = POLLIN;
243 fds[0].events = POLLIN;
244 fds[0].revents = POLLIN;
255 EXPECT_EQ(dispatch._sources.size(), 1u);
258 fds[0].events = POLLOUT;
259 fds[0].revents = POLLOUT;
267 EXPECT_EQ(dispatch._sources.size(), 0u);
279 EXPECT_EQ(dispatch._sources.size(), 1u);
282 fds[0].events = POLLOUT;
288 EXPECT_EQ(dispatch._sources.size(), 1u);
294 EXPECT_EQ(dispatch._sources.size(), 1u);
298 fds[0].events = POLLOUT;
299 fds[0].revents = POLLOUT;
308 EXPECT_EQ(dispatch._sources.size(), 0u);
320 EXPECT_EQ(dispatch._sources.size(), 1u);
323 fds[0].events = POLLPRI;
331 fds[0].events = POLLPRI;
332 fds[0].revents = POLLPRI;
344 EXPECT_EQ(dispatch._sources.size(), 1u);
348 fds[0].events = POLLOUT;
349 fds[0].revents = POLLOUT;
354 EXPECT_EQ(dispatch._sources.size(), 1u);
357 int main(
int argc,
char **argv)
359 ::testing::InitGoogleTest(&argc, argv);
360 return RUN_ALL_TESTS();