xref: /aosp_15_r20/external/libchrome-gestures/src/multitouch_mouse_interpreter_unittest.cc (revision aed3e5085e770be5b69ce25295ecf6ddf906af95)
1 // Copyright 2013 The ChromiumOS Authors
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 <gtest/gtest.h>
6 
7 #include "include/gestures.h"
8 #include "include/multitouch_mouse_interpreter.h"
9 #include "include/unittest_util.h"
10 #include "include/util.h"
11 
12 namespace gestures {
13 
14 class MultitouchMouseInterpreterTest : public ::testing::Test {};
15 
TEST(MultitouchMouseInterpreterTest,SimpleTest)16 TEST(MultitouchMouseInterpreterTest, SimpleTest) {
17   MultitouchMouseInterpreter mi(nullptr, nullptr);
18   Gesture* gs;
19 
20   HardwareProperties hwprops = {
21     .left = 133, .top = 728, .right = 10279, .bottom = 5822,
22     .res_x = (10279.0 - 133.0) / 100.0,
23     .res_y = (5822.0 - 728.0) / 60,
24     .orientation_minimum = -1,
25     .orientation_maximum = 2,
26     .max_finger_cnt = 2, .max_touch_cnt = 5,
27     .supports_t5r2 = 0, .support_semi_mt = 0, .is_button_pad = 0,
28     .has_wheel = 0, .wheel_is_hi_res = 0,
29     .is_haptic_pad = 0,
30   };
31   TestInterpreterWrapper wrapper(&mi, &hwprops);
32 
33   FingerState fs_0[] = {
34     { 1, 1, 0, 0, 0, 0, 0, 0, 1, 0 },
35     { 1, 1, 0, 0, 0, 0, 0, 0, 2, 0 },
36   };
37   FingerState fs_1[] = {
38     { 1, 1, 0, 0, 0, 0, 3, 4, 1, 0 },
39     { 1, 1, 0, 0, 0, 0, 6, 8, 2, 0 },
40   };
41   HardwareState hwstates[] = {
42     { 200000, 0, 2, 2, fs_0, 0, 0, 0, 0, 0, 0.0 },
43     { 210000, 0, 2, 2, fs_0, 9, -7, 0, 0, 0, 0.0 },
44     { 220000, 1, 2, 2, fs_0, 0, 0, 0, 0, 0, 0.0 },
45     { 230000, 0, 2, 2, fs_0, 0, 0, 0, 0, 0, 0.0 },
46     { 240000, 0, 2, 2, fs_1, 0, 0, 0, 0, 0, 0.0 },
47   };
48 
49   // Make snap impossible
50   mi.scroll_manager_.horizontal_scroll_snap_slope_.val_ = 0;
51   mi.scroll_manager_.vertical_scroll_snap_slope_.val_ = 100;
52 
53   gs = wrapper.SyncInterpret(hwstates[0], nullptr);
54   EXPECT_EQ(nullptr, gs);
55 
56   gs = wrapper.SyncInterpret(hwstates[1], nullptr);
57   ASSERT_NE(nullptr, gs);
58   EXPECT_EQ(kGestureTypeMove, gs->type);
59   EXPECT_EQ(9, gs->details.move.dx);
60   EXPECT_EQ(-7, gs->details.move.dy);
61   EXPECT_EQ(200000, gs->start_time);
62   EXPECT_EQ(210000, gs->end_time);
63 
64   gs = wrapper.SyncInterpret(hwstates[2], nullptr);
65   ASSERT_NE(nullptr, gs);
66   EXPECT_EQ(kGestureTypeButtonsChange, gs->type);
67   EXPECT_EQ(1, gs->details.buttons.down);
68   EXPECT_EQ(0, gs->details.buttons.up);
69   EXPECT_GE(210000, gs->start_time);
70   EXPECT_EQ(220000, gs->end_time);
71 
72   gs = wrapper.SyncInterpret(hwstates[3], nullptr);
73   ASSERT_NE(nullptr, gs);
74   EXPECT_EQ(kGestureTypeButtonsChange, gs->type);
75   EXPECT_EQ(0, gs->details.buttons.down);
76   EXPECT_EQ(1, gs->details.buttons.up);
77   EXPECT_EQ(220000, gs->start_time);
78   EXPECT_EQ(230000, gs->end_time);
79 
80   gs = wrapper.SyncInterpret(hwstates[4], nullptr);
81   ASSERT_NE(nullptr, gs);
82   EXPECT_EQ(kGestureTypeScroll, gs->type);
83   EXPECT_EQ(6, gs->details.scroll.dx);
84   EXPECT_EQ(8, gs->details.scroll.dy);
85   EXPECT_EQ(230000, gs->start_time);
86   EXPECT_EQ(240000, gs->end_time);
87 }
88 
89 }  // namespace gestures
90