• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 
16 #include <gtest/gtest.h>
17 #include "common_event_manager.h"
18 #include "singleton.h"
19 
20 namespace OHOS {
21 namespace EventFwk {
22 static std::shared_ptr<CommonEventSubscriber> subscriberMOCK = nullptr;
23 
PublishCommonEvent(const CommonEventData & data)24 bool CommonEventManager::PublishCommonEvent(const CommonEventData& data)
25 {
26     GTEST_LOG_(INFO) << "MOCK CommonEventManager PublishCommonEvent";
27     if (!subscriberMOCK) {
28         GTEST_LOG_(INFO) << "subscriberMOCK is nullptr";
29         return false;
30     }
31     subscriberMOCK->OnReceiveEvent(data);
32     return true;
33 }
34 
PublishCommonEvent(const CommonEventData & data,const CommonEventPublishInfo & publishInfo)35 bool CommonEventManager::PublishCommonEvent(const CommonEventData& data, const CommonEventPublishInfo& publishInfo)
36 {
37     (void)data;
38     (void)publishInfo;
39     return true;
40 }
41 
PublishCommonEvent(const CommonEventData & data,const CommonEventPublishInfo & publishInfo,const std::shared_ptr<CommonEventSubscriber> & subscriber)42 bool CommonEventManager::PublishCommonEvent(const CommonEventData& data, const CommonEventPublishInfo& publishInfo,
43     const std::shared_ptr<CommonEventSubscriber>& subscriber)
44 {
45     (void)data;
46     (void)publishInfo;
47     (void)subscriber;
48     return true;
49 }
50 
SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> & subscriber)51 bool CommonEventManager::SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber>& subscriber)
52 {
53     GTEST_LOG_(INFO) << "MOCK CommonEventManager SubscribeCommonEvent";
54     subscriberMOCK = subscriber;
55     return true;
56 }
57 
UnSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> & subscriber)58 bool CommonEventManager::UnSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber>& subscriber)
59 {
60     GTEST_LOG_(INFO) << "MOCK CommonEventManager UnSubscribeCommonEvent";
61     if (subscriberMOCK == subscriber) {
62         subscriberMOCK = nullptr;
63     }
64 
65     return true;
66 }
67 
GetStickyCommonEvent(const std::string & event,CommonEventData & commonEventData)68 bool CommonEventManager::GetStickyCommonEvent(const std::string& event, CommonEventData& commonEventData)
69 {
70     (void)event;
71     (void)commonEventData;
72     return true;
73 }
74 } // namespace EventFwk
75 } // namespace OHOS