summaryrefslogtreecommitdiff
path: root/src/multitouch_mouse_interpreter_unittest.cc
blob: 48bba2919637d2b12f1df4a1129a51aee7ddad95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2013 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <gtest/gtest.h>

#include "include/gestures.h"
#include "include/multitouch_mouse_interpreter.h"
#include "include/unittest_util.h"
#include "include/util.h"

namespace gestures {

class MultitouchMouseInterpreterTest : public ::testing::Test {};

TEST(MultitouchMouseInterpreterTest, SimpleTest) {
  MultitouchMouseInterpreter mi(nullptr, nullptr);
  Gesture* gs;

  HardwareProperties hwprops = {
    133, 728, 10279, 5822,  // left, top, right, bottom
    (10279.0 - 133.0) / 100.0,  // x res (pixels/mm)
    (5822.0 - 728.0) / 60,  // y res (pixels/mm)
    133, 133,  // scrn DPI X, Y
    -1,  // orientation minimum
    2,   // orientation maximum
    2, 5,  // max fingers, max_touch
    0, 0, 0,  // t5r2, semi, button pad
    0, 0,  // has wheel, vertical wheel is high resolution
    0,  // haptic pad
  };
  TestInterpreterWrapper wrapper(&mi, &hwprops);

  FingerState fs_0[] = {
    { 1, 1, 0, 0, 0, 0, 0, 0, 1, 0 },
    { 1, 1, 0, 0, 0, 0, 0, 0, 2, 0 },
  };
  FingerState fs_1[] = {
    { 1, 1, 0, 0, 0, 0, 3, 4, 1, 0 },
    { 1, 1, 0, 0, 0, 0, 6, 8, 2, 0 },
  };
  HardwareState hwstates[] = {
    { 200000, 0, 2, 2, fs_0, 0, 0, 0, 0, 0, 0.0 },
    { 210000, 0, 2, 2, fs_0, 9, -7, 0, 0, 0, 0.0 },
    { 220000, 1, 2, 2, fs_0, 0, 0, 0, 0, 0, 0.0 },
    { 230000, 0, 2, 2, fs_0, 0, 0, 0, 0, 0, 0.0 },
    { 240000, 0, 2, 2, fs_1, 0, 0, 0, 0, 0, 0.0 },
  };

  // Make snap impossible
  mi.scroll_manager_.horizontal_scroll_snap_slope_.val_ = 0;
  mi.scroll_manager_.vertical_scroll_snap_slope_.val_ = 100;

  gs = wrapper.SyncInterpret(hwstates[0], nullptr);
  EXPECT_EQ(nullptr, gs);

  gs = wrapper.SyncInterpret(hwstates[1], nullptr);
  ASSERT_NE(nullptr, gs);
  EXPECT_EQ(kGestureTypeMove, gs->type);
  EXPECT_EQ(9, gs->details.move.dx);
  EXPECT_EQ(-7, gs->details.move.dy);
  EXPECT_EQ(200000, gs->start_time);
  EXPECT_EQ(210000, gs->end_time);

  gs = wrapper.SyncInterpret(hwstates[2], nullptr);
  ASSERT_NE(nullptr, gs);
  EXPECT_EQ(kGestureTypeButtonsChange, gs->type);
  EXPECT_EQ(1, gs->details.buttons.down);
  EXPECT_EQ(0, gs->details.buttons.up);
  EXPECT_GE(210000, gs->start_time);
  EXPECT_EQ(220000, gs->end_time);

  gs = wrapper.SyncInterpret(hwstates[3], nullptr);
  ASSERT_NE(nullptr, gs);
  EXPECT_EQ(kGestureTypeButtonsChange, gs->type);
  EXPECT_EQ(0, gs->details.buttons.down);
  EXPECT_EQ(1, gs->details.buttons.up);
  EXPECT_EQ(220000, gs->start_time);
  EXPECT_EQ(230000, gs->end_time);

  gs = wrapper.SyncInterpret(hwstates[4], nullptr);
  ASSERT_NE(nullptr, gs);
  EXPECT_EQ(kGestureTypeScroll, gs->type);
  EXPECT_EQ(6, gs->details.scroll.dx);
  EXPECT_EQ(8, gs->details.scroll.dy);
  EXPECT_EQ(230000, gs->start_time);
  EXPECT_EQ(240000, gs->end_time);
}

}  // namespace gestures