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