2
* Copyright © 2015 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
19
#include "src/common/dispatch/utils.h"
21
#include <gtest/gtest.h>
22
#include <gmock/gmock.h>
24
namespace md = mir::dispatch;
26
TEST(DispatchUtilsTest, conversion_functions_roundtrip)
28
using namespace testing;
31
for (int event : {EPOLLIN, EPOLLOUT, EPOLLERR})
34
EXPECT_THAT(md::fd_event_to_epoll(md::epoll_to_fd_event(dummy)), Eq(event));
37
// HUP is special; FdEvent doesn't differentiate between remote hangup and local hangup
38
dummy.events = EPOLLHUP;
39
EXPECT_THAT(md::fd_event_to_epoll(md::epoll_to_fd_event(dummy)), Eq(EPOLLHUP | EPOLLRDHUP));
40
dummy.events = EPOLLRDHUP;
41
EXPECT_THAT(md::fd_event_to_epoll(md::epoll_to_fd_event(dummy)), Eq(EPOLLHUP | EPOLLRDHUP));
44
TEST(DispatchUtilsTest, epoll_to_fd_event_works_for_combinations)
46
using namespace testing;
50
dummy.events = EPOLLIN | EPOLLOUT;
51
EXPECT_THAT(md::epoll_to_fd_event(dummy), Eq(md::FdEvent::readable | md::FdEvent::writable));
53
dummy.events = EPOLLERR | EPOLLOUT;
54
EXPECT_THAT(md::epoll_to_fd_event(dummy), Eq(md::FdEvent::error | md::FdEvent::writable));
56
dummy.events = EPOLLIN | EPOLLRDHUP;
57
EXPECT_THAT(md::epoll_to_fd_event(dummy), Eq(md::FdEvent::readable | md::FdEvent::remote_closed));
60
TEST(DispatchUtilsTest, fd_event_to_epoll_works_for_combinations)
62
using namespace testing;
64
EXPECT_THAT(md::fd_event_to_epoll(md::FdEvent::readable | md::FdEvent::writable),
65
Eq(EPOLLIN | EPOLLOUT));
66
EXPECT_THAT(md::fd_event_to_epoll(md::FdEvent::error | md::FdEvent::writable),
67
Eq(EPOLLERR | EPOLLOUT));
68
EXPECT_THAT(md::fd_event_to_epoll(md::FdEvent::readable | md::FdEvent::remote_closed),
69
Eq(EPOLLIN | EPOLLHUP | EPOLLRDHUP));