• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(NULL, NULL);
18   Gesture* gs;
19 
20   HardwareProperties hwprops = {
21     133, 728, 10279, 5822,  // left, top, right, bottom
22     (10279.0 - 133.0) / 100.0,  // x res (pixels/mm)
23     (5822.0 - 728.0) / 60,  // y res (pixels/mm)
24     133, 133,  // scrn DPI X, Y
25     -1,  // orientation minimum
26     2,   // orientation maximum
27     2, 5,  // max fingers, max_touch
28     0, 0, 0,  // t5r2, semi, button pad
29     0, 0,  // has wheel, vertical wheel is high resolution
30     0,  // haptic pad
31   };
32   TestInterpreterWrapper wrapper(&mi, &hwprops);
33 
34   FingerState fs_0[] = {
35     { 1, 1, 0, 0, 0, 0, 0, 0, 1, 0 },
36     { 1, 1, 0, 0, 0, 0, 0, 0, 2, 0 },
37   };
38   FingerState fs_1[] = {
39     { 1, 1, 0, 0, 0, 0, 3, 4, 1, 0 },
40     { 1, 1, 0, 0, 0, 0, 6, 8, 2, 0 },
41   };
42   HardwareState hwstates[] = {
43     { 200000, 0, 2, 2, fs_0, 0, 0, 0, 0, 0, 0.0 },
44     { 210000, 0, 2, 2, fs_0, 9, -7, 0, 0, 0, 0.0 },
45     { 220000, 1, 2, 2, fs_0, 0, 0, 0, 0, 0, 0.0 },
46     { 230000, 0, 2, 2, fs_0, 0, 0, 0, 0, 0, 0.0 },
47     { 240000, 0, 2, 2, fs_1, 0, 0, 0, 0, 0, 0.0 },
48   };
49 
50   // Make snap impossible
51   mi.scroll_manager_.horizontal_scroll_snap_slope_.val_ = 0;
52   mi.scroll_manager_.vertical_scroll_snap_slope_.val_ = 100;
53 
54   gs = wrapper.SyncInterpret(&hwstates[0], NULL);
55   EXPECT_EQ(reinterpret_cast<Gesture*>(NULL), gs);
56 
57   gs = wrapper.SyncInterpret(&hwstates[1], NULL);
58   ASSERT_NE(reinterpret_cast<Gesture*>(NULL), gs);
59   EXPECT_EQ(kGestureTypeMove, gs->type);
60   EXPECT_EQ(9, gs->details.move.dx);
61   EXPECT_EQ(-7, gs->details.move.dy);
62   EXPECT_EQ(200000, gs->start_time);
63   EXPECT_EQ(210000, gs->end_time);
64 
65   gs = wrapper.SyncInterpret(&hwstates[2], NULL);
66   ASSERT_NE(reinterpret_cast<Gesture*>(NULL), gs);
67   EXPECT_EQ(kGestureTypeButtonsChange, gs->type);
68   EXPECT_EQ(1, gs->details.buttons.down);
69   EXPECT_EQ(0, gs->details.buttons.up);
70   EXPECT_GE(210000, gs->start_time);
71   EXPECT_EQ(220000, gs->end_time);
72 
73   gs = wrapper.SyncInterpret(&hwstates[3], NULL);
74   ASSERT_NE(reinterpret_cast<Gesture*>(NULL), gs);
75   EXPECT_EQ(kGestureTypeButtonsChange, gs->type);
76   EXPECT_EQ(0, gs->details.buttons.down);
77   EXPECT_EQ(1, gs->details.buttons.up);
78   EXPECT_EQ(220000, gs->start_time);
79   EXPECT_EQ(230000, gs->end_time);
80 
81   gs = wrapper.SyncInterpret(&hwstates[4], NULL);
82   ASSERT_NE(reinterpret_cast<Gesture*>(NULL), gs);
83   EXPECT_EQ(kGestureTypeScroll, gs->type);
84   EXPECT_EQ(6, gs->details.scroll.dx);
85   EXPECT_EQ(8, gs->details.scroll.dy);
86   EXPECT_EQ(230000, gs->start_time);
87   EXPECT_EQ(240000, gs->end_time);
88 }
89 
90 }  // namespace gestures
91