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 ErrCode PublishCommonEvent( 35 const CommonEventData& event, 36 const CommonEventPublishInfo& publishInfo, 37 int32_t userId, 38 int32_t& funcResult) override; 39 40 ErrCode PublishCommonEvent( 41 const CommonEventData& event, 42 const CommonEventPublishInfo& publishInfo, 43 const sptr<IRemoteObject>& commonEventListener, 44 int32_t userId, 45 int32_t& funcResult) override; 46 47 ErrCode PublishCommonEvent( 48 const CommonEventData& event, 49 const CommonEventPublishInfo& publishInfo, 50 uint32_t uid, 51 int32_t callerToken, 52 int32_t userId, 53 bool& funcResult) override; 54 55 ErrCode PublishCommonEvent( 56 const CommonEventData& event, 57 const CommonEventPublishInfo& publishInfo, 58 const sptr<IRemoteObject>& commonEventListener, 59 uint32_t uid, 60 int32_t callerToken, 61 int32_t userId, 62 bool& funcResult) override; 63 64 ErrCode SubscribeCommonEvent( 65 const CommonEventSubscribeInfo& subscribeInfo, 66 const sptr<IRemoteObject>& commonEventListener, 67 int32_t instanceKey, 68 int32_t& funcResult) override; 69 70 ErrCode UnsubscribeCommonEvent( 71 const sptr<IRemoteObject>& commonEventListener, 72 int32_t& funcResult) override; 73 74 ErrCode UnsubscribeCommonEventSync( 75 const sptr<IRemoteObject>& commonEventListener, 76 int32_t& funcResult) override; 77 78 ErrCode GetStickyCommonEvent( 79 const std::string& event, 80 CommonEventData& eventData, 81 bool& funcResult) override; 82 83 ErrCode DumpState( 84 uint8_t dumpType, 85 const std::string& event, 86 int32_t userId, 87 std::vector<std::string>& state, 88 bool& funcResult) override; 89 90 ErrCode FinishReceiver( 91 const sptr<IRemoteObject>& proxy, 92 int32_t code, 93 const std::string& receiverData, 94 bool abortEvent, 95 bool& funcResult) override; 96 97 ErrCode Freeze( 98 uint32_t uid, 99 bool& funcResult) override; 100 101 ErrCode Unfreeze( 102 uint32_t uid, 103 bool& funcResult) override; 104 105 ErrCode UnfreezeAll( 106 bool& funcResult) override; 107 108 ErrCode RemoveStickyCommonEvent( 109 const std::string& event, 110 int32_t& funcResult) override; 111 112 ErrCode SetStaticSubscriberState( 113 bool enable, 114 int32_t& funcResult) override; 115 116 ErrCode SetStaticSubscriberStateByEvents( 117 const std::vector<std::string>& events, 118 bool enable, 119 int32_t& funcResult) override; 120 121 ErrCode SetFreezeStatus( 122 const std::set<int32_t>& pidList, 123 bool isFreeze, 124 bool& funcResult) override; 125 126 private: 127 static std::mutex instanceMutex_; 128 static sptr<MockCommonEventStub> instance_; 129 std::shared_ptr<CommonEventSubscribeInfo> subscribeInfoPtr; 130 }; 131 } // namespace EventFwk 132 } // namespace OHOS 133 134 #endif // BASE_NOTIFICATION_CES_STANDARD_CESFWK_TOOLS_TEST_MOCK_MOCK_COMMON_EVENT_STUB_H 135