• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef MMI_KEY_MONITOR_MANAGER_MOCK_H
17 #define MMI_KEY_MONITOR_MANAGER_MOCK_H
18 #include <cstdint>
19 #include <gmock/gmock.h>
20 #include "key_event.h"
21 
22 namespace OHOS {
23 namespace MMI {
24 class IKeyMonitorManager {
25 public:
26     struct Monitor {
27         int32_t session_ { -1 };
28         int32_t key_ { KeyEvent::KEYCODE_UNKNOWN };
29         int32_t action_ { KeyEvent::KEY_ACTION_UNKNOWN };
30         bool isRepeat_ { false };
31     };
32 
33     IKeyMonitorManager() = default;
34     virtual ~IKeyMonitorManager() = default;
35 
36     virtual int32_t AddMonitor(const Monitor &monitor) = 0;
37     virtual void RemoveMonitor(const Monitor &monitor) = 0;
38 };
39 
40 class KeyMonitorManager final : public IKeyMonitorManager {
41 public:
42     KeyMonitorManager() = default;
43     ~KeyMonitorManager() override = default;
44 
45     MOCK_METHOD(int32_t, AddMonitor, (const Monitor&));
46     MOCK_METHOD(void, RemoveMonitor, (const Monitor&));
47 
48     static std::shared_ptr<KeyMonitorManager> GetInstance();
49     static void ReleaseInstance();
50 
51 private:
52     static std::shared_ptr<KeyMonitorManager> instance_;
53 };
54 
55 #define KEY_MONITOR_MGR KeyMonitorManager::GetInstance()
56 } // namespace MMI
57 } // namespace OHOS
58 #endif // MMI_KEY_MONITOR_MANAGER_MOCK_H