• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _UI_TEST_INPUT_LISTENER_H
18 #define _UI_TEST_INPUT_LISTENER_H
19 
20 #include <android-base/thread_annotations.h>
21 #include <gtest/gtest.h>
22 #include "InputListener.h"
23 
24 using std::chrono_literals::operator""ms;
25 
26 namespace android {
27 
28 // --- TestInputListener ---
29 
30 class TestInputListener : public InputListenerInterface {
31 protected:
32     virtual ~TestInputListener();
33 
34 public:
35     TestInputListener(std::chrono::milliseconds eventHappenedTimeout = 0ms,
36                       std::chrono::milliseconds eventDidNotHappenTimeout = 0ms);
37 
38     void assertNotifyConfigurationChangedWasCalled(
39             NotifyConfigurationChangedArgs* outEventArgs = nullptr);
40 
41     void assertNotifyConfigurationChangedWasNotCalled();
42 
43     void assertNotifyDeviceResetWasCalled(NotifyDeviceResetArgs* outEventArgs = nullptr);
44 
45     void assertNotifyDeviceResetWasNotCalled();
46 
47     void assertNotifyKeyWasCalled(NotifyKeyArgs* outEventArgs = nullptr);
48 
49     void assertNotifyKeyWasNotCalled();
50 
51     void assertNotifyMotionWasCalled(NotifyMotionArgs* outEventArgs = nullptr);
52 
53     void assertNotifyMotionWasNotCalled();
54 
55     void assertNotifySwitchWasCalled(NotifySwitchArgs* outEventArgs = nullptr);
56 
57     void assertNotifyCaptureWasCalled(NotifyPointerCaptureChangedArgs* outEventArgs = nullptr);
58     void assertNotifySensorWasCalled(NotifySensorArgs* outEventArgs = nullptr);
59     void assertNotifyVibratorStateWasCalled(NotifyVibratorStateArgs* outEventArgs = nullptr);
60 
61 private:
62     template <class NotifyArgsType>
63     void assertCalled(NotifyArgsType* outEventArgs, std::string message);
64 
65     template <class NotifyArgsType>
66     void assertNotCalled(std::string message);
67 
68     template <class NotifyArgsType>
69     void notify(const NotifyArgsType* args);
70 
71     virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
72 
73     virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) override;
74 
75     virtual void notifyKey(const NotifyKeyArgs* args) override;
76 
77     virtual void notifyMotion(const NotifyMotionArgs* args) override;
78 
79     virtual void notifySwitch(const NotifySwitchArgs* args) override;
80 
81     virtual void notifySensor(const NotifySensorArgs* args) override;
82 
83     virtual void notifyVibratorState(const NotifyVibratorStateArgs* args) override;
84 
85     virtual void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override;
86 
87     std::mutex mLock;
88     std::condition_variable mCondition;
89     const std::chrono::milliseconds mEventHappenedTimeout;
90     const std::chrono::milliseconds mEventDidNotHappenTimeout;
91 
92     std::tuple<std::vector<NotifyConfigurationChangedArgs>,  //
93                std::vector<NotifyDeviceResetArgs>,           //
94                std::vector<NotifyKeyArgs>,                   //
95                std::vector<NotifyMotionArgs>,                //
96                std::vector<NotifySwitchArgs>,                //
97                std::vector<NotifySensorArgs>,                //
98                std::vector<NotifyVibratorStateArgs>,         //
99                std::vector<NotifyPointerCaptureChangedArgs>> //
100             mQueues GUARDED_BY(mLock);
101 };
102 
103 } // namespace android
104 #endif
105