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
18 #include "shell_cmd_result.h"
19 #include "hilog_tag_wrapper.h"
20
21 using namespace testing::ext;
22 using namespace OHOS;
23 using namespace OHOS::AppExecFwk;
24
25 namespace {
26 const std::string SHELLCOMMANDDRESULT = "shell cmd result CCCCCCCCCCCCCCCCCCCCCCCCCCC";
27 const std::string CHANGESHELLCOMMANDDRESULT = "shell cmd result DDDDDDDDDDDDDDDDDDDDDDDDDDDDDD";
28 const int EXITCODE = 20;
29 const int CHANGEEXITCODE = 300;
30 } // namespace
31
32 class ShellCmdResultModuleTest : public ::testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp() override;
37 void TearDown() override;
38 };
39
SetUpTestCase()40 void ShellCmdResultModuleTest::SetUpTestCase()
41 {}
42
TearDownTestCase()43 void ShellCmdResultModuleTest::TearDownTestCase()
44 {}
45
SetUp()46 void ShellCmdResultModuleTest::SetUp()
47 {}
48
TearDown()49 void ShellCmdResultModuleTest::TearDown()
50 {}
51
52 /**
53 * @tc.number: Shell_Cmd_Result_Module_Test_0100
54 * @tc.name: GetExitCode and GetStdResult
55 * @tc.desc: Verify the GetExitCode and GetStdResult.
56 */
57 HWTEST_F(ShellCmdResultModuleTest, Shell_Cmd_Result_Module_Test_0100, Function | MediumTest | Level1)
58 {
59 TAG_LOGI(AAFwkTag::TEST, "Shell_Cmd_Result_Module_Test_0100 is called");
60 ShellCmdResult shellCmd(EXITCODE, SHELLCOMMANDDRESULT);
61
62 EXPECT_EQ(shellCmd.GetExitCode(), EXITCODE);
63 EXPECT_EQ(shellCmd.GetStdResult(), SHELLCOMMANDDRESULT);
64 }
65
66 /**
67 * @tc.number: Shell_Cmd_Result_Module_Test_0200
68 * @tc.name: SetExitCode and GetExitCode
69 * @tc.desc: Verify the SetExitCode and GetExitCode.
70 */
71 HWTEST_F(ShellCmdResultModuleTest, Shell_Cmd_Result_Module_Test_0200, Function | MediumTest | Level1)
72 {
73 TAG_LOGI(AAFwkTag::TEST, "Shell_Cmd_Result_Module_Test_0200 is called");
74 ShellCmdResult shellCmd(EXITCODE, SHELLCOMMANDDRESULT);
75 shellCmd.SetExitCode(CHANGEEXITCODE);
76
77 EXPECT_EQ(shellCmd.GetExitCode(), CHANGEEXITCODE);
78 }
79
80 /**
81 * @tc.number: Shell_Cmd_Result_Module_Test_0300
82 * @tc.name: SetStdResult and GetStdResult
83 * @tc.desc: Verify the SetStdResult and GetStdResult.
84 */
85 HWTEST_F(ShellCmdResultModuleTest, Shell_Cmd_Result_Module_Test_0300, Function | MediumTest | Level1)
86 {
87 TAG_LOGI(AAFwkTag::TEST, "Shell_Cmd_Result_Module_Test_0300 is called");
88 ShellCmdResult shellCmd(EXITCODE, SHELLCOMMANDDRESULT);
89 shellCmd.SetStdResult(CHANGESHELLCOMMANDDRESULT);
90
91 EXPECT_EQ(shellCmd.GetStdResult(), CHANGESHELLCOMMANDDRESULT);
92 }
93