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_subscriber.h"
18 
19 namespace OHOS {
20 namespace EventFwk {
CommonEventSubscriber()21 CommonEventSubscriber::CommonEventSubscriber() : result_(nullptr)
22 {}
23 
CommonEventSubscriber(const CommonEventSubscribeInfo & subscribeInfo)24 CommonEventSubscriber::CommonEventSubscriber(const CommonEventSubscribeInfo& subscribeInfo)
25     : subscribeInfo_(subscribeInfo), result_(nullptr)
26 {}
27 
~CommonEventSubscriber()28 CommonEventSubscriber::~CommonEventSubscriber()
29 {}
30 
GetSubscribeInfo() const31 const CommonEventSubscribeInfo& CommonEventSubscriber::GetSubscribeInfo() const
32 {
33     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber CommonEventSubscriber";
34     return subscribeInfo_;
35 }
36 
SetCode(const int & code)37 bool CommonEventSubscriber::SetCode(const int& code)
38 {
39     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber SetCode";
40     return result_->SetCode(code);
41 }
42 
GetCode() const43 int CommonEventSubscriber::GetCode() const
44 {
45     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber GetCode";
46     return result_->GetCode();
47 }
48 
SetData(const std::string & data)49 bool CommonEventSubscriber::SetData(const std::string& data)
50 {
51     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber SetData";
52     return result_->SetData(data);
53 }
54 
GetData() const55 std::string CommonEventSubscriber::GetData() const
56 {
57     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber GetData";
58     return result_->GetData();
59 }
60 
SetCodeAndData(const int & code,const std::string & data)61 bool CommonEventSubscriber::SetCodeAndData(const int& code, const std::string& data)
62 {
63     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber SetCodeAndData";
64     return result_->SetCodeAndData(code, data);
65 }
66 
AbortCommonEvent()67 bool CommonEventSubscriber::AbortCommonEvent()
68 {
69     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber AbortCommonEvent";
70     return result_->AbortCommonEvent();
71 }
72 
ClearAbortCommonEvent()73 bool CommonEventSubscriber::ClearAbortCommonEvent()
74 {
75     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber ClearAbortCommonEvent";
76     return result_->ClearAbortCommonEvent();
77 }
78 
GetAbortCommonEvent() const79 bool CommonEventSubscriber::GetAbortCommonEvent() const
80 {
81     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber GetAbortCommonEvent";
82     return result_->GetAbortCommonEvent();
83 }
84 
GoAsyncCommonEvent()85 std::shared_ptr<AsyncCommonEventResult> CommonEventSubscriber::GoAsyncCommonEvent()
86 {
87     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber GoAsyncCommonEvent";
88     std::shared_ptr<AsyncCommonEventResult> res = result_;
89     result_ = nullptr;
90     return res;
91 }
92 
IsOrderedCommonEvent() const93 bool CommonEventSubscriber::IsOrderedCommonEvent() const
94 {
95     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber IsOrderedCommonEvent";
96     return (result_ != nullptr) ? result_->IsOrderedCommonEvent() : false;
97 }
98 
IsStickyCommonEvent() const99 bool CommonEventSubscriber::IsStickyCommonEvent() const
100 {
101     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber IsStickyCommonEvent";
102     return (result_ != nullptr) ? result_->IsStickyCommonEvent() : false;
103 }
104 
SetAsyncCommonEventResult(const std::shared_ptr<AsyncCommonEventResult> & result)105 bool CommonEventSubscriber::SetAsyncCommonEventResult(const std::shared_ptr<AsyncCommonEventResult>& result)
106 {
107     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber SetAsyncCommonEventResult";
108     result_ = result;
109     return true;
110 }
111 
GetAsyncCommonEventResult()112 std::shared_ptr<AsyncCommonEventResult> CommonEventSubscriber::GetAsyncCommonEventResult()
113 {
114     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber GetAsyncCommonEventResult";
115     return result_;
116 }
117 
CheckSynchronous() const118 bool CommonEventSubscriber::CheckSynchronous() const
119 {
120     GTEST_LOG_(INFO) << "MOCK CommonEventSubscriber CheckSynchronous";
121     return true;
122 }
123 } // namespace EventFwk
124 } // namespace OHOS