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