• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <gtest/gtest.h>
17 #include <vector>
18 #include "script_context.h"
19 #include "script_instruction.h"
20 #include "script_instruction_unittest.h"
21 #include "script_instructionhelper.h"
22 #include "script_registercmd.h"
23 #include "script_manager_impl.h"
24 #include "script/script_unittest.h"
25 #include "unittest_comm.h"
26 
27 using namespace Uscript;
28 using namespace BasicInstruction;
29 using namespace Hpackage;
30 using namespace testing::ext;
31 
32 class TestPkgManager : public TestScriptPkgManager {
33 public:
ExtractFile(const std::string & fileId,StreamPtr output)34     int32_t ExtractFile(const std::string &fileId, StreamPtr output) override
35     {
36         return 0;
37     }
GetFileInfo(const std::string & fileId)38     const FileInfo *GetFileInfo(const std::string &fileId) override
39     {
40         static FileInfo fileInfo {};
41         if (fileId == "script") {
42             return &fileInfo;
43         }
44         return nullptr;
45     }
46 };
47 
48 class RegisterCmdInstructionUnittest : public ::testing::Test {
49 public:
RegisterCmdInstructionUnittest()50     RegisterCmdInstructionUnittest() {}
~RegisterCmdInstructionUnittest()51     ~RegisterCmdInstructionUnittest() {}
TestRegisterCmd01() const52     void TestRegisterCmd01() const
53     {
54         TestPkgManager pkgManager;
55         UTestScriptEnv env {&pkgManager};
56         ScriptManagerImpl scriptManager {&env};
57         ScriptInstructionHelper::GetBasicInstructionHelper(&scriptManager);
58         UScriptInstructionContext context {};
59         context.AddInputParam(std::make_shared<IntegerValue>(1));
60         auto instruction = std::make_unique<ScriptRegisterCmd>();
61         EXPECT_EQ(instruction->Execute(env, context), USCRIPT_INVALID_PARAM);
62         std::vector<UScriptValuePtr> output = context.GetOutVar();
63         EXPECT_EQ(output.size(), 0);
64     }
TestRegisterCmd02() const65     void TestRegisterCmd02() const
66     {
67         TestPkgManager pkgManager;
68         UTestScriptEnv env {&pkgManager};
69         ScriptManagerImpl scriptManager {&env};
70         ScriptInstructionHelper::GetBasicInstructionHelper(&scriptManager);
71         UScriptInstructionContext context {};
72         context.AddInputParam(std::make_shared<StringValue>(TEST_VALID_LIB_PATH));
73         context.AddInputParam(std::make_shared<IntegerValue>(1));
74         auto instruction = std::make_unique<ScriptRegisterCmd>();
75         EXPECT_EQ(instruction->Execute(env, context), USCRIPT_INVALID_PARAM);
76         std::vector<UScriptValuePtr> output = context.GetOutVar();
77         EXPECT_EQ(output.size(), 0);
78     }
TestRegisterCmd03() const79     void TestRegisterCmd03() const
80     {
81         TestPkgManager pkgManager;
82         UTestScriptEnv env {&pkgManager};
83         ScriptManagerImpl scriptManager {&env};
84         ScriptInstructionHelper::GetBasicInstructionHelper(&scriptManager);
85         UScriptInstructionContext context {};
86         context.AddInputParam(std::make_shared<StringValue>("uInstruction1"));
87         context.AddInputParam(std::make_shared<StringValue>(TEST_VALID_LIB_PATH));
88         auto instruction = std::make_unique<ScriptRegisterCmd>();
89         EXPECT_EQ(instruction->Execute(env, context), USCRIPT_SUCCESS);
90         std::vector<UScriptValuePtr> output = context.GetOutVar();
91         EXPECT_EQ(output.size(), 0);
92     }
93 protected:
SetUp()94     void SetUp() {}
TearDown()95     void TearDown() {}
TestBody()96     void TestBody() {}
97 };
98 
99 HWTEST_F(RegisterCmdInstructionUnittest, TestRegisterCmd01, TestSize.Level1)
100 {
101     RegisterCmdInstructionUnittest {}.TestRegisterCmd01();
102 }
103 
104 HWTEST_F(RegisterCmdInstructionUnittest, TestRegisterCmd02, TestSize.Level1)
105 {
106     RegisterCmdInstructionUnittest {}.TestRegisterCmd02();
107 }
108 
109 HWTEST_F(RegisterCmdInstructionUnittest, TestRegisterCmd03, TestSize.Level1)
110 {
111     RegisterCmdInstructionUnittest {}.TestRegisterCmd03();
112 }