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> g_subscriberMOCK = nullptr;
23
PublishCommonEvent(const CommonEventData & data)24 bool CommonEventManager::PublishCommonEvent(const CommonEventData &data)
25 {
26 GTEST_LOG_(INFO) << "MOCK CommonEventManager PublishCommonEvent";
27 if (!g_subscriberMOCK) {
28 GTEST_LOG_(INFO) << "g_subscriberMOCK is nullptr";
29 return false;
30 }
31 g_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 return true;
38 }
39
PublishCommonEvent(const CommonEventData & data,const CommonEventPublishInfo & publishInfo,const std::shared_ptr<CommonEventSubscriber> & subscriber)40 bool CommonEventManager::PublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishInfo,
41 const std::shared_ptr<CommonEventSubscriber> &subscriber)
42 {
43 return true;
44 }
45
SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> & subscriber)46 bool CommonEventManager::SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> &subscriber)
47 {
48 GTEST_LOG_(INFO) << "MOCK CommonEventManager SubscribeCommonEvent";
49 g_subscriberMOCK = subscriber;
50 return true;
51 }
52
UnSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> & subscriber)53 bool CommonEventManager::UnSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> &subscriber)
54 {
55 GTEST_LOG_(INFO) << "MOCK CommonEventManager UnSubscribeCommonEvent";
56 if (g_subscriberMOCK == subscriber) {
57 g_subscriberMOCK = nullptr;
58 }
59
60 return true;
61 }
62
GetStickyCommonEvent(const std::string & event,CommonEventData & commonEventData)63 bool CommonEventManager::GetStickyCommonEvent(const std::string &event, CommonEventData &commonEventData)
64 {
65 return true;
66 }
67 } // namespace EventFwk
68 } // namespace OHOS