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