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 #define private public
19 #include "ability_manager_client.h"
20 #undef private
21 #include "shell_command_result.h"
22 #include "mock_ability_manager_stub.h"
23 
24 using namespace testing::ext;
25 using namespace OHOS;
26 using namespace OHOS::AAFwk;
27 
28 namespace {
29 const std::string SHELL_COMMAND_RESULT = "shell cmd result aaaaaaaaaaaaaaaaa";
30 const int EXITCODE = 150;
31 }  // namespace
32 
33 class ShellCommandResultModuleTest : public ::testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp() override;
38     void TearDown() override;
39 };
40 
SetUpTestCase()41 void ShellCommandResultModuleTest::SetUpTestCase()
42 {}
43 
TearDownTestCase()44 void ShellCommandResultModuleTest::TearDownTestCase()
45 {}
46 
SetUp()47 void ShellCommandResultModuleTest::SetUp()
48 {}
49 
TearDown()50 void ShellCommandResultModuleTest::TearDown()
51 {}
52 
53 /**
54  * @tc.number: Shell_Command_Result_Module_Test_0100
55  * @tc.name: Marshalling and Unmarshalling
56  * @tc.desc: Verify the Marshalling and Unmarshalling.
57  */
58 HWTEST_F(ShellCommandResultModuleTest, Shell_Command_Result_Module_Test_0100, Function | MediumTest | Level1)
59 {
60     ShellCommandResult shellCmd;
61     shellCmd.exitCode = EXITCODE;
62     shellCmd.stdResult = SHELL_COMMAND_RESULT;
63     Parcel parcel;
64     EXPECT_TRUE(shellCmd.Marshalling(parcel));
65     EXPECT_NE(shellCmd.Unmarshalling(parcel), nullptr);
66 }
67 
68 /**
69  * @tc.number: Shell_Command_Result_Module_Test_0100
70  * @tc.name: Marshalling and ReadFromParcel
71  * @tc.desc: Verify the Marshalling and ReadFromParcel.
72  */
73 HWTEST_F(ShellCommandResultModuleTest, Shell_Command_Result_Module_Test_0200, Function | MediumTest | Level1)
74 {
75     ShellCommandResult shellCmd;
76     shellCmd.exitCode = EXITCODE;
77     shellCmd.stdResult = SHELL_COMMAND_RESULT;
78     Parcel parcel;
79     EXPECT_TRUE(shellCmd.Marshalling(parcel));
80     shellCmd.ReadFromParcel(parcel);
81     EXPECT_EQ(shellCmd.exitCode, EXITCODE);
82     EXPECT_EQ(shellCmd.stdResult, SHELL_COMMAND_RESULT);
83 }
84 
85