1 /* 2 * Copyright (c) 2023-2024 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 "common_event_manager.h" 17 #include "mock_common_event.h" 18 19 namespace { 20 bool g_mockPublishCommonEvent = true; 21 bool g_mockSubscribeCommonEvent = true; 22 int32_t CLOUD_CONFIG_INDEX = 7; 23 } 24 25 namespace OHOS { 26 namespace EventFwk { PublishCommonEvent(const CommonEventData& data)27bool CommonEventManager::PublishCommonEvent(const CommonEventData& data) 28 { 29 return g_mockPublishCommonEvent; 30 } 31 SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber>& subscriber)32bool CommonEventManager::SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber>& subscriber) 33 { 34 return g_mockSubscribeCommonEvent; 35 } 36 UnSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber>& subscriber)37bool CommonEventManager::UnSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber>& subscriber) 38 { 39 return g_mockSubscribeCommonEvent; 40 } 41 } // namespace EventFwk 42 namespace DevStandbyMgr { 43 int g_mockFunctionCallCount = 0; 44 int32_t ERR_FAIL = -1; 45 MockPublishCommonEvent(bool mockRet)46void MockCommonEvent::MockPublishCommonEvent(bool mockRet) 47 { 48 g_mockPublishCommonEvent = mockRet; 49 } 50 MockSubscribeCommonEvent(bool mockRet)51void MockCommonEvent::MockSubscribeCommonEvent(bool mockRet) 52 { 53 g_mockSubscribeCommonEvent = mockRet; 54 } 55 MockGetSingleExtConfigFunc(int32_t index, std::string &config)56int32_t MockUtils::MockGetSingleExtConfigFunc(int32_t index, std::string &config) 57 { 58 g_mockFunctionCallCount++; 59 if (index == CLOUD_CONFIG_INDEX) { 60 config = R"({"version" : "1.1.1.1"})"; 61 return ERR_OK; 62 } 63 return ERR_FAIL; 64 } 65 } 66 } // namespace OHOS 67