Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: ui/events/ozone/gamepad/generic_gamepad_mapping_unittest.cc

Issue 2899893003: Add generic mapping for gamepad (Closed)
Patch Set: Add generic mapping for gamepad Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/events/ozone/gamepad/generic_gamepad_mapping.h"
6
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <linux/input.h>
10 #include <unistd.h>
11
12 #include <memory>
13 #include <queue>
14 #include <utility>
15 #include <vector>
16
17 #include "base/bind.h"
18 #include "base/files/file_util.h"
19 #include "base/macros.h"
20 #include "base/memory/ptr_util.h"
21 #include "base/posix/eintr_wrapper.h"
22 #include "base/run_loop.h"
23 #include "base/time/time.h"
24 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/events/event.h"
27 #include "ui/events/ozone/device/device_manager.h"
28 #include "ui/events/ozone/evdev/event_converter_test_util.h"
29 #include "ui/events/ozone/evdev/event_device_info.h"
30 #include "ui/events/ozone/evdev/event_device_test_util.h"
31 #include "ui/events/ozone/evdev/event_device_util.h"
32 #include "ui/events/ozone/evdev/event_factory_evdev.h"
33 #include "ui/events/ozone/gamepad/gamepad_event.h"
34 #include "ui/events/ozone/gamepad/gamepad_observer.h"
35 #include "ui/events/ozone/gamepad/gamepad_provider_ozone.h"
36 #include "ui/events/ozone/gamepad/static_gamepad_mapping.h"
37 #include "ui/events/ozone/gamepad/webgamepad_constants.h"
38 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
39 #include "ui/events/platform/platform_event_dispatcher.h"
40 #include "ui/events/platform/platform_event_source.h"
41
42 namespace ui {
43
44 class GenericGamepadMappingTest : public testing::Test {
45 public:
46 GenericGamepadMappingTest() {}
47
48 void CompareGamepadMapper(const GamepadMapper* l_mapper,
49 const GamepadMapper* r_mapper) {
50 bool l_result, r_result;
51 GamepadEventType l_mapped_type, r_mapped_type;
52 uint16_t l_mapped_code, r_mapped_code;
53 for (uint16_t code = BTN_MISC; code < KEY_MAX; code++) {
54 l_result = l_mapper->Map(EV_KEY, code, &l_mapped_type, &l_mapped_code);
55 r_result = r_mapper->Map(EV_KEY, code, &r_mapped_type, &r_mapped_code);
56 EXPECT_EQ(l_result, r_result) << " Current Code: " << code;
57 if (l_result) {
58 EXPECT_EQ(l_mapped_type, r_mapped_type);
59 EXPECT_EQ(r_mapped_code, r_mapped_code);
60 }
61 }
62 for (uint16_t code = ABS_X; code < ABS_MAX; code++) {
63 l_result = l_mapper->Map(EV_ABS, code, &l_mapped_type, &l_mapped_code);
64 r_result = r_mapper->Map(EV_ABS, code, &r_mapped_type, &r_mapped_code);
65 EXPECT_EQ(l_result, r_result);
66 if (l_result) {
67 EXPECT_EQ(l_mapped_type, r_mapped_type);
68 EXPECT_EQ(r_mapped_code, r_mapped_code);
69 }
70 }
71 }
72
73 void TestCompatableWithCapabilities(const DeviceCapabilities& cap) {
74 ui::EventDeviceInfo devinfo;
75 CapabilitiesToDeviceInfo(cap, &devinfo);
76 std::unique_ptr<GamepadMapper> static_mapper(
77 GetStaticGamepadMapper(devinfo.vendor_id(), devinfo.product_id()));
78 std::unique_ptr<GamepadMapper> generic_mapper =
79 BuildGenericGamepadMapper(devinfo);
80 CompareGamepadMapper(static_mapper.get(), generic_mapper.get());
81 }
82 };
83
84 TEST_F(GenericGamepadMappingTest, XInputGamepad) {
85 TestCompatableWithCapabilities(kXboxGamepad);
86 }
87
88 TEST_F(GenericGamepadMappingTest, HJCGamepad) {
89 TestCompatableWithCapabilities(kHJCGamepad);
90 }
91
92 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/gamepad/generic_gamepad_mapping.cc ('k') | ui/events/ozone/gamepad/static_gamepad_mapping.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698