xref: /aosp_15_r20/external/libchrome-gestures/include/unittest_util.h (revision aed3e5085e770be5b69ce25295ecf6ddf906af95)
1*aed3e508SAndroid Build Coastguard Worker // Copyright 2013 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 #ifndef GESTURES_UNITTEST_UTIL_H_
6*aed3e508SAndroid Build Coastguard Worker #define GESTURES_UNITTEST_UTIL_H_
7*aed3e508SAndroid Build Coastguard Worker 
8*aed3e508SAndroid Build Coastguard Worker #include "include/finger_metrics.h"
9*aed3e508SAndroid Build Coastguard Worker #include "include/gestures.h"
10*aed3e508SAndroid Build Coastguard Worker #include "include/interpreter.h"
11*aed3e508SAndroid Build Coastguard Worker 
12*aed3e508SAndroid Build Coastguard Worker namespace gestures {
13*aed3e508SAndroid Build Coastguard Worker 
14*aed3e508SAndroid Build Coastguard Worker // A wrapper for interpreters in unit tests. Mimicks the old API and
15*aed3e508SAndroid Build Coastguard Worker // initializes the interpreter correctly.
16*aed3e508SAndroid Build Coastguard Worker class TestInterpreterWrapper : public GestureConsumer {
17*aed3e508SAndroid Build Coastguard Worker  public:
18*aed3e508SAndroid Build Coastguard Worker   explicit TestInterpreterWrapper(Interpreter* interpreter);
19*aed3e508SAndroid Build Coastguard Worker   TestInterpreterWrapper(Interpreter* interpreter,
20*aed3e508SAndroid Build Coastguard Worker                          const HardwareProperties* hwprops);
21*aed3e508SAndroid Build Coastguard Worker 
22*aed3e508SAndroid Build Coastguard Worker   void Reset(Interpreter* interpreter);
23*aed3e508SAndroid Build Coastguard Worker   // Takes ownership of mprops
24*aed3e508SAndroid Build Coastguard Worker   void Reset(Interpreter* interpreter, MetricsProperties* mprops);
25*aed3e508SAndroid Build Coastguard Worker   void Reset(Interpreter* interpreter, const HardwareProperties* hwprops);
26*aed3e508SAndroid Build Coastguard Worker   Gesture* SyncInterpret(HardwareState& state, stime_t* timeout);
27*aed3e508SAndroid Build Coastguard Worker   Gesture* HandleTimer(stime_t now, stime_t* timeout);
28*aed3e508SAndroid Build Coastguard Worker   virtual void ConsumeGesture(const Gesture& gs);
29*aed3e508SAndroid Build Coastguard Worker 
30*aed3e508SAndroid Build Coastguard Worker  private:
31*aed3e508SAndroid Build Coastguard Worker   Interpreter* interpreter_;
32*aed3e508SAndroid Build Coastguard Worker   const HardwareProperties* hwprops_;
33*aed3e508SAndroid Build Coastguard Worker   HardwareProperties dummy_;
34*aed3e508SAndroid Build Coastguard Worker   Gesture gesture_;
35*aed3e508SAndroid Build Coastguard Worker   std::unique_ptr<PropRegistry> prop_reg_;
36*aed3e508SAndroid Build Coastguard Worker   std::unique_ptr<MetricsProperties> mprops_;
37*aed3e508SAndroid Build Coastguard Worker };
38*aed3e508SAndroid Build Coastguard Worker 
39*aed3e508SAndroid Build Coastguard Worker 
40*aed3e508SAndroid Build Coastguard Worker // A utility method for making a HardwareState struct with just the fields
41*aed3e508SAndroid Build Coastguard Worker // necessary for touchpads. The remaining fields are set to sensible defaults.
42*aed3e508SAndroid Build Coastguard Worker HardwareState make_hwstate(stime_t timestamp, int buttons_down,
43*aed3e508SAndroid Build Coastguard Worker                            unsigned short finger_cnt, unsigned short touch_cnt,
44*aed3e508SAndroid Build Coastguard Worker                            struct FingerState* fingers);
45*aed3e508SAndroid Build Coastguard Worker 
46*aed3e508SAndroid Build Coastguard Worker }  // namespace gestures
47*aed3e508SAndroid Build Coastguard Worker 
48*aed3e508SAndroid Build Coastguard Worker #endif  // GESTURES_UNITTEST_UTIL_H_
49