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 SCRIPT_INSTRUCTION_UNITTEST_H
17 #define SCRIPT_INSTRUCTION_UNITTEST_H
18 namespace Uscript {
19 class UTestScriptEnv : public UScriptEnv {
20 public:
UTestScriptEnv(Hpackage::PkgManager::PkgManagerPtr pkgManager)21     explicit UTestScriptEnv(Hpackage::PkgManager::PkgManagerPtr pkgManager) : UScriptEnv(pkgManager)
22     {}
23     ~UTestScriptEnv() = default;
24 
PostMessage(const std::string & cmd,std::string content)25     void PostMessage(const std::string &cmd, std::string content) {}
26 
GetInstructionFactory()27     UScriptInstructionFactoryPtr GetInstructionFactory()
28     {
29         return nullptr;
30     }
31 
GetInstructionNames()32     const std::vector<std::string> GetInstructionNames() const
33     {
34         return {};
35     }
36 
IsRetry()37     bool IsRetry() const
38     {
39         return isRetry;
40     }
41 
GetPostmsgFunc()42     virtual Updater::PostMessageFunction GetPostmsgFunc()
43     {
44         return nullptr;
45     }
46     UScriptInstructionFactory *factory_ = nullptr;
47 private:
48     bool isRetry = false;
49 };
50 
51 constexpr auto TEST_VALID_LIB_PATH = "/data/updater/lib/libuser_instruction.so";
52 constexpr auto TEST_INVALID_LIB_PATH = "/data/updater/lib/libuser_instruction_invalid.so";
53 constexpr auto TEST_NONEXIST_LIB_PATH = "/system/lib/other.so"; // this lib doesn't exist
54 }
55 #endif // SCRIPT_INSTRUCTION_UNITTEST_H