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 #ifndef RESSCHED_SERVICES_RESSCHEDMGR_TEST_UNITTEST_INCLUDE_MOCK_H 17 #define RESSCHED_SERVICES_RESSCHEDMGR_TEST_UNITTEST_INCLUDE_MOCK_H 18 19 #include <algorithm> 20 #include <dlfcn.h> 21 #include <iostream> 22 #include <memory> 23 #include <thread> 24 #include "datetime_ex.h" 25 #include "event_runner.h" 26 #include "plugin_mgr.h" 27 28 namespace OHOS { 29 namespace ResourceSchedule { 30 class MockPluginMgr : public PluginMgr { 31 public: 32 MockPluginMgr() = default; 33 const std::string TEST_PREFIX_RES_SWITCH_PATH = 34 "/data/test/resource/resschedfwk/parseswitch/res_sched_plugin_switch.xml"; 35 const std::string TEST_PREFIX_RES_PATH = "/data/test/resource/resschedfwk/parseconfig/res_sched_config.xml"; 36 const std::string MOCK_RUNNER_NAME = "mockRssDispatcher"; 37 const int32_t DISPATCH_WARNING_TIME = 1; // ms 38 const int32_t DISPATCH_TIME_OUT = 10; // ms 39 enum : int32_t { 40 SWITCH_NULL, 41 LOAD_CONFIG_FAIL, 42 LOAD_CUST_CONFIG_FAIL, 43 INIT_SUCCESS 44 }; 45 int32_t initStatus; 46 Init()47 void Init() 48 { 49 if (pluginSwitch_) { 50 initStatus = SWITCH_NULL; 51 return; 52 } 53 54 if (!pluginSwitch_) { 55 pluginSwitch_ = std::make_unique<PluginSwitch>(); 56 bool loadRet = pluginSwitch_->LoadFromConfigFile(TEST_PREFIX_RES_SWITCH_PATH); 57 if (!loadRet) { 58 initStatus = LOAD_CONFIG_FAIL; 59 } 60 } 61 62 if (!configReader_) { 63 configReader_ = std::make_unique<ConfigReader>(); 64 bool loadRet = configReader_->LoadFromCustConfigFile(TEST_PREFIX_RES_PATH); 65 if (!loadRet) { 66 initStatus = LOAD_CUST_CONFIG_FAIL; 67 } 68 } 69 70 initStatus = INIT_SUCCESS; 71 } 72 }; 73 } // namespace ResourceSchedule 74 } // namespace OHOS 75 76 #endif // RESSCHED_SERVICES_RESSCHEDMGR_TEST_UNITTEST_INCLUDEMOCK_H 77