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
23 using namespace testing::ext;
24 using namespace OHOS;
25 using namespace OHOS::AAFwk;
26
27 namespace {
28 const std::string SHELL_COMMAND_RESULT = "shell cmd result";
29 const int EXITCODE = 15;
30 } // namespace
31
32 class ShellCommandResultTest : 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 ShellCommandResultTest::SetUpTestCase()
41 {}
42
TearDownTestCase()43 void ShellCommandResultTest::TearDownTestCase()
44 {}
45
SetUp()46 void ShellCommandResultTest::SetUp()
47 {}
48
TearDown()49 void ShellCommandResultTest::TearDown()
50 {}
51
52 /**
53 * @tc.number: Shell_Command_Result_Test_0100
54 * @tc.name: Marshalling and Unmarshalling
55 * @tc.desc: Verify the Marshalling and Unmarshalling.
56 */
57 HWTEST_F(ShellCommandResultTest, Shell_Command_Result_Test_0100, Function | MediumTest | Level1)
58 {
59 ShellCommandResult shellCmd;
60 shellCmd.exitCode = EXITCODE;
61 shellCmd.stdResult = SHELL_COMMAND_RESULT;
62 Parcel parcel;
63 EXPECT_TRUE(shellCmd.Marshalling(parcel));
64 EXPECT_NE(shellCmd.Unmarshalling(parcel), nullptr);
65 }
66
67 /**
68 * @tc.number: Shell_Command_Result_Test_0200
69 * @tc.name: Marshalling and ReadFromParcel
70 * @tc.desc: Verify the Marshalling and ReadFromParcel.
71 */
72 HWTEST_F(ShellCommandResultTest, Shell_Command_Result_Test_0200, Function | MediumTest | Level1)
73 {
74 ShellCommandResult shellCmd;
75 shellCmd.exitCode = EXITCODE;
76 shellCmd.stdResult = SHELL_COMMAND_RESULT;
77 Parcel parcel;
78 EXPECT_TRUE(shellCmd.Marshalling(parcel));
79 shellCmd.ReadFromParcel(parcel);
80 EXPECT_EQ(shellCmd.exitCode, EXITCODE);
81 EXPECT_EQ(shellCmd.stdResult, SHELL_COMMAND_RESULT);
82 }
83
84