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