xref: /aosp_15_r20/external/libchrome-gestures/src/unittest_util.cc (revision aed3e5085e770be5b69ce25295ecf6ddf906af95)
1*aed3e508SAndroid Build Coastguard Worker // Copyright 2012 The ChromiumOS Authors
2*aed3e508SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*aed3e508SAndroid Build Coastguard Worker // found in the LICENSE file.
4*aed3e508SAndroid Build Coastguard Worker 
5*aed3e508SAndroid Build Coastguard Worker #include "include/unittest_util.h"
6*aed3e508SAndroid Build Coastguard Worker 
7*aed3e508SAndroid Build Coastguard Worker #include "include/gestures.h"
8*aed3e508SAndroid Build Coastguard Worker 
9*aed3e508SAndroid Build Coastguard Worker namespace gestures {
10*aed3e508SAndroid Build Coastguard Worker 
TestInterpreterWrapper(Interpreter * interpreter,const HardwareProperties * hwprops)11*aed3e508SAndroid Build Coastguard Worker TestInterpreterWrapper::TestInterpreterWrapper(Interpreter* interpreter,
12*aed3e508SAndroid Build Coastguard Worker     const HardwareProperties* hwprops)
13*aed3e508SAndroid Build Coastguard Worker     : interpreter_(interpreter),
14*aed3e508SAndroid Build Coastguard Worker       hwprops_(hwprops) {
15*aed3e508SAndroid Build Coastguard Worker   Reset(interpreter);
16*aed3e508SAndroid Build Coastguard Worker }
17*aed3e508SAndroid Build Coastguard Worker 
TestInterpreterWrapper(Interpreter * interpreter)18*aed3e508SAndroid Build Coastguard Worker TestInterpreterWrapper::TestInterpreterWrapper(Interpreter* interpreter)
19*aed3e508SAndroid Build Coastguard Worker     : interpreter_(interpreter),
20*aed3e508SAndroid Build Coastguard Worker       hwprops_(nullptr) {
21*aed3e508SAndroid Build Coastguard Worker   Reset(interpreter);
22*aed3e508SAndroid Build Coastguard Worker }
23*aed3e508SAndroid Build Coastguard Worker 
Reset(Interpreter * interpreter)24*aed3e508SAndroid Build Coastguard Worker void TestInterpreterWrapper::Reset(Interpreter* interpreter) {
25*aed3e508SAndroid Build Coastguard Worker   Reset(interpreter, static_cast<MetricsProperties*>(nullptr));
26*aed3e508SAndroid Build Coastguard Worker }
27*aed3e508SAndroid Build Coastguard Worker 
Reset(Interpreter * interpreter,MetricsProperties * mprops)28*aed3e508SAndroid Build Coastguard Worker void TestInterpreterWrapper::Reset(Interpreter* interpreter,
29*aed3e508SAndroid Build Coastguard Worker                                    MetricsProperties* mprops) {
30*aed3e508SAndroid Build Coastguard Worker   memset(&dummy_, 0, sizeof(HardwareProperties));
31*aed3e508SAndroid Build Coastguard Worker   if (!hwprops_)
32*aed3e508SAndroid Build Coastguard Worker     hwprops_ = &dummy_;
33*aed3e508SAndroid Build Coastguard Worker 
34*aed3e508SAndroid Build Coastguard Worker   if (!mprops) {
35*aed3e508SAndroid Build Coastguard Worker     if (mprops_.get()) {
36*aed3e508SAndroid Build Coastguard Worker       mprops_.reset(nullptr);
37*aed3e508SAndroid Build Coastguard Worker     }
38*aed3e508SAndroid Build Coastguard Worker     prop_reg_.reset(new PropRegistry());
39*aed3e508SAndroid Build Coastguard Worker     mprops_.reset(new MetricsProperties(prop_reg_.get()));
40*aed3e508SAndroid Build Coastguard Worker   } else {
41*aed3e508SAndroid Build Coastguard Worker     mprops_.reset(mprops);
42*aed3e508SAndroid Build Coastguard Worker   }
43*aed3e508SAndroid Build Coastguard Worker 
44*aed3e508SAndroid Build Coastguard Worker   interpreter_ = interpreter;
45*aed3e508SAndroid Build Coastguard Worker   if (interpreter_) {
46*aed3e508SAndroid Build Coastguard Worker     interpreter_->Initialize(hwprops_, nullptr, mprops_.get(), this);
47*aed3e508SAndroid Build Coastguard Worker   }
48*aed3e508SAndroid Build Coastguard Worker }
49*aed3e508SAndroid Build Coastguard Worker 
Reset(Interpreter * interpreter,const HardwareProperties * hwprops)50*aed3e508SAndroid Build Coastguard Worker void TestInterpreterWrapper::Reset(Interpreter* interpreter,
51*aed3e508SAndroid Build Coastguard Worker                                    const HardwareProperties* hwprops) {
52*aed3e508SAndroid Build Coastguard Worker   hwprops_ = hwprops;
53*aed3e508SAndroid Build Coastguard Worker   Reset(interpreter);
54*aed3e508SAndroid Build Coastguard Worker }
55*aed3e508SAndroid Build Coastguard Worker 
SyncInterpret(HardwareState & state,stime_t * timeout)56*aed3e508SAndroid Build Coastguard Worker Gesture* TestInterpreterWrapper::SyncInterpret(HardwareState& state,
57*aed3e508SAndroid Build Coastguard Worker                                                stime_t* timeout) {
58*aed3e508SAndroid Build Coastguard Worker   gesture_ = Gesture();
59*aed3e508SAndroid Build Coastguard Worker   interpreter_->SyncInterpret(state, timeout);
60*aed3e508SAndroid Build Coastguard Worker   if (gesture_.type == kGestureTypeNull)
61*aed3e508SAndroid Build Coastguard Worker     return nullptr;
62*aed3e508SAndroid Build Coastguard Worker   return &gesture_;
63*aed3e508SAndroid Build Coastguard Worker }
64*aed3e508SAndroid Build Coastguard Worker 
HandleTimer(stime_t now,stime_t * timeout)65*aed3e508SAndroid Build Coastguard Worker Gesture* TestInterpreterWrapper::HandleTimer(stime_t now, stime_t* timeout) {
66*aed3e508SAndroid Build Coastguard Worker   gesture_.type = kGestureTypeNull;
67*aed3e508SAndroid Build Coastguard Worker   interpreter_->HandleTimer(now, timeout);
68*aed3e508SAndroid Build Coastguard Worker   if (gesture_.type == kGestureTypeNull)
69*aed3e508SAndroid Build Coastguard Worker     return nullptr;
70*aed3e508SAndroid Build Coastguard Worker   return &gesture_;
71*aed3e508SAndroid Build Coastguard Worker }
72*aed3e508SAndroid Build Coastguard Worker 
ConsumeGesture(const Gesture & gesture)73*aed3e508SAndroid Build Coastguard Worker void TestInterpreterWrapper::ConsumeGesture(const Gesture& gesture) {
74*aed3e508SAndroid Build Coastguard Worker   Assert(gesture_.type == kGestureTypeNull);
75*aed3e508SAndroid Build Coastguard Worker   gesture_ = gesture;
76*aed3e508SAndroid Build Coastguard Worker }
77*aed3e508SAndroid Build Coastguard Worker 
78*aed3e508SAndroid Build Coastguard Worker 
make_hwstate(stime_t timestamp,int buttons_down,unsigned short finger_cnt,unsigned short touch_cnt,struct FingerState * fingers)79*aed3e508SAndroid Build Coastguard Worker HardwareState make_hwstate(stime_t timestamp, int buttons_down,
80*aed3e508SAndroid Build Coastguard Worker                            unsigned short finger_cnt, unsigned short touch_cnt,
81*aed3e508SAndroid Build Coastguard Worker                            struct FingerState* fingers) {
82*aed3e508SAndroid Build Coastguard Worker   return {
83*aed3e508SAndroid Build Coastguard Worker     timestamp,
84*aed3e508SAndroid Build Coastguard Worker     buttons_down,
85*aed3e508SAndroid Build Coastguard Worker     finger_cnt,
86*aed3e508SAndroid Build Coastguard Worker     touch_cnt,
87*aed3e508SAndroid Build Coastguard Worker     fingers,
88*aed3e508SAndroid Build Coastguard Worker     0,    // rel_x
89*aed3e508SAndroid Build Coastguard Worker     0,    // rel_y
90*aed3e508SAndroid Build Coastguard Worker     0,    // rel_wheel
91*aed3e508SAndroid Build Coastguard Worker     0,    // rel_wheel_hi_res
92*aed3e508SAndroid Build Coastguard Worker     0,    // rel_hwheel
93*aed3e508SAndroid Build Coastguard Worker     0.0,  // msc_timestamp
94*aed3e508SAndroid Build Coastguard Worker   };
95*aed3e508SAndroid Build Coastguard Worker }
96*aed3e508SAndroid Build Coastguard Worker 
97*aed3e508SAndroid Build Coastguard Worker }  // namespace gestures
98