1 /*
2 * Copyright (c) 2021 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 protected public
19 #include "ability_command.h"
20 #undef protected
21 #include "mock_ability_manager_stub.h"
22 #define private public
23 #include "ability_manager_client.h"
24 #undef private
25 #include "ability_manager_interface.h"
26
27 using namespace testing::ext;
28 using namespace OHOS;
29 using namespace OHOS::AAFwk;
30
31 class AaCommandDumpModuleTest : public ::testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp() override;
36 void TearDown() override;
37
38 void MakeMockObjects() const;
39
40 std::string cmd_ = "dump";
41 };
42
SetUpTestCase()43 void AaCommandDumpModuleTest::SetUpTestCase()
44 {}
45
TearDownTestCase()46 void AaCommandDumpModuleTest::TearDownTestCase()
47 {}
48
SetUp()49 void AaCommandDumpModuleTest::SetUp()
50 {
51 // reset optind to 0
52 optind = 0;
53
54 // make mock objects
55 MakeMockObjects();
56 }
57
TearDown()58 void AaCommandDumpModuleTest::TearDown()
59 {}
60
MakeMockObjects() const61 void AaCommandDumpModuleTest::MakeMockObjects() const
62 {
63 // mock a stub
64 auto managerStubPtr = sptr<IAbilityManager>(new MockAbilityManagerStub());
65
66 // set the mock stub
67 auto managerClientPtr = AbilityManagerClient::GetInstance();
68 managerClientPtr->proxy_ = managerStubPtr;
69 }
70
71 /**
72 * @tc.number: Aa_Command_Dump_ModuleTest_0100
73 * @tc.name: ExecCommand
74 * @tc.desc: Verify the "aa dump -a" command.
75 */
76 HWTEST_F(AaCommandDumpModuleTest, Aa_Command_Dump_ModuleTest_0100, Function | MediumTest | Level1)
77 {
78 char* argv[] = {
79 (char*)TOOL_NAME.c_str(),
80 (char*)cmd_.c_str(),
81 (char*)"-a",
82 (char*)"",
83 };
84 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
85
86 AbilityManagerShellCommand cmd(argc, argv);
87 EXPECT_EQ(cmd.ExecCommand(), "");
88 }
89
90 /**
91 * @tc.number: Aa_Command_Dump_ModuleTest_0200
92 * @tc.name: ExecCommand
93 * @tc.desc: Verify the "aa dump --all" command.
94 */
95 HWTEST_F(AaCommandDumpModuleTest, Aa_Command_Dump_ModuleTest_0200, Function | MediumTest | Level1)
96 {
97 char* argv[] = {
98 (char*)TOOL_NAME.c_str(),
99 (char*)cmd_.c_str(),
100 (char*)"--all",
101 (char*)"",
102 };
103 int argc = sizeof(argv) / sizeof(argv[0]) - 1;
104
105 AbilityManagerShellCommand cmd(argc, argv);
106 EXPECT_EQ(cmd.ExecCommand(), "");
107 }
108