1 /* 2 * Copyright (c) 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 "simulator.h" 17 #include "MockGlobalResult.h" 18 19 namespace OHOS { 20 namespace AbilityRuntime { 21 22 class MockSimulator : public Simulator { 23 public: 24 MockSimulator() = default; 25 ~MockSimulator() = default; 26 int64_t StartAbility(const std::string &abilitySrcPath, TerminateCallback callback, 27 const std::string &abilityName) override 28 { 29 int ret = 1; 30 return ret; 31 } 32 33 void TerminateAbility(int64_t abilityId) override 34 { 35 g_terminateAbility = true; 36 } 37 38 void UpdateConfiguration(const AppExecFwk::Configuration &config) override 39 { 40 g_updateConfiguration = true; 41 } 42 43 void SetMockList(const std::map<std::string, std::string> &mockList) override 44 { 45 g_setAbilityMockList = true; 46 } 47 48 void SetHostResolveBufferTracker(ResolveBufferTrackerCallback cb) override 49 { 50 g_setHostResolveBufferTracker = true; 51 } 52 53 Options option_; 54 }; 55 Create(const Options &options)56std::shared_ptr<Simulator> Simulator::Create(const Options &options) 57 { 58 auto simulator = std::make_shared<MockSimulator>(); 59 if (simulator) { 60 simulator->option_ = options; 61 return simulator; 62 } 63 return nullptr; 64 } 65 } 66 }