~mir-team/mir/development-branch

« back to all changes in this revision

Viewing changes to tests/unit-tests/input/android/test_android_input_sender.cpp

merge trunk and resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
17
17
 */
18
18
 
 
19
#define MIR_INCLUDE_DEPRECATED_EVENT_HEADER
 
20
 
19
21
#include "src/server/input/android/android_input_channel.h"
20
22
#include "src/server/input/android/input_sender.h"
21
23
#include "src/server/report/null_report_factory.h"
22
24
 
23
 
#include "mir_test_doubles/mock_main_loop.h"
24
25
#include "mir_test_doubles/stub_scene_surface.h"
25
26
#include "mir_test_doubles/mock_input_surface.h"
26
27
#include "mir_test_doubles/mock_input_send_observer.h"
27
28
#include "mir_test_doubles/stub_scene.h"
28
29
#include "mir_test_doubles/mock_scene.h"
29
 
#include "mir_test_doubles/stub_timer.h"
 
30
#include "mir_test_doubles/triggered_main_loop.h"
30
31
#include "mir_test/fake_shared.h"
31
32
#include "mir_test/event_matchers.h"
32
33
 
38
39
 
39
40
#include <boost/exception/all.hpp>
40
41
 
41
 
#include <vector>
42
 
#include <algorithm>
 
42
//#include <algorithm>
43
43
#include <cstring>
44
44
 
45
45
namespace mi = mir::input;
75
75
    std::shared_ptr<ms::Observer> observer;
76
76
};
77
77
 
78
 
class TriggeredMainLoop : public ::testing::NiceMock<mtd::MockMainLoop>
79
 
{
80
 
public:
81
 
    typedef ::testing::NiceMock<mtd::MockMainLoop> base;
82
 
    typedef std::function<void(int)> fd_callback;
83
 
    typedef std::function<void(int)> signal_callback;
84
 
    typedef std::function<void()> callback;
85
 
 
86
 
    void register_fd_handler(std::initializer_list<int> fds, void const* owner, fd_callback const& handler) override
87
 
    {
88
 
        base::register_fd_handler(fds, owner, handler);
89
 
        for (int fd : fds)
90
 
        {
91
 
            fd_callbacks.emplace_back(Item{fd, owner, handler});
92
 
        }
93
 
    }
94
 
 
95
 
    void unregister_fd_handler(void const* owner)
96
 
    {
97
 
        base::unregister_fd_handler(owner);
98
 
        fd_callbacks.erase(
99
 
            remove_if(
100
 
                begin(fd_callbacks),
101
 
                end(fd_callbacks),
102
 
                [owner](Item const& item)
103
 
                {
104
 
                    return item.owner == owner;
105
 
                }),
106
 
            end(fd_callbacks)
107
 
            );
108
 
    }
109
 
 
110
 
    void trigger_pending_fds()
111
 
    {
112
 
        fd_set read_fds;
113
 
        FD_ZERO(&read_fds);
114
 
        int max_fd = 0;
115
 
 
116
 
        for (auto const & item : fd_callbacks)
117
 
        {
118
 
            FD_SET(item.fd, &read_fds);
119
 
            max_fd = std::max(item.fd, max_fd);
120
 
        }
121
 
 
122
 
        struct timeval do_not_wait{0, 0};
123
 
 
124
 
        if (select(max_fd+1, &read_fds, nullptr, nullptr, &do_not_wait))
125
 
        {
126
 
            for (auto const & item : fd_callbacks)
127
 
            {
128
 
                FD_ISSET(item.fd, &read_fds);
129
 
                item.callback(item.fd);
130
 
            }
131
 
        }
132
 
    }
133
 
 
134
 
    std::unique_ptr<mir::time::Alarm> notify_in(std::chrono::milliseconds delay,
135
 
                                                callback call) override
136
 
    {
137
 
        base::notify_in(delay, call);
138
 
        timeout_callbacks.push_back(call);
139
 
        return std::unique_ptr<mir::time::Alarm>{new mtd::StubAlarm};
140
 
    }
141
 
 
142
 
    void fire_all_alarms()
143
 
    {
144
 
        for(auto const& callback : timeout_callbacks)
145
 
            callback();
146
 
    }
147
 
 
148
 
private:
149
 
    std::vector<callback> timeout_callbacks;
150
 
 
151
 
private:
152
 
    struct Item
153
 
    {
154
 
        int fd;
155
 
        void const* owner;
156
 
        fd_callback callback;
157
 
    };
158
 
    std::vector<Item> fd_callbacks;
159
 
};
160
 
 
161
78
}
162
79
 
163
80
class AndroidInputSender : public ::testing::Test
205
122
    droidinput::sp<droidinput::InputChannel> client_channel{new droidinput::InputChannel(droidinput::String8("test"), channel->client_fd())};
206
123
    droidinput::InputConsumer consumer{client_channel};
207
124
 
208
 
    TriggeredMainLoop loop;
 
125
    mtd::TriggeredMainLoop loop;
209
126
    testing::NiceMock<mtd::MockInputSendObserver> observer;
210
127
 
211
128
    MirEvent key_event;