~andreas-pokorny/mir/activate-pointer-acceleration

« back to all changes in this revision

Viewing changes to tests/unit-tests/dispatch/test_dispatch_utils.cpp

  • Committer: Tarmac
  • Author(s): Christopher James Halse Rogers, Christopher James Halse Rogers
  • Date: 2015-02-18 04:25:26 UTC
  • mfrom: (2239.7.33 add-multiplexing-dispatchable)
  • Revision ID: tarmac-20150218042526-j1ei9ni2k4tua4e9
Add MultiplexingDispatchable.

This does exactly what it says; multiplexes multiple Dispatchables into a single Dispatchable. Each dispatch() of the MultiplexingDispatchable dispatches to a child Dispatchable with active events.

Approved by Alexandros Frantzis, PS Jenkins bot, Robert Carr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2015 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
 
17
 */
 
18
 
 
19
#include "src/common/dispatch/utils.h"
 
20
 
 
21
#include <gtest/gtest.h>
 
22
#include <gmock/gmock.h>
 
23
 
 
24
namespace md = mir::dispatch;
 
25
 
 
26
TEST(DispatchUtilsTest, conversion_functions_roundtrip)
 
27
{
 
28
    using namespace testing;
 
29
 
 
30
    epoll_event dummy;
 
31
    for (int event : {EPOLLIN, EPOLLOUT, EPOLLERR})
 
32
    {
 
33
        dummy.events = event;
 
34
        EXPECT_THAT(md::fd_event_to_epoll(md::epoll_to_fd_event(dummy)), Eq(event));
 
35
    }
 
36
 
 
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));
 
42
}
 
43
 
 
44
TEST(DispatchUtilsTest, epoll_to_fd_event_works_for_combinations)
 
45
{
 
46
    using namespace testing;
 
47
 
 
48
    epoll_event dummy;
 
49
 
 
50
    dummy.events = EPOLLIN | EPOLLOUT;
 
51
    EXPECT_THAT(md::epoll_to_fd_event(dummy), Eq(md::FdEvent::readable | md::FdEvent::writable));
 
52
 
 
53
    dummy.events = EPOLLERR | EPOLLOUT;
 
54
    EXPECT_THAT(md::epoll_to_fd_event(dummy), Eq(md::FdEvent::error | md::FdEvent::writable));
 
55
 
 
56
    dummy.events = EPOLLIN | EPOLLRDHUP;
 
57
    EXPECT_THAT(md::epoll_to_fd_event(dummy), Eq(md::FdEvent::readable | md::FdEvent::remote_closed));
 
58
}
 
59
 
 
60
TEST(DispatchUtilsTest, fd_event_to_epoll_works_for_combinations)
 
61
{
 
62
    using namespace testing;
 
63
 
 
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));
 
70
}