• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 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/finger_metrics.h"
8 #include "include/gestures.h"
9 
10 namespace gestures {
11 
12 class FingerMetricsTest : public ::testing::Test {};
13 
14 // This test adds code coverage for finger_metrics.
15 
TEST(FingerMetricsTest,SimpleTest)16 TEST(FingerMetricsTest, SimpleTest) {
17   Vector2 v1 = {1.0, 1.0};
18   Vector2 v2 = {2.0, 2.0};
19 
20   Vector2 v3 = Add(v1, v2);
21   EXPECT_EQ(v3.x, 3.0);
22   EXPECT_EQ(v3.y, 3.0);
23 
24   float mag = v3.Mag();
25   EXPECT_GT(mag, 4.242);
26   EXPECT_LT(mag, 4.243);
27 
28   EXPECT_TRUE(v1 == v1);
29   EXPECT_TRUE(v1 != v2);
30 
31   EXPECT_EQ(Dot(v1, v2), 4.0);
32 
33   FingerState fs = {
34     44.0, 24.0,
35     30.0, 10.0,
36     100.0,
37     0.0,
38     123.0, 321.0,
39     42,
40     0
41   };
42   FingerMetrics fm = {fs, 0.0};
43   EXPECT_EQ(fm.position(), Vector2(123.0, 321.0));
44 
45   fm.Update(fs, 0.1, true);
46   EXPECT_EQ(Vector2(0.0, 0.0), fm.delta());
47   EXPECT_EQ(Vector2(123.0, 321.0), fm.origin_position());
48   EXPECT_EQ(0.0, fm.origin_time());
49   EXPECT_EQ(Vector2(0.0, 0.0), fm.origin_delta());
50   EXPECT_EQ(Vector2(123.0, 321.0), fm.start_position());
51   EXPECT_EQ(0.1, fm.start_time());
52   EXPECT_EQ(Vector2(0.0, 0.0), fm.start_delta());
53 }
54 
55 }  // namespace gestures
56