• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef DUMMY_CONTROLLER_H
16 #define DUMMY_CONTROLLER_H
17 
18 #include "ui_controller.h"
19 
20 namespace OHOS::uitest {
21 class DummyEventMonitor {
22 public:
GetInstance()23     static DummyEventMonitor &GetInstance()
24     {
25         static DummyEventMonitor instance;
26         return instance;
27     }
28 
OnEvent(string eventInfo)29     static void OnEvent(string eventInfo)
30     {
31         UiEventSourceInfo uiEventSourceInfo { "", "", eventInfo };
32         for (auto &listener : listeners_) {
33             listener->OnEvent(eventInfo, uiEventSourceInfo);
34         }
35     }
36 
RegisterUiEventListener(shared_ptr<UiEventListener> listerner)37     static void RegisterUiEventListener(shared_ptr<UiEventListener> listerner)
38     {
39         listeners_.push_back(listerner);
40     }
41 
GetListenerCount()42     static uint32_t GetListenerCount()
43     {
44         return listeners_.size();
45     }
46 private:
47     DummyEventMonitor() = default;
48     static vector<shared_ptr<UiEventListener>> listeners_;
49 };
50 
51 class DummyController : public UiController {
52 public:
DummyController()53     DummyController() : UiController() {}
54 
~DummyController()55     ~DummyController() {}
56 
IsWorkable()57     bool IsWorkable() const override
58     {
59         return workable_;
60     }
61 
IsWearable()62     bool IsWearable() const override
63     {
64         return false;
65     }
66 
IsAdjustWindowModeEnable()67     bool IsAdjustWindowModeEnable() const override
68     {
69         return false;
70     }
71 
SetWorkable(bool wb)72     void SetWorkable(bool wb)
73     {
74         this->workable_ = wb;
75     }
76 
RegisterUiEventListener(std::shared_ptr<UiEventListener> listener)77     void RegisterUiEventListener(std::shared_ptr<UiEventListener> listener) const override
78     {
79         DummyEventMonitor::GetInstance().RegisterUiEventListener(listener);
80     }
81 
82 private:
83     bool workable_ = false;
84 };
85 }
86 
87 #endif
88