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 .screen_x_dpi = 0,
25 .screen_y_dpi = 0,
26 .orientation_minimum = -1,
27 .orientation_maximum = 2,
28 .max_finger_cnt = 2, .max_touch_cnt = 5,
29 .supports_t5r2 = 0, .support_semi_mt = 0, .is_button_pad = 0,
30 .has_wheel = 0, .wheel_is_hi_res = 0,
31 .is_haptic_pad = 0,
32 };
33 TestInterpreterWrapper wrapper(&mi, &hwprops);
34
35 FingerState fs_0[] = {
36 { 1, 1, 0, 0, 0, 0, 0, 0, 1, 0 },
37 { 1, 1, 0, 0, 0, 0, 0, 0, 2, 0 },
38 };
39 FingerState fs_1[] = {
40 { 1, 1, 0, 0, 0, 0, 3, 4, 1, 0 },
41 { 1, 1, 0, 0, 0, 0, 6, 8, 2, 0 },
42 };
43 HardwareState hwstates[] = {
44 { 200000, 0, 2, 2, fs_0, 0, 0, 0, 0, 0, 0.0 },
45 { 210000, 0, 2, 2, fs_0, 9, -7, 0, 0, 0, 0.0 },
46 { 220000, 1, 2, 2, fs_0, 0, 0, 0, 0, 0, 0.0 },
47 { 230000, 0, 2, 2, fs_0, 0, 0, 0, 0, 0, 0.0 },
48 { 240000, 0, 2, 2, fs_1, 0, 0, 0, 0, 0, 0.0 },
49 };
50
51 // Make snap impossible
52 mi.scroll_manager_.horizontal_scroll_snap_slope_.val_ = 0;
53 mi.scroll_manager_.vertical_scroll_snap_slope_.val_ = 100;
54
55 gs = wrapper.SyncInterpret(hwstates[0], nullptr);
56 EXPECT_EQ(nullptr, gs);
57
58 gs = wrapper.SyncInterpret(hwstates[1], nullptr);
59 ASSERT_NE(nullptr, gs);
60 EXPECT_EQ(kGestureTypeMove, gs->type);
61 EXPECT_EQ(9, gs->details.move.dx);
62 EXPECT_EQ(-7, gs->details.move.dy);
63 EXPECT_EQ(200000, gs->start_time);
64 EXPECT_EQ(210000, gs->end_time);
65
66 gs = wrapper.SyncInterpret(hwstates[2], nullptr);
67 ASSERT_NE(nullptr, gs);
68 EXPECT_EQ(kGestureTypeButtonsChange, gs->type);
69 EXPECT_EQ(1, gs->details.buttons.down);
70 EXPECT_EQ(0, gs->details.buttons.up);
71 EXPECT_GE(210000, gs->start_time);
72 EXPECT_EQ(220000, gs->end_time);
73
74 gs = wrapper.SyncInterpret(hwstates[3], nullptr);
75 ASSERT_NE(nullptr, gs);
76 EXPECT_EQ(kGestureTypeButtonsChange, gs->type);
77 EXPECT_EQ(0, gs->details.buttons.down);
78 EXPECT_EQ(1, gs->details.buttons.up);
79 EXPECT_EQ(220000, gs->start_time);
80 EXPECT_EQ(230000, gs->end_time);
81
82 gs = wrapper.SyncInterpret(hwstates[4], nullptr);
83 ASSERT_NE(nullptr, gs);
84 EXPECT_EQ(kGestureTypeScroll, gs->type);
85 EXPECT_EQ(6, gs->details.scroll.dx);
86 EXPECT_EQ(8, gs->details.scroll.dy);
87 EXPECT_EQ(230000, gs->start_time);
88 EXPECT_EQ(240000, gs->end_time);
89 }
90
91 } // namespace gestures
92