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 #include "mock_common_event_stub.h"
17
18 using namespace OHOS::EventFwk;
19
PublishCommonEvent(const CommonEventData & event,const CommonEventPublishInfo & publishinfo,const sptr<IRemoteObject> & commonEventListener,const int32_t & userId)20 bool MockCommonEventStub::PublishCommonEvent(const CommonEventData &event, const CommonEventPublishInfo &publishinfo,
21 const sptr<IRemoteObject> &commonEventListener, const int32_t &userId)
22 {
23 EVENT_LOGI("enter");
24
25 return true;
26 }
27
SubscribeCommonEvent(const CommonEventSubscribeInfo & subscribeInfo,const sptr<IRemoteObject> & commonEventListener)28 bool MockCommonEventStub::SubscribeCommonEvent(
29 const CommonEventSubscribeInfo &subscribeInfo, const sptr<IRemoteObject> &commonEventListener)
30 {
31 EVENT_LOGI("enter");
32
33 subscribeInfoPtr = std::make_shared<CommonEventSubscribeInfo>(subscribeInfo);
34
35 return true;
36 }
37
DumpState(const std::string & event,const int32_t & userId,std::vector<std::string> & state)38 bool MockCommonEventStub::DumpState(const std::string &event, const int32_t &userId, std::vector<std::string> &state)
39 {
40 EVENT_LOGI("enter");
41
42 if (subscribeInfoPtr) {
43 // get matchingSkills
44 auto matchingSkills = subscribeInfoPtr->GetMatchingSkills();
45 // get events
46 auto events = matchingSkills.GetEvents();
47
48 for (auto it : events) {
49 state.emplace_back(it);
50 }
51 } else {
52 // do nothing
53 }
54
55 subscribeInfoPtr = nullptr;
56
57 return true;
58 }
59