Merge lp:~dandrader/mir/mergeFakeInputReaders into lp:mir
- mergeFakeInputReaders
- Merge into development-branch
Status: | Merged |
---|---|
Approved by: | Robert Carr |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1109 |
Proposed branch: | lp:~dandrader/mir/mergeFakeInputReaders |
Merge into: | lp:mir |
Diff against target: |
1422 lines (+534/-600) 3 files modified
include/test/mir_test/fake_event_hub.h (+88/-64) tests/mir_test_doubles/fake_event_hub.cpp (+432/-117) tests/unit-tests/android_input/input_reader.cpp (+14/-419) |
To merge this branch: | bzr merge lp:~dandrader/mir/mergeFakeInputReaders |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Robert Carr (community) | Approve | ||
Alan Griffiths | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Daniel van Vugt | Needs Information | ||
Review via email: mp+188662@code.launchpad.net |
Commit message
android-input - Merge the two existing FakeEventHub implementations
-Enables the FakeEventHub from tests/unit-
to be used elsewhere
-No need to keep two distinct implementations.
-Reduces confusion in the test code base.
Description of the change
PS Jenkins bot (ps-jenkins) wrote : | # |
Daniel van Vugt (vanvugt) wrote : | # |
I thought all 3rd party code had to live under 3rd_party/ ?
Seems like we're not doing that any more. e.g. tests/mir_
Daniel d'Andrada (dandrader) wrote : | # |
> I thought all 3rd party code had to live under 3rd_party/ ?
>
> Seems like we're not doing that any more. e.g.
> tests/mir_
So what directory structure you suggest for those tests and fake implementations?
Bear in mind that I'm preparing the ground for my modifications to android-input, so it won't be strictly 3rd party.
Daniel van Vugt (vanvugt) wrote : | # |
I don't know. I'm not sure if it's worth blocking on yet... Unless this is the first time we've put 3rd party code outside of 3rd_party. Maybe racarr had a plan in mind?
Alan Griffiths (alan-griffiths) wrote : | # |
I think we need a discussion about migrating this code into our codebase. We obviously relax our rules for style in 3rd_party, but under include, src or test it ought to conform.
237 +using mir::input:
238 +using namespace android;
Nit, but project style is to use namespace aliases in preference to bringing names into global namespace.
~~~~
242 + const nsecs_t ARBITRARY_TIME = 1234;
UPPERCASE is reserved for macros - http://
Daniel d'Andrada (dandrader) wrote : | # |
> 237 +using mir::input:
> 238 +using namespace android;
>
> Nit, but project style is to use namespace aliases in preference to bringing
> names into global namespace.
But what's the advantage of prepending everything with namespace acronyms? IMHO this is an unnecessary clutter/boilerplate that just hampers readability.
In this specific case we would have:
void mia::FakeEventH
As opposed to simply:
void FakeEventHub::foo()
What good is that "mia::" prefix bringing us? We are inside fake_event_hub.cpp and we refer to no other FakeEventHub from any other namespace. Actually no other FakeEventHub even exist in our code base.
It makes all the sense in the world to avoid the "using foo;" in header files as it unwittingly contaminates anyone that includes it but what's the point of avoiding it in .cpp files?
You use namespaces to avoid naming clashes. But if there are no possible clashes to be had, what's the point? It's just clutter and the "using ..." declaration was invented to solve that.
Can we have a discussion on changing the project style regarding that?
Daniel d'Andrada (dandrader) wrote : | # |
> 242 + const nsecs_t ARBITRARY_TIME = 1234;
>
> UPPERCASE is reserved for macros - http://
> html?showone=
Done.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:1097
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Daniel van Vugt (vanvugt) wrote : | # |
I agree with Daniel. Namespace aliases just hamper readability. I prefer carefully placed "using namespace". There's less syntactical coupling and it's more readable. We have already begun landing code of that style (my own).
Daniel d'Andrada (dandrader) wrote : | # |
> I don't know. I'm not sure if it's worth blocking on yet... Unless this is the
> first time we've put 3rd party code outside of 3rd_party.
There's tests/unit-
Alan Griffiths (alan-griffiths) wrote : | # |
Better landed and deal with any remaining issues later
Robert Carr (robertcarr) wrote : | # |
Sorry! Looked at this yesterday afternoon but forgot to comment
LGTM
Preview Diff
1 | === modified file 'include/test/mir_test/fake_event_hub.h' |
2 | --- include/test/mir_test/fake_event_hub.h 2013-05-13 09:35:44 +0000 |
3 | +++ include/test/mir_test/fake_event_hub.h 2013-10-02 11:08:26 +0000 |
4 | @@ -1,5 +1,5 @@ |
5 | /* |
6 | - * Copyright © 2012 Canonical Ltd. |
7 | + * Copyright © 2012-2013 Canonical Ltd. |
8 | * |
9 | * This program is free software: you can redistribute it and/or modify it |
10 | * under the terms of the GNU General Public License version 3, |
11 | @@ -13,7 +13,8 @@ |
12 | * You should have received a copy of the GNU General Public License |
13 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
14 | * |
15 | - * Authored by: Robert Carr <robert.carr@canonical.com |
16 | + * Authored by: Robert Carr <robert.carr@canonical.com> |
17 | + * Daniel d'Andrada <daniel.dandrada@canonical.com> |
18 | */ |
19 | |
20 | #ifndef MIR_TEST_FAKE_EVENT_HUB_H_ |
21 | @@ -43,6 +44,29 @@ |
22 | class FakeEventHub : public droidinput::EventHubInterface |
23 | { |
24 | public: |
25 | + struct KeyInfo { |
26 | + int32_t keyCode; |
27 | + uint32_t flags; |
28 | + }; |
29 | + |
30 | + typedef struct FakeDevice |
31 | + { |
32 | + uint32_t classes; |
33 | + droidinput::InputDeviceIdentifier identifier; |
34 | + droidinput::PropertyMap configuration; |
35 | + droidinput::KeyedVector<int, droidinput::RawAbsoluteAxisInfo> absoluteAxes; |
36 | + droidinput::KeyedVector<int, bool> relativeAxes; |
37 | + droidinput::KeyedVector<int32_t, int32_t> keyCodeStates; |
38 | + droidinput::KeyedVector<int32_t, int32_t> scanCodeStates; |
39 | + droidinput::KeyedVector<int32_t, int32_t> switchStates; |
40 | + droidinput::KeyedVector<int32_t, int32_t> absoluteAxisValue; |
41 | + droidinput::KeyedVector<int32_t, KeyInfo> keysByScanCode; |
42 | + droidinput::KeyedVector<int32_t, KeyInfo> keysByUsageCode; |
43 | + droidinput::KeyedVector<int32_t, bool> leds; |
44 | + droidinput::Vector<droidinput::VirtualKeyDefinition> virtualKeys; |
45 | + std::map<int, bool> input_properties; |
46 | + } FakeDevice; |
47 | + |
48 | FakeEventHub(); |
49 | virtual ~FakeEventHub(); |
50 | |
51 | @@ -52,62 +76,41 @@ |
52 | // cursor device in the android input stack. |
53 | static const int BuiltInCursorID = droidinput::BUILT_IN_KEYBOARD_ID + 1; |
54 | |
55 | - virtual uint32_t getDeviceClasses(int32_t deviceId) const; |
56 | - |
57 | - virtual droidinput::InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const; |
58 | - |
59 | - virtual void getConfiguration(int32_t deviceId, |
60 | - droidinput::PropertyMap* outConfiguration) const; |
61 | - |
62 | - virtual droidinput::status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
63 | - droidinput::RawAbsoluteAxisInfo* outAxisInfo) const; |
64 | - |
65 | - virtual bool hasRelativeAxis(int32_t deviceId, int axis) const; |
66 | - |
67 | - virtual bool hasInputProperty(int32_t deviceId, int property) const; |
68 | - |
69 | - virtual droidinput::status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, |
70 | - int32_t* outKeycode, uint32_t* outFlags) const; |
71 | - |
72 | - virtual droidinput::status_t mapAxis(int32_t deviceId, int32_t scanCode, |
73 | - droidinput::AxisInfo* outAxisInfo) const; |
74 | - |
75 | - virtual void setExcludedDevices(const droidinput::Vector<droidinput::String8>& devices); |
76 | - |
77 | - virtual size_t getEvents(int timeoutMillis, droidinput::RawEvent* buffer, |
78 | - size_t bufferSize); |
79 | - |
80 | - virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const; |
81 | - virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const; |
82 | - virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const; |
83 | - virtual droidinput::status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, |
84 | - int32_t* outValue) const; |
85 | - |
86 | - virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, |
87 | - const int32_t* keyCodes, uint8_t* outFlags) const; |
88 | - |
89 | - virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const; |
90 | - virtual bool hasLed(int32_t deviceId, int32_t led) const; |
91 | - virtual void setLedState(int32_t deviceId, int32_t led, bool on); |
92 | - |
93 | - virtual void getVirtualKeyDefinitions(int32_t deviceId, |
94 | - droidinput::Vector<droidinput::VirtualKeyDefinition>& outVirtualKeys) const; |
95 | - |
96 | - virtual droidinput::sp<droidinput::KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const; |
97 | - virtual bool setKeyboardLayoutOverlay(int32_t deviceId, |
98 | - const droidinput::sp<droidinput::KeyCharacterMap>& map); |
99 | - |
100 | - virtual void vibrate(int32_t deviceId, nsecs_t duration); |
101 | - virtual void cancelVibrate(int32_t deviceId); |
102 | - |
103 | - virtual void requestReopenDevices(); |
104 | - |
105 | - virtual void wake(); |
106 | - |
107 | - virtual void dump(droidinput::String8& dump); |
108 | - |
109 | - virtual void monitor(); |
110 | - virtual void flush(); |
111 | + // From EventHubInterface |
112 | + uint32_t getDeviceClasses(int32_t deviceId) const override; |
113 | + droidinput::InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const override; |
114 | + void getConfiguration(int32_t deviceId, droidinput::PropertyMap* outConfiguration) const override; |
115 | + droidinput::status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
116 | + droidinput::RawAbsoluteAxisInfo* outAxisInfo) const override; |
117 | + bool hasRelativeAxis(int32_t deviceId, int axis) const override; |
118 | + bool hasInputProperty(int32_t deviceId, int property) const override; |
119 | + droidinput::status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, int32_t* outKeycode, |
120 | + uint32_t* outFlags) const override; |
121 | + droidinput::status_t mapAxis(int32_t deviceId, int32_t scanCode, |
122 | + droidinput::AxisInfo* outAxisInfo) const override; |
123 | + void setExcludedDevices(const droidinput::Vector<droidinput::String8>& devices) override; |
124 | + size_t getEvents(int timeoutMillis, droidinput::RawEvent* buffer, size_t bufferSize) override; |
125 | + int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const override; |
126 | + int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const override; |
127 | + int32_t getSwitchState(int32_t deviceId, int32_t sw) const override; |
128 | + droidinput::status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const override; |
129 | + bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, |
130 | + uint8_t* outFlags) const override; |
131 | + bool hasScanCode(int32_t deviceId, int32_t scanCode) const override; |
132 | + bool hasLed(int32_t deviceId, int32_t led) const override; |
133 | + void setLedState(int32_t deviceId, int32_t led, bool on) override; |
134 | + void getVirtualKeyDefinitions(int32_t deviceId, |
135 | + droidinput::Vector<droidinput::VirtualKeyDefinition>& outVirtualKeys) const override; |
136 | + droidinput::sp<droidinput::KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const override; |
137 | + bool setKeyboardLayoutOverlay(int32_t deviceId, |
138 | + const droidinput::sp<droidinput::KeyCharacterMap>& map) override; |
139 | + void vibrate(int32_t deviceId, nsecs_t duration) override; |
140 | + void cancelVibrate(int32_t deviceId) override; |
141 | + void requestReopenDevices() override; |
142 | + void wake() override; |
143 | + void dump(droidinput::String8& dump) override; |
144 | + void monitor() override; |
145 | + void flush() override; |
146 | |
147 | void synthesize_builtin_keyboard_added(); |
148 | void synthesize_builtin_cursor_added(); |
149 | @@ -116,22 +119,43 @@ |
150 | void synthesize_event(const synthesis::KeyParameters ¶meters); |
151 | void synthesize_event(const synthesis::ButtonParameters ¶meters); |
152 | void synthesize_event(const synthesis::MotionParameters ¶meters); |
153 | + void synthesize_event(nsecs_t when, int32_t deviceId, int32_t type, int32_t code, int32_t value); |
154 | + |
155 | + void addDevice(int32_t deviceId, const std::string& name, uint32_t classes); |
156 | + void removeDevice(int32_t deviceId); |
157 | + void finishDeviceScan(); |
158 | + void addConfigurationProperty(int32_t device_id, const std::string& key, const std::string& value); |
159 | + void addConfigurationMap(int32_t device_id, const droidinput::PropertyMap* configuration); |
160 | + void addAbsoluteAxis(int32_t device_id, int axis, int32_t minValue, int32_t maxValue, |
161 | + int flat, int fuzz, int resolution = 0); |
162 | + void addRelativeAxis(int32_t device_id, int32_t axis); |
163 | + void setKeyCodeState(int32_t deviceId, int32_t keyCode, int32_t state); |
164 | + void setScanCodeState(int32_t deviceId, int32_t scanCode, int32_t state); |
165 | + void setSwitchState(int32_t deviceId, int32_t switchCode, int32_t state); |
166 | + void setAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t value); |
167 | + void addKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, int32_t keyCode, uint32_t flags); |
168 | + void addLed(int32_t deviceId, int32_t led, bool initialState); |
169 | + bool getLedState(int32_t deviceId, int32_t led); |
170 | + droidinput::Vector<std::string>& getExcludedDevices(); |
171 | + void addVirtualKeyDefinition(int32_t deviceId, const droidinput::VirtualKeyDefinition& definition); |
172 | + const FakeDevice* getDevice(int32_t deviceId) const; |
173 | + FakeDevice* getDevice(int32_t deviceId); |
174 | + size_t eventsQueueSize() const; |
175 | |
176 | // list of RawEvents available for consumption via getEvents |
177 | std::mutex guard; |
178 | std::list<droidinput::RawEvent> events_available; |
179 | |
180 | - typedef struct FakeDevice |
181 | - { |
182 | - uint32_t classes; |
183 | - droidinput::InputDeviceIdentifier identifier; |
184 | - std::map<int, bool> input_properties; |
185 | - } FakeDevice; |
186 | |
187 | std::map<int32_t, FakeDevice> device_from_id; |
188 | |
189 | droidinput::KeyMap keymap; |
190 | |
191 | + droidinput::Vector<droidinput::String8> excluded_devices; |
192 | + |
193 | +private: |
194 | + const KeyInfo* getKey(const FakeDevice* device, int32_t scanCode, int32_t usageCode) const; |
195 | + |
196 | }; |
197 | } |
198 | } |
199 | |
200 | === modified file 'tests/mir_test_doubles/fake_event_hub.cpp' |
201 | --- tests/mir_test_doubles/fake_event_hub.cpp 2013-05-13 09:35:44 +0000 |
202 | +++ tests/mir_test_doubles/fake_event_hub.cpp 2013-10-02 11:08:26 +0000 |
203 | @@ -1,6 +1,25 @@ |
204 | +/* |
205 | + * Copyright (C) 2012-2013 Canonical Ltd. |
206 | + * Copyright (C) 2010 The Android Open Source Project |
207 | + * |
208 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
209 | + * you may not use this file except in compliance with the License. |
210 | + * You may obtain a copy of the License at |
211 | + * |
212 | + * http://www.apache.org/licenses/LICENSE-2.0 |
213 | + * |
214 | + * Unless required by applicable law or agreed to in writing, software |
215 | + * distributed under the License is distributed on an "AS IS" BASIS, |
216 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
217 | + * See the License for the specific language governing permissions and |
218 | + * limitations under the License. |
219 | + */ |
220 | #include "mir_test/fake_event_hub.h" |
221 | |
222 | +// from android-input |
223 | #include <androidfw/Keyboard.h> |
224 | +#include <std/Errors.h> |
225 | + |
226 | #include <thread> |
227 | #include <chrono> |
228 | |
229 | @@ -17,19 +36,26 @@ |
230 | using droidinput::VirtualKeyDefinition; |
231 | |
232 | namespace mi = mir::input; |
233 | -namespace mia = mir::input::android; |
234 | namespace mis = mir::input::synthesis; |
235 | |
236 | -mia::FakeEventHub::FakeEventHub() |
237 | +using mir::input::android::FakeEventHub; |
238 | +using namespace android; |
239 | + |
240 | +namespace { |
241 | + // An arbitrary time value. |
242 | + const nsecs_t arbitrary_time = 1234; |
243 | +} // anonymous namespace |
244 | + |
245 | +FakeEventHub::FakeEventHub() |
246 | { |
247 | keymap.loadGenericMaps(); |
248 | } |
249 | |
250 | -mia::FakeEventHub::~FakeEventHub() |
251 | +FakeEventHub::~FakeEventHub() |
252 | { |
253 | } |
254 | |
255 | -uint32_t mia::FakeEventHub::getDeviceClasses(int32_t deviceId) const |
256 | +uint32_t FakeEventHub::getDeviceClasses(int32_t deviceId) const |
257 | { |
258 | if (deviceId == BuiltInKeyboardID) |
259 | { |
260 | @@ -52,7 +78,7 @@ |
261 | } |
262 | } |
263 | |
264 | -InputDeviceIdentifier mia::FakeEventHub::getDeviceIdentifier(int32_t deviceId) const |
265 | +InputDeviceIdentifier FakeEventHub::getDeviceIdentifier(int32_t deviceId) const |
266 | { |
267 | auto fake_device_iterator = device_from_id.find(deviceId); |
268 | |
269 | @@ -66,38 +92,51 @@ |
270 | } |
271 | } |
272 | |
273 | -void mia::FakeEventHub::getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const |
274 | +void FakeEventHub::getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const |
275 | { |
276 | - (void)deviceId; |
277 | - (void)outConfiguration; |
278 | + auto device_iterator = device_from_id.find(deviceId); |
279 | + if (device_iterator != device_from_id.end()) |
280 | + { |
281 | + *outConfiguration = device_iterator->second.configuration; |
282 | + } |
283 | } |
284 | |
285 | -status_t mia::FakeEventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis, |
286 | +status_t FakeEventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis, |
287 | RawAbsoluteAxisInfo* outAxisInfo) const |
288 | { |
289 | - (void)deviceId; |
290 | - (void)axis; |
291 | - (void)outAxisInfo; |
292 | + outAxisInfo->clear(); |
293 | + const FakeDevice* device = getDevice(deviceId); |
294 | + if (device) |
295 | + { |
296 | + ssize_t index = device->absoluteAxes.indexOfKey(axis); |
297 | + if (index >= 0) |
298 | + { |
299 | + *outAxisInfo = device->absoluteAxes.valueAt(index); |
300 | + return OK; |
301 | + } |
302 | + } |
303 | return -1; |
304 | } |
305 | |
306 | -bool mia::FakeEventHub::hasRelativeAxis(int32_t deviceId, int axis) const |
307 | +bool FakeEventHub::hasRelativeAxis(int32_t deviceId, int axis) const |
308 | { |
309 | - (void)deviceId; |
310 | - (void)axis; |
311 | + const FakeDevice* device = getDevice(deviceId); |
312 | + if (device) |
313 | + { |
314 | + return device->relativeAxes.indexOfKey(axis) >= 0; |
315 | + } |
316 | return false; |
317 | } |
318 | |
319 | -bool mia::FakeEventHub::hasInputProperty(int32_t deviceId, int property) const |
320 | +bool FakeEventHub::hasInputProperty(int32_t deviceId, int property) const |
321 | { |
322 | - auto fake_device_iterator = device_from_id.find(deviceId); |
323 | + const FakeDevice* device = getDevice(deviceId); |
324 | |
325 | - if (fake_device_iterator != device_from_id.end()) |
326 | + if (device) |
327 | { |
328 | - auto property_iterator = |
329 | - fake_device_iterator->second.input_properties.find(property); |
330 | + auto property_iterator = device->input_properties.find(property); |
331 | |
332 | - if (property_iterator != fake_device_iterator->second.input_properties.end()) |
333 | + if (property_iterator != device->input_properties.end()) |
334 | { |
335 | return property_iterator->second; |
336 | } |
337 | @@ -112,30 +151,71 @@ |
338 | } |
339 | } |
340 | |
341 | -status_t mia::FakeEventHub::mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, |
342 | +status_t FakeEventHub::mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, |
343 | int32_t* outKeycode, uint32_t* outFlags) const |
344 | { |
345 | - (void)deviceId; |
346 | - (void)usageCode; |
347 | - keymap.keyLayoutMap->mapKey(scanCode, usageCode, outKeycode, outFlags); |
348 | - return droidinput::OK; |
349 | -} |
350 | - |
351 | -status_t mia::FakeEventHub::mapAxis(int32_t deviceId, int32_t scanCode, |
352 | + const FakeDevice* device = getDevice(deviceId); |
353 | + if (device) |
354 | + { |
355 | + const KeyInfo* key = getKey(device, scanCode, usageCode); |
356 | + if (key) |
357 | + { |
358 | + if (outKeycode) |
359 | + { |
360 | + *outKeycode = key->keyCode; |
361 | + } |
362 | + if (outFlags) |
363 | + { |
364 | + *outFlags = key->flags; |
365 | + } |
366 | + return OK; |
367 | + } |
368 | + return NAME_NOT_FOUND; |
369 | + } |
370 | + else |
371 | + { |
372 | + keymap.keyLayoutMap->mapKey(scanCode, usageCode, outKeycode, outFlags); |
373 | + return droidinput::OK; |
374 | + } |
375 | +} |
376 | + |
377 | +const FakeEventHub::KeyInfo* FakeEventHub::getKey(const FakeDevice* device, |
378 | + int32_t scanCode, int32_t usageCode) const |
379 | +{ |
380 | + if (usageCode) |
381 | + { |
382 | + ssize_t index = device->keysByUsageCode.indexOfKey(usageCode); |
383 | + if (index >= 0) |
384 | + { |
385 | + return &device->keysByUsageCode.valueAt(index); |
386 | + } |
387 | + } |
388 | + if (scanCode) |
389 | + { |
390 | + ssize_t index = device->keysByScanCode.indexOfKey(scanCode); |
391 | + if (index >= 0) |
392 | + { |
393 | + return &device->keysByScanCode.valueAt(index); |
394 | + } |
395 | + } |
396 | + return NULL; |
397 | +} |
398 | + |
399 | +status_t FakeEventHub::mapAxis(int32_t deviceId, int32_t scanCode, |
400 | AxisInfo* outAxisInfo) const |
401 | { |
402 | (void)deviceId; |
403 | (void)scanCode; |
404 | (void)outAxisInfo; |
405 | - return -1; |
406 | + return NAME_NOT_FOUND; |
407 | } |
408 | |
409 | -void mia::FakeEventHub::setExcludedDevices(const Vector<String8>& devices) |
410 | +void FakeEventHub::setExcludedDevices(const Vector<String8>& devices) |
411 | { |
412 | - (void)devices; |
413 | + excluded_devices = devices; |
414 | } |
415 | |
416 | -size_t mia::FakeEventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) |
417 | +size_t FakeEventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) |
418 | { |
419 | size_t num_events_obtained = 0; |
420 | (void) timeoutMillis; |
421 | @@ -155,82 +235,145 @@ |
422 | return num_events_obtained; |
423 | } |
424 | |
425 | -int32_t mia::FakeEventHub::getScanCodeState(int32_t deviceId, int32_t scanCode) const |
426 | -{ |
427 | - (void)deviceId; |
428 | - (void)scanCode; |
429 | - return AKEY_STATE_UNKNOWN; |
430 | -} |
431 | - |
432 | -int32_t mia::FakeEventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const |
433 | -{ |
434 | - (void)deviceId; |
435 | - (void)keyCode; |
436 | - return AKEY_STATE_UNKNOWN; |
437 | -} |
438 | - |
439 | -int32_t mia::FakeEventHub::getSwitchState(int32_t deviceId, int32_t sw) const |
440 | -{ |
441 | - (void)deviceId; |
442 | - (void)sw; |
443 | - return AKEY_STATE_UNKNOWN; |
444 | -} |
445 | - |
446 | -status_t mia::FakeEventHub::getAbsoluteAxisValue(int32_t deviceId, int32_t axis, |
447 | +int32_t FakeEventHub::getScanCodeState(int32_t deviceId, int32_t scanCode) const |
448 | +{ |
449 | + const FakeDevice* device = getDevice(deviceId); |
450 | + if (device) |
451 | + { |
452 | + ssize_t index = device->scanCodeStates.indexOfKey(scanCode); |
453 | + if (index >= 0) |
454 | + { |
455 | + return device->scanCodeStates.valueAt(index); |
456 | + } |
457 | + } |
458 | + return AKEY_STATE_UNKNOWN; |
459 | +} |
460 | + |
461 | +int32_t FakeEventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const |
462 | +{ |
463 | + const FakeDevice* device = getDevice(deviceId); |
464 | + if (device) |
465 | + { |
466 | + ssize_t index = device->keyCodeStates.indexOfKey(keyCode); |
467 | + if (index >= 0) |
468 | + { |
469 | + return device->keyCodeStates.valueAt(index); |
470 | + } |
471 | + } |
472 | + return AKEY_STATE_UNKNOWN; |
473 | +} |
474 | + |
475 | +int32_t FakeEventHub::getSwitchState(int32_t deviceId, int32_t sw) const |
476 | +{ |
477 | + const FakeDevice* device = getDevice(deviceId); |
478 | + if (device) |
479 | + { |
480 | + ssize_t index = device->switchStates.indexOfKey(sw); |
481 | + if (index >= 0) |
482 | + { |
483 | + return device->switchStates.valueAt(index); |
484 | + } |
485 | + } |
486 | + return AKEY_STATE_UNKNOWN; |
487 | +} |
488 | + |
489 | +status_t FakeEventHub::getAbsoluteAxisValue(int32_t deviceId, int32_t axis, |
490 | int32_t* outValue) const |
491 | { |
492 | - (void)deviceId; |
493 | - (void)axis; |
494 | - (void)outValue; |
495 | + const FakeDevice* device = getDevice(deviceId); |
496 | + if (device) |
497 | + { |
498 | + ssize_t index = device->absoluteAxisValue.indexOfKey(axis); |
499 | + if (index >= 0) |
500 | + { |
501 | + *outValue = device->absoluteAxisValue.valueAt(index); |
502 | + return OK; |
503 | + } |
504 | + } |
505 | + *outValue = 0; |
506 | return -1; |
507 | } |
508 | |
509 | -bool mia::FakeEventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes, |
510 | +bool FakeEventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes, |
511 | const int32_t* keyCodes, |
512 | uint8_t* outFlags) const |
513 | { |
514 | - (void)deviceId; |
515 | - (void)numCodes; |
516 | - (void)keyCodes; |
517 | - (void)outFlags; |
518 | - return true; |
519 | -} |
520 | - |
521 | -bool mia::FakeEventHub::hasScanCode(int32_t deviceId, int32_t scanCode) const |
522 | -{ |
523 | - (void)deviceId; |
524 | - (void)scanCode; |
525 | - return false; |
526 | -} |
527 | - |
528 | -bool mia::FakeEventHub::hasLed(int32_t deviceId, int32_t led) const |
529 | -{ |
530 | - (void)deviceId; |
531 | - (void)led; |
532 | - return false; |
533 | -} |
534 | - |
535 | -void mia::FakeEventHub::setLedState(int32_t deviceId, int32_t led, bool on) |
536 | -{ |
537 | - (void)deviceId; |
538 | - (void)led; |
539 | - (void)on; |
540 | -} |
541 | - |
542 | -void mia::FakeEventHub::getVirtualKeyDefinitions(int32_t deviceId, |
543 | + bool result = false; |
544 | + const FakeDevice* device = getDevice(deviceId); |
545 | + if (device) |
546 | + { |
547 | + for (size_t i = 0; i < numCodes; i++) |
548 | + { |
549 | + for (size_t j = 0; j < device->keysByScanCode.size(); j++) |
550 | + { |
551 | + if (keyCodes[i] == device->keysByScanCode.valueAt(j).keyCode) |
552 | + { |
553 | + outFlags[i] = 1; |
554 | + result = true; |
555 | + } |
556 | + } |
557 | + for (size_t j = 0; j < device->keysByUsageCode.size(); j++) |
558 | + { |
559 | + if (keyCodes[i] == device->keysByUsageCode.valueAt(j).keyCode) |
560 | + { |
561 | + outFlags[i] = 1; |
562 | + result = true; |
563 | + } |
564 | + } |
565 | + } |
566 | + } |
567 | + return result; |
568 | +} |
569 | + |
570 | +bool FakeEventHub::hasScanCode(int32_t deviceId, int32_t scanCode) const |
571 | +{ |
572 | + const FakeDevice* device = getDevice(deviceId); |
573 | + if (device) |
574 | + { |
575 | + ssize_t index = device->keysByScanCode.indexOfKey(scanCode); |
576 | + return index >= 0; |
577 | + } |
578 | + return false; |
579 | +} |
580 | + |
581 | +bool FakeEventHub::hasLed(int32_t deviceId, int32_t led) const |
582 | +{ |
583 | + const FakeDevice* device = getDevice(deviceId); |
584 | + return device && device->leds.indexOfKey(led) >= 0; |
585 | +} |
586 | + |
587 | +void FakeEventHub::setLedState(int32_t deviceId, int32_t led, bool on) |
588 | +{ |
589 | + FakeDevice* device = getDevice(deviceId); |
590 | + if (device) |
591 | + { |
592 | + ssize_t index = device->leds.indexOfKey(led); |
593 | + if (index >= 0) |
594 | + { |
595 | + device->leds.replaceValueAt(led, on); |
596 | + } |
597 | + } |
598 | +} |
599 | + |
600 | +void FakeEventHub::getVirtualKeyDefinitions(int32_t deviceId, |
601 | Vector<VirtualKeyDefinition>& outVirtualKeys) const |
602 | { |
603 | - (void)deviceId; |
604 | - (void)outVirtualKeys; |
605 | + outVirtualKeys.clear(); |
606 | + |
607 | + const FakeDevice* device = getDevice(deviceId); |
608 | + if (device) |
609 | + { |
610 | + outVirtualKeys.appendVector(device->virtualKeys); |
611 | + } |
612 | } |
613 | |
614 | -sp<KeyCharacterMap> mia::FakeEventHub::getKeyCharacterMap(int32_t deviceId) const |
615 | +sp<KeyCharacterMap> FakeEventHub::getKeyCharacterMap(int32_t deviceId) const |
616 | { |
617 | (void)deviceId; |
618 | return sp<KeyCharacterMap>(); |
619 | } |
620 | |
621 | -bool mia::FakeEventHub::setKeyboardLayoutOverlay(int32_t deviceId, |
622 | +bool FakeEventHub::setKeyboardLayoutOverlay(int32_t deviceId, |
623 | const sp<KeyCharacterMap>& map) |
624 | { |
625 | (void)deviceId; |
626 | @@ -238,39 +381,39 @@ |
627 | return true; |
628 | } |
629 | |
630 | -void mia::FakeEventHub::vibrate(int32_t deviceId, nsecs_t duration) |
631 | +void FakeEventHub::vibrate(int32_t deviceId, nsecs_t duration) |
632 | { |
633 | (void)deviceId; |
634 | (void)duration; |
635 | } |
636 | |
637 | -void mia::FakeEventHub::cancelVibrate(int32_t deviceId) |
638 | +void FakeEventHub::cancelVibrate(int32_t deviceId) |
639 | { |
640 | (void)deviceId; |
641 | } |
642 | |
643 | -void mia::FakeEventHub::requestReopenDevices() |
644 | -{ |
645 | -} |
646 | - |
647 | -void mia::FakeEventHub::wake() |
648 | -{ |
649 | -} |
650 | - |
651 | -void mia::FakeEventHub::dump(droidinput::String8& dump) |
652 | +void FakeEventHub::requestReopenDevices() |
653 | +{ |
654 | +} |
655 | + |
656 | +void FakeEventHub::wake() |
657 | +{ |
658 | +} |
659 | + |
660 | +void FakeEventHub::dump(droidinput::String8& dump) |
661 | { |
662 | (void)dump; |
663 | } |
664 | |
665 | -void mia::FakeEventHub::monitor() |
666 | -{ |
667 | -} |
668 | - |
669 | -void mia::FakeEventHub::flush() |
670 | -{ |
671 | -} |
672 | - |
673 | -void mia::FakeEventHub::synthesize_builtin_keyboard_added() |
674 | +void FakeEventHub::monitor() |
675 | +{ |
676 | +} |
677 | + |
678 | +void FakeEventHub::flush() |
679 | +{ |
680 | +} |
681 | + |
682 | +void FakeEventHub::synthesize_builtin_keyboard_added() |
683 | { |
684 | RawEvent event; |
685 | event.when = 0; |
686 | @@ -281,7 +424,7 @@ |
687 | events_available.push_back(event); |
688 | } |
689 | |
690 | -void mia::FakeEventHub::synthesize_builtin_cursor_added() |
691 | +void FakeEventHub::synthesize_builtin_cursor_added() |
692 | { |
693 | RawEvent event; |
694 | event.when = 0; |
695 | @@ -292,7 +435,7 @@ |
696 | events_available.push_back(event); |
697 | } |
698 | |
699 | -void mia::FakeEventHub::synthesize_device_scan_complete() |
700 | +void FakeEventHub::synthesize_device_scan_complete() |
701 | { |
702 | RawEvent event; |
703 | event.when = 0; |
704 | @@ -302,7 +445,7 @@ |
705 | events_available.push_back(event); |
706 | } |
707 | |
708 | -void mia::FakeEventHub::synthesize_event(const mis::KeyParameters ¶meters) |
709 | +void FakeEventHub::synthesize_event(const mis::KeyParameters ¶meters) |
710 | { |
711 | RawEvent event; |
712 | event.when = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); |
713 | @@ -323,7 +466,7 @@ |
714 | events_available.push_back(event); |
715 | } |
716 | |
717 | -void mia::FakeEventHub::synthesize_event(const mis::ButtonParameters ¶meters) |
718 | +void FakeEventHub::synthesize_event(const mis::ButtonParameters ¶meters) |
719 | { |
720 | RawEvent event; |
721 | event.when = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); |
722 | @@ -349,7 +492,7 @@ |
723 | events_available.push_back(event); |
724 | } |
725 | |
726 | -void mia::FakeEventHub::synthesize_event(const mis::MotionParameters ¶meters) |
727 | +void FakeEventHub::synthesize_event(const mis::MotionParameters ¶meters) |
728 | { |
729 | RawEvent event; |
730 | event.when = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); |
731 | @@ -373,3 +516,175 @@ |
732 | event.code = SYN_REPORT; |
733 | events_available.push_back(event); |
734 | } |
735 | + |
736 | +void FakeEventHub::synthesize_event(nsecs_t when, int32_t device_id, int32_t type, int32_t code, int32_t value) |
737 | +{ |
738 | + RawEvent event; |
739 | + event.when = when; |
740 | + event.deviceId = device_id; |
741 | + event.type = type; |
742 | + event.code = code; |
743 | + event.value = value; |
744 | + |
745 | + { |
746 | + std::lock_guard<std::mutex> lg(guard); |
747 | + events_available.push_back(event); |
748 | + } |
749 | + |
750 | + if (type == EV_ABS) |
751 | + { |
752 | + setAbsoluteAxisValue(device_id, code, value); |
753 | + } |
754 | +} |
755 | + |
756 | +void FakeEventHub::addDevice(int32_t deviceId, const std::string& name, uint32_t classes) |
757 | +{ |
758 | + FakeDevice device; |
759 | + device.classes = classes; |
760 | + device.identifier.name = name; |
761 | + device_from_id.insert(std::pair<int32_t, FakeDevice>(deviceId, device)); |
762 | + |
763 | + synthesize_event(arbitrary_time, deviceId, EventHubInterface::DEVICE_ADDED, 0, 0); |
764 | +} |
765 | + |
766 | +void FakeEventHub::removeDevice(int32_t device_id) |
767 | +{ |
768 | + device_from_id.erase(device_id); |
769 | + |
770 | + synthesize_event(arbitrary_time, device_id, EventHubInterface::DEVICE_REMOVED, 0, 0); |
771 | +} |
772 | + |
773 | +void FakeEventHub::finishDeviceScan() |
774 | +{ |
775 | + synthesize_event(arbitrary_time, 0, EventHubInterface::FINISHED_DEVICE_SCAN, 0, 0); |
776 | +} |
777 | + |
778 | +void FakeEventHub::addConfigurationProperty(int32_t device_id, const std::string& key, const std::string& value) |
779 | +{ |
780 | + FakeDevice& device = device_from_id.at(device_id); |
781 | + device.configuration.addProperty(key, value); |
782 | +} |
783 | + |
784 | +void FakeEventHub::addConfigurationMap(int32_t device_id, const PropertyMap* configuration) |
785 | +{ |
786 | + FakeDevice& device = device_from_id.at(device_id); |
787 | + device.configuration.addAll(configuration); |
788 | +} |
789 | + |
790 | +void FakeEventHub::addAbsoluteAxis(int32_t device_id, int axis, |
791 | + int32_t minValue, int32_t maxValue, int flat, int fuzz, int resolution) |
792 | +{ |
793 | + FakeDevice& device = device_from_id.at(device_id); |
794 | + |
795 | + RawAbsoluteAxisInfo info; |
796 | + info.valid = true; |
797 | + info.minValue = minValue; |
798 | + info.maxValue = maxValue; |
799 | + info.flat = flat; |
800 | + info.fuzz = fuzz; |
801 | + info.resolution = resolution; |
802 | + device.absoluteAxes.add(axis, info); |
803 | +} |
804 | + |
805 | +void FakeEventHub::addRelativeAxis(int32_t device_id, int32_t axis) |
806 | +{ |
807 | + FakeDevice& device = device_from_id.at(device_id); |
808 | + device.relativeAxes.add(axis, true); |
809 | +} |
810 | + |
811 | +void FakeEventHub::setKeyCodeState(int32_t deviceId, int32_t keyCode, int32_t state) |
812 | +{ |
813 | + FakeDevice& device = device_from_id.at(deviceId); |
814 | + device.keyCodeStates.replaceValueFor(keyCode, state); |
815 | +} |
816 | + |
817 | +void FakeEventHub::setScanCodeState(int32_t deviceId, int32_t scanCode, int32_t state) |
818 | +{ |
819 | + FakeDevice& device = device_from_id.at(deviceId); |
820 | + device.scanCodeStates.replaceValueFor(scanCode, state); |
821 | +} |
822 | + |
823 | +void FakeEventHub::setSwitchState(int32_t deviceId, int32_t switchCode, int32_t state) |
824 | +{ |
825 | + FakeDevice& device = device_from_id.at(deviceId); |
826 | + device.switchStates.replaceValueFor(switchCode, state); |
827 | +} |
828 | + |
829 | +void FakeEventHub::setAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t value) |
830 | +{ |
831 | + FakeDevice& device = device_from_id.at(deviceId); |
832 | + device.absoluteAxisValue.replaceValueFor(axis, value); |
833 | +} |
834 | + |
835 | +void FakeEventHub::addKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, |
836 | + int32_t keyCode, uint32_t flags) |
837 | +{ |
838 | + FakeDevice& device = device_from_id.at(deviceId); |
839 | + KeyInfo info; |
840 | + info.keyCode = keyCode; |
841 | + info.flags = flags; |
842 | + if (scanCode) |
843 | + { |
844 | + device.keysByScanCode.add(scanCode, info); |
845 | + } |
846 | + if (usageCode) |
847 | + { |
848 | + device.keysByUsageCode.add(usageCode, info); |
849 | + } |
850 | +} |
851 | + |
852 | +void FakeEventHub::addLed(int32_t deviceId, int32_t led, bool initialState) |
853 | +{ |
854 | + FakeDevice& device = device_from_id.at(deviceId); |
855 | + device.leds.add(led, initialState); |
856 | +} |
857 | + |
858 | +bool FakeEventHub::getLedState(int32_t deviceId, int32_t led) |
859 | +{ |
860 | + FakeDevice& device = device_from_id.at(deviceId); |
861 | + return device.leds.valueFor(led); |
862 | +} |
863 | + |
864 | +Vector<std::string>& FakeEventHub::getExcludedDevices() |
865 | +{ |
866 | + return excluded_devices; |
867 | +} |
868 | + |
869 | +void FakeEventHub::addVirtualKeyDefinition(int32_t deviceId, const VirtualKeyDefinition& definition) |
870 | +{ |
871 | + FakeDevice& device = device_from_id.at(deviceId); |
872 | + device.virtualKeys.push(definition); |
873 | +} |
874 | + |
875 | +FakeEventHub::FakeDevice* FakeEventHub::getDevice(int32_t deviceId) |
876 | +{ |
877 | + auto fake_device_iterator = device_from_id.find(deviceId); |
878 | + |
879 | + if (fake_device_iterator != device_from_id.end()) |
880 | + { |
881 | + return &(fake_device_iterator->second); |
882 | + } |
883 | + else |
884 | + { |
885 | + return nullptr; |
886 | + } |
887 | +} |
888 | + |
889 | +const FakeEventHub::FakeDevice* FakeEventHub::getDevice(int32_t deviceId) const |
890 | +{ |
891 | + auto fake_device_iterator = device_from_id.find(deviceId); |
892 | + |
893 | + if (fake_device_iterator != device_from_id.end()) |
894 | + { |
895 | + return &(fake_device_iterator->second); |
896 | + } |
897 | + else |
898 | + { |
899 | + return nullptr; |
900 | + } |
901 | +} |
902 | + |
903 | +size_t FakeEventHub::eventsQueueSize() const |
904 | +{ |
905 | + return events_available.size(); |
906 | +} |
907 | |
908 | === modified file 'tests/unit-tests/android_input/input_reader.cpp' |
909 | --- tests/unit-tests/android_input/input_reader.cpp 2013-09-26 08:25:01 +0000 |
910 | +++ tests/unit-tests/android_input/input_reader.cpp 2013-10-02 11:08:26 +0000 |
911 | @@ -1,4 +1,5 @@ |
912 | /* |
913 | + * Copyright (C) 2013 Canonical Ltd. |
914 | * Copyright (C) 2010 The Android Open Source Project |
915 | * |
916 | * Licensed under the Apache License, Version 2.0 (the "License"); |
917 | @@ -25,10 +26,12 @@ |
918 | |
919 | #include <mir/logging/logger.h> |
920 | #include <mir/logging/input_report.h> |
921 | +#include <mir_test/fake_event_hub.h> |
922 | |
923 | namespace ml = mir::logging; |
924 | |
925 | using std::string; |
926 | +using mir::input::android::FakeEventHub; |
927 | |
928 | namespace |
929 | { |
930 | @@ -298,415 +301,6 @@ |
931 | } |
932 | }; |
933 | |
934 | - |
935 | -// --- FakeEventHub --- |
936 | - |
937 | -class FakeEventHub : public EventHubInterface { |
938 | - struct KeyInfo { |
939 | - int32_t keyCode; |
940 | - uint32_t flags; |
941 | - }; |
942 | - |
943 | - struct Device { |
944 | - InputDeviceIdentifier identifier; |
945 | - uint32_t classes; |
946 | - PropertyMap configuration; |
947 | - KeyedVector<int, RawAbsoluteAxisInfo> absoluteAxes; |
948 | - KeyedVector<int, bool> relativeAxes; |
949 | - KeyedVector<int32_t, int32_t> keyCodeStates; |
950 | - KeyedVector<int32_t, int32_t> scanCodeStates; |
951 | - KeyedVector<int32_t, int32_t> switchStates; |
952 | - KeyedVector<int32_t, int32_t> absoluteAxisValue; |
953 | - KeyedVector<int32_t, KeyInfo> keysByScanCode; |
954 | - KeyedVector<int32_t, KeyInfo> keysByUsageCode; |
955 | - KeyedVector<int32_t, bool> leds; |
956 | - Vector<VirtualKeyDefinition> virtualKeys; |
957 | - |
958 | - Device(uint32_t classes) : |
959 | - classes(classes) { |
960 | - } |
961 | - }; |
962 | - |
963 | - KeyedVector<int32_t, Device*> mDevices; |
964 | - Vector<String8> mExcludedDevices; |
965 | - List<RawEvent> mEvents; |
966 | - |
967 | -protected: |
968 | - virtual ~FakeEventHub() { |
969 | - for (size_t i = 0; i < mDevices.size(); i++) { |
970 | - delete mDevices.valueAt(i); |
971 | - } |
972 | - } |
973 | - |
974 | -public: |
975 | - FakeEventHub() { } |
976 | - |
977 | - void addDevice(int32_t deviceId, const String8& name, uint32_t classes) { |
978 | - Device* device = new Device(classes); |
979 | - device->identifier.name = name; |
980 | - mDevices.add(deviceId, device); |
981 | - |
982 | - enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_ADDED, 0, 0); |
983 | - } |
984 | - |
985 | - void removeDevice(int32_t deviceId) { |
986 | - delete mDevices.valueFor(deviceId); |
987 | - mDevices.removeItem(deviceId); |
988 | - |
989 | - enqueueEvent(ARBITRARY_TIME, deviceId, EventHubInterface::DEVICE_REMOVED, 0, 0); |
990 | - } |
991 | - |
992 | - void finishDeviceScan() { |
993 | - enqueueEvent(ARBITRARY_TIME, 0, EventHubInterface::FINISHED_DEVICE_SCAN, 0, 0); |
994 | - } |
995 | - |
996 | - void addConfigurationProperty(int32_t deviceId, const String8& key, const String8& value) { |
997 | - Device* device = getDevice(deviceId); |
998 | - device->configuration.addProperty(key, value); |
999 | - } |
1000 | - |
1001 | - void addConfigurationMap(int32_t deviceId, const PropertyMap* configuration) { |
1002 | - Device* device = getDevice(deviceId); |
1003 | - device->configuration.addAll(configuration); |
1004 | - } |
1005 | - |
1006 | - void addAbsoluteAxis(int32_t deviceId, int axis, |
1007 | - int32_t minValue, int32_t maxValue, int flat, int fuzz, int resolution = 0) { |
1008 | - Device* device = getDevice(deviceId); |
1009 | - |
1010 | - RawAbsoluteAxisInfo info; |
1011 | - info.valid = true; |
1012 | - info.minValue = minValue; |
1013 | - info.maxValue = maxValue; |
1014 | - info.flat = flat; |
1015 | - info.fuzz = fuzz; |
1016 | - info.resolution = resolution; |
1017 | - device->absoluteAxes.add(axis, info); |
1018 | - } |
1019 | - |
1020 | - void addRelativeAxis(int32_t deviceId, int32_t axis) { |
1021 | - Device* device = getDevice(deviceId); |
1022 | - device->relativeAxes.add(axis, true); |
1023 | - } |
1024 | - |
1025 | - void setKeyCodeState(int32_t deviceId, int32_t keyCode, int32_t state) { |
1026 | - Device* device = getDevice(deviceId); |
1027 | - device->keyCodeStates.replaceValueFor(keyCode, state); |
1028 | - } |
1029 | - |
1030 | - void setScanCodeState(int32_t deviceId, int32_t scanCode, int32_t state) { |
1031 | - Device* device = getDevice(deviceId); |
1032 | - device->scanCodeStates.replaceValueFor(scanCode, state); |
1033 | - } |
1034 | - |
1035 | - void setSwitchState(int32_t deviceId, int32_t switchCode, int32_t state) { |
1036 | - Device* device = getDevice(deviceId); |
1037 | - device->switchStates.replaceValueFor(switchCode, state); |
1038 | - } |
1039 | - |
1040 | - void setAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t value) { |
1041 | - Device* device = getDevice(deviceId); |
1042 | - device->absoluteAxisValue.replaceValueFor(axis, value); |
1043 | - } |
1044 | - |
1045 | - void addKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, |
1046 | - int32_t keyCode, uint32_t flags) { |
1047 | - Device* device = getDevice(deviceId); |
1048 | - KeyInfo info; |
1049 | - info.keyCode = keyCode; |
1050 | - info.flags = flags; |
1051 | - if (scanCode) { |
1052 | - device->keysByScanCode.add(scanCode, info); |
1053 | - } |
1054 | - if (usageCode) { |
1055 | - device->keysByUsageCode.add(usageCode, info); |
1056 | - } |
1057 | - } |
1058 | - |
1059 | - void addLed(int32_t deviceId, int32_t led, bool initialState) { |
1060 | - Device* device = getDevice(deviceId); |
1061 | - device->leds.add(led, initialState); |
1062 | - } |
1063 | - |
1064 | - bool getLedState(int32_t deviceId, int32_t led) { |
1065 | - Device* device = getDevice(deviceId); |
1066 | - return device->leds.valueFor(led); |
1067 | - } |
1068 | - |
1069 | - Vector<String8>& getExcludedDevices() { |
1070 | - return mExcludedDevices; |
1071 | - } |
1072 | - |
1073 | - void addVirtualKeyDefinition(int32_t deviceId, const VirtualKeyDefinition& definition) { |
1074 | - Device* device = getDevice(deviceId); |
1075 | - device->virtualKeys.push(definition); |
1076 | - } |
1077 | - |
1078 | - void enqueueEvent(nsecs_t when, int32_t deviceId, int32_t type, |
1079 | - int32_t code, int32_t value) { |
1080 | - RawEvent event; |
1081 | - event.when = when; |
1082 | - event.deviceId = deviceId; |
1083 | - event.type = type; |
1084 | - event.code = code; |
1085 | - event.value = value; |
1086 | - mEvents.push_back(event); |
1087 | - |
1088 | - if (type == EV_ABS) { |
1089 | - setAbsoluteAxisValue(deviceId, code, value); |
1090 | - } |
1091 | - } |
1092 | - |
1093 | - void assertQueueIsEmpty() { |
1094 | - ASSERT_EQ(size_t(0), mEvents.size()) |
1095 | - << "Expected the event queue to be empty (fully consumed)."; |
1096 | - } |
1097 | - |
1098 | -private: |
1099 | - Device* getDevice(int32_t deviceId) const { |
1100 | - ssize_t index = mDevices.indexOfKey(deviceId); |
1101 | - return index >= 0 ? mDevices.valueAt(index) : NULL; |
1102 | - } |
1103 | - |
1104 | - virtual uint32_t getDeviceClasses(int32_t deviceId) const { |
1105 | - Device* device = getDevice(deviceId); |
1106 | - return device ? device->classes : 0; |
1107 | - } |
1108 | - |
1109 | - virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const { |
1110 | - Device* device = getDevice(deviceId); |
1111 | - return device ? device->identifier : InputDeviceIdentifier(); |
1112 | - } |
1113 | - |
1114 | - virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const { |
1115 | - Device* device = getDevice(deviceId); |
1116 | - if (device) { |
1117 | - *outConfiguration = device->configuration; |
1118 | - } |
1119 | - } |
1120 | - |
1121 | - virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
1122 | - RawAbsoluteAxisInfo* outAxisInfo) const { |
1123 | - outAxisInfo->clear(); |
1124 | - Device* device = getDevice(deviceId); |
1125 | - if (device) { |
1126 | - ssize_t index = device->absoluteAxes.indexOfKey(axis); |
1127 | - if (index >= 0) { |
1128 | - *outAxisInfo = device->absoluteAxes.valueAt(index); |
1129 | - return OK; |
1130 | - } |
1131 | - } |
1132 | - return -1; |
1133 | - } |
1134 | - |
1135 | - virtual bool hasRelativeAxis(int32_t deviceId, int axis) const { |
1136 | - Device* device = getDevice(deviceId); |
1137 | - if (device) { |
1138 | - return device->relativeAxes.indexOfKey(axis) >= 0; |
1139 | - } |
1140 | - return false; |
1141 | - } |
1142 | - |
1143 | - bool hasInputProperty(int32_t deviceId, int property) const override { |
1144 | - (void)deviceId; |
1145 | - (void)property; |
1146 | - return false; |
1147 | - } |
1148 | - |
1149 | - virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, |
1150 | - int32_t* outKeycode, uint32_t* outFlags) const { |
1151 | - Device* device = getDevice(deviceId); |
1152 | - if (device) { |
1153 | - const KeyInfo* key = getKey(device, scanCode, usageCode); |
1154 | - if (key) { |
1155 | - if (outKeycode) { |
1156 | - *outKeycode = key->keyCode; |
1157 | - } |
1158 | - if (outFlags) { |
1159 | - *outFlags = key->flags; |
1160 | - } |
1161 | - return OK; |
1162 | - } |
1163 | - } |
1164 | - return NAME_NOT_FOUND; |
1165 | - } |
1166 | - |
1167 | - const KeyInfo* getKey(Device* device, int32_t scanCode, int32_t usageCode) const { |
1168 | - if (usageCode) { |
1169 | - ssize_t index = device->keysByUsageCode.indexOfKey(usageCode); |
1170 | - if (index >= 0) { |
1171 | - return &device->keysByUsageCode.valueAt(index); |
1172 | - } |
1173 | - } |
1174 | - if (scanCode) { |
1175 | - ssize_t index = device->keysByScanCode.indexOfKey(scanCode); |
1176 | - if (index >= 0) { |
1177 | - return &device->keysByScanCode.valueAt(index); |
1178 | - } |
1179 | - } |
1180 | - return NULL; |
1181 | - } |
1182 | - |
1183 | - status_t mapAxis(int32_t deviceId, int32_t scanCode, AxisInfo* outAxisInfo) const override { |
1184 | - (void)deviceId; |
1185 | - (void)scanCode; |
1186 | - (void)outAxisInfo; |
1187 | - return NAME_NOT_FOUND; |
1188 | - } |
1189 | - |
1190 | - virtual void setExcludedDevices(const Vector<String8>& devices) { |
1191 | - mExcludedDevices = devices; |
1192 | - } |
1193 | - |
1194 | - size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) override { |
1195 | - (void)timeoutMillis; |
1196 | - (void)bufferSize; |
1197 | - |
1198 | - if (mEvents.empty()) { |
1199 | - return 0; |
1200 | - } |
1201 | - |
1202 | - *buffer = *mEvents.begin(); |
1203 | - mEvents.erase(mEvents.begin()); |
1204 | - return 1; |
1205 | - } |
1206 | - |
1207 | - int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const override { |
1208 | - Device* device = getDevice(deviceId); |
1209 | - if (device) { |
1210 | - ssize_t index = device->scanCodeStates.indexOfKey(scanCode); |
1211 | - if (index >= 0) { |
1212 | - return device->scanCodeStates.valueAt(index); |
1213 | - } |
1214 | - } |
1215 | - return AKEY_STATE_UNKNOWN; |
1216 | - } |
1217 | - |
1218 | - int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const override { |
1219 | - Device* device = getDevice(deviceId); |
1220 | - if (device) { |
1221 | - ssize_t index = device->keyCodeStates.indexOfKey(keyCode); |
1222 | - if (index >= 0) { |
1223 | - return device->keyCodeStates.valueAt(index); |
1224 | - } |
1225 | - } |
1226 | - return AKEY_STATE_UNKNOWN; |
1227 | - } |
1228 | - |
1229 | - int32_t getSwitchState(int32_t deviceId, int32_t sw) const override { |
1230 | - Device* device = getDevice(deviceId); |
1231 | - if (device) { |
1232 | - ssize_t index = device->switchStates.indexOfKey(sw); |
1233 | - if (index >= 0) { |
1234 | - return device->switchStates.valueAt(index); |
1235 | - } |
1236 | - } |
1237 | - return AKEY_STATE_UNKNOWN; |
1238 | - } |
1239 | - |
1240 | - virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, |
1241 | - int32_t* outValue) const { |
1242 | - Device* device = getDevice(deviceId); |
1243 | - if (device) { |
1244 | - ssize_t index = device->absoluteAxisValue.indexOfKey(axis); |
1245 | - if (index >= 0) { |
1246 | - *outValue = device->absoluteAxisValue.valueAt(index); |
1247 | - return OK; |
1248 | - } |
1249 | - } |
1250 | - *outValue = 0; |
1251 | - return -1; |
1252 | - } |
1253 | - |
1254 | - virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, |
1255 | - uint8_t* outFlags) const { |
1256 | - bool result = false; |
1257 | - Device* device = getDevice(deviceId); |
1258 | - if (device) { |
1259 | - for (size_t i = 0; i < numCodes; i++) { |
1260 | - for (size_t j = 0; j < device->keysByScanCode.size(); j++) { |
1261 | - if (keyCodes[i] == device->keysByScanCode.valueAt(j).keyCode) { |
1262 | - outFlags[i] = 1; |
1263 | - result = true; |
1264 | - } |
1265 | - } |
1266 | - for (size_t j = 0; j < device->keysByUsageCode.size(); j++) { |
1267 | - if (keyCodes[i] == device->keysByUsageCode.valueAt(j).keyCode) { |
1268 | - outFlags[i] = 1; |
1269 | - result = true; |
1270 | - } |
1271 | - } |
1272 | - } |
1273 | - } |
1274 | - return result; |
1275 | - } |
1276 | - |
1277 | - virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const { |
1278 | - Device* device = getDevice(deviceId); |
1279 | - if (device) { |
1280 | - ssize_t index = device->keysByScanCode.indexOfKey(scanCode); |
1281 | - return index >= 0; |
1282 | - } |
1283 | - return false; |
1284 | - } |
1285 | - |
1286 | - virtual bool hasLed(int32_t deviceId, int32_t led) const { |
1287 | - Device* device = getDevice(deviceId); |
1288 | - return device && device->leds.indexOfKey(led) >= 0; |
1289 | - } |
1290 | - |
1291 | - virtual void setLedState(int32_t deviceId, int32_t led, bool on) { |
1292 | - Device* device = getDevice(deviceId); |
1293 | - if (device) { |
1294 | - ssize_t index = device->leds.indexOfKey(led); |
1295 | - if (index >= 0) { |
1296 | - device->leds.replaceValueAt(led, on); |
1297 | - } else { |
1298 | - ADD_FAILURE() |
1299 | - << "Attempted to set the state of an LED that the EventHub declared " |
1300 | - "was not present. led=" << led; |
1301 | - } |
1302 | - } |
1303 | - } |
1304 | - |
1305 | - void getVirtualKeyDefinitions(int32_t deviceId, |
1306 | - Vector<VirtualKeyDefinition>& outVirtualKeys) const override { |
1307 | - outVirtualKeys.clear(); |
1308 | - |
1309 | - Device* device = getDevice(deviceId); |
1310 | - if (device) { |
1311 | - outVirtualKeys.appendVector(device->virtualKeys); |
1312 | - } |
1313 | - } |
1314 | - |
1315 | - sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const override { |
1316 | - (void)deviceId; |
1317 | - return NULL; |
1318 | - } |
1319 | - |
1320 | - bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) override { |
1321 | - (void)deviceId; |
1322 | - (void)map; |
1323 | - return false; |
1324 | - } |
1325 | - |
1326 | - void vibrate(int32_t /*deviceId*/, nsecs_t /*duration*/) override {} |
1327 | - |
1328 | - void cancelVibrate(int32_t /*deviceId*/) override {} |
1329 | - |
1330 | - void wake() override {} |
1331 | - |
1332 | - void dump(String8& /*dump*/) override {} |
1333 | - |
1334 | - void monitor() override {} |
1335 | - |
1336 | - void flush() override {} |
1337 | - |
1338 | - void requestReopenDevices() override {} |
1339 | - |
1340 | -}; |
1341 | - |
1342 | - |
1343 | // --- FakeInputReaderContext --- |
1344 | |
1345 | class FakeInputReaderContext : public InputReaderContext { |
1346 | @@ -1001,7 +595,8 @@ |
1347 | mFakeEventHub->finishDeviceScan(); |
1348 | mReader->loopOnce(); |
1349 | mReader->loopOnce(); |
1350 | - mFakeEventHub->assertQueueIsEmpty(); |
1351 | + ASSERT_EQ(size_t(0), mFakeEventHub->eventsQueueSize()) |
1352 | + << "Expected the event queue to be empty (fully consumed)."; |
1353 | } |
1354 | |
1355 | FakeInputMapper* addDeviceWithFakeInputMapper(int32_t deviceId, |
1356 | @@ -1017,16 +612,16 @@ |
1357 | }; |
1358 | |
1359 | TEST_F(InputReaderTest, GetInputDevices) { |
1360 | - ASSERT_NO_FATAL_FAILURE(addDevice(1, String8("keyboard"), |
1361 | + ASSERT_NO_FATAL_FAILURE(addDevice(2, String8("keyboard"), |
1362 | INPUT_DEVICE_CLASS_KEYBOARD, NULL)); |
1363 | - ASSERT_NO_FATAL_FAILURE(addDevice(2, String8("ignored"), |
1364 | + ASSERT_NO_FATAL_FAILURE(addDevice(3, String8("ignored"), |
1365 | 0, NULL)); // no classes so device will be ignored |
1366 | |
1367 | Vector<InputDeviceInfo> inputDevices; |
1368 | mReader->getInputDevices(inputDevices); |
1369 | |
1370 | ASSERT_EQ(1U, inputDevices.size()); |
1371 | - ASSERT_EQ(1, inputDevices[0].getId()); |
1372 | + ASSERT_EQ(2, inputDevices[0].getId()); |
1373 | ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.c_str()); |
1374 | ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType()); |
1375 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources()); |
1376 | @@ -1035,7 +630,7 @@ |
1377 | // Should also have received a notification describing the new input devices. |
1378 | inputDevices = mFakePolicy->getInputDevices(); |
1379 | ASSERT_EQ(1U, inputDevices.size()); |
1380 | - ASSERT_EQ(1, inputDevices[0].getId()); |
1381 | + ASSERT_EQ(2, inputDevices[0].getId()); |
1382 | ASSERT_STREQ("keyboard", inputDevices[0].getIdentifier().name.c_str()); |
1383 | ASSERT_EQ(AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC, inputDevices[0].getKeyboardType()); |
1384 | ASSERT_EQ(AINPUT_SOURCE_KEYBOARD, inputDevices[0].getSources()); |
1385 | @@ -1159,7 +754,7 @@ |
1386 | } |
1387 | |
1388 | TEST_F(InputReaderTest, LoopOnce_WhenDeviceScanFinished_SendsConfigurationChanged) { |
1389 | - addDevice(1, String8("ignored"), INPUT_DEVICE_CLASS_KEYBOARD, NULL); |
1390 | + addDevice(2, String8("ignored"), INPUT_DEVICE_CLASS_KEYBOARD, NULL); |
1391 | |
1392 | NotifyConfigurationChangedArgs args{0}; |
1393 | |
1394 | @@ -1172,9 +767,9 @@ |
1395 | ASSERT_NO_FATAL_FAILURE(mapper = addDeviceWithFakeInputMapper(1, String8("fake"), |
1396 | INPUT_DEVICE_CLASS_KEYBOARD, AINPUT_SOURCE_KEYBOARD, NULL)); |
1397 | |
1398 | - mFakeEventHub->enqueueEvent(0, 1, EV_KEY, KEY_A, 1); |
1399 | + mFakeEventHub->synthesize_event(0, 1, EV_KEY, KEY_A, 1); |
1400 | mReader->loopOnce(); |
1401 | - ASSERT_NO_FATAL_FAILURE(mFakeEventHub->assertQueueIsEmpty()); |
1402 | + EXPECT_EQ(size_t(0), mFakeEventHub->eventsQueueSize()); |
1403 | |
1404 | RawEvent event; |
1405 | ASSERT_NO_FATAL_FAILURE(mapper->assertProcessWasCalled(&event)); |
1406 | @@ -1227,7 +822,7 @@ |
1407 | }; |
1408 | |
1409 | const char* InputDeviceTest::DEVICE_NAME = "device"; |
1410 | -const int32_t InputDeviceTest::DEVICE_ID = 1; |
1411 | +const int32_t InputDeviceTest::DEVICE_ID = 2; |
1412 | const int32_t InputDeviceTest::DEVICE_GENERATION = 2; |
1413 | const uint32_t InputDeviceTest::DEVICE_CLASSES = INPUT_DEVICE_CLASS_KEYBOARD |
1414 | | INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_JOYSTICK; |
1415 | @@ -1479,7 +1074,7 @@ |
1416 | }; |
1417 | |
1418 | const char* InputMapperTest::DEVICE_NAME = "device"; |
1419 | -const int32_t InputMapperTest::DEVICE_ID = 1; |
1420 | +const int32_t InputMapperTest::DEVICE_ID = 2; |
1421 | const int32_t InputMapperTest::DEVICE_GENERATION = 2; |
1422 | const uint32_t InputMapperTest::DEVICE_CLASSES = 0; // not needed for current tests |
1423 |
PASSED: Continuous integration, rev:1096 jenkins. qa.ubuntu. com/job/ mir-team- mir-development -branch- ci/63/ jenkins. qa.ubuntu. com/job/ mir-android- saucy-i386- build/2191 jenkins. qa.ubuntu. com/job/ mir-clang- saucy-amd64- build/2076 jenkins. qa.ubuntu. com/job/ mir-team- mir-development -branch- saucy-amd64- ci/63 jenkins. qa.ubuntu. com/job/ mir-team- mir-development -branch- saucy-amd64- ci/63/artifact/ work/output/ *zip*/output. zip
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ mir-team- mir-development -branch- ci/63/rebuild
http://