1 /*
2  * Copyright (c) 2021 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 #ifndef BASE_NOTIFICATION_CES_STANDARD_CESFWK_TOOLS_TEST_MOCK_MOCK_COMMON_EVENT_STUB_H
17 #define BASE_NOTIFICATION_CES_STANDARD_CESFWK_TOOLS_TEST_MOCK_MOCK_COMMON_EVENT_STUB_H
18 
19 #include "gmock/gmock.h"
20 #include <mutex>
21 
22 #include "common_event_stub.h"
23 #include "event_log_wrapper.h"
24 #include "refbase.h"
25 
26 namespace OHOS {
27 namespace EventFwk {
28 class MockCommonEventStub : public CommonEventStub {
29 public:
30     static sptr<MockCommonEventStub> GetInstance();
31     MOCK_METHOD4(FinishReceiver, bool(const sptr<IRemoteObject> &proxy, const int32_t &code,
32                                      const std::string &receiverData, const bool &abortEvent));
33 
34     /**
35      * Publishes a common event.
36      *
37      * @param event Indicates the common event data.
38      * @param publishInfo Indicates the publish info.
39      * @param commonEventListener Indicates the last subscriber to receive the ordered common event.
40      * @param userId Indicates the user ID.
41      * @return Returns true if success; false otherwise.
42      */
43     int32_t PublishCommonEvent(const CommonEventData &event, const CommonEventPublishInfo &publishinfo,
44         const sptr<IRemoteObject> &commonEventListener, const int32_t &userId) override;
45 
46     /**
47      * Subscribes to common events.
48      *
49      * @param subscribeInfo the subscribe information.
50      * @param commonEventListener the subscriber object.
51      * @param instanceKey Indicates the instance key
52      * @return Returns true if success; false otherwise.
53      */
54     int32_t SubscribeCommonEvent(const CommonEventSubscribeInfo &subscribeInfo,
55         const sptr<IRemoteObject> &commonEventListener, const int32_t instanceKey = 0) override;
56 
57     /**
58      * Dumps the state for common event service.
59      *
60      * @param event the specified event.
61      * @param userId the user id.
62      * @param state the output result.
63      * @return Returns true if success; false otherwise.
64      */
65     bool DumpState(const uint8_t &dumpType, const std::string &event, const int32_t &userId,
66         std::vector<std::string> &state) override;
67 
68 private:
69     static std::mutex instanceMutex_;
70     static sptr<MockCommonEventStub> instance_;
71     std::shared_ptr<CommonEventSubscribeInfo> subscribeInfoPtr;
72 };
73 }  // namespace EventFwk
74 }  // namespace OHOS
75 
76 #endif  // BASE_NOTIFICATION_CES_STANDARD_CESFWK_TOOLS_TEST_MOCK_MOCK_COMMON_EVENT_STUB_H
77