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 #include "ability_command.h"
19 #include "tool_system_test.h"
20
21 using namespace testing::ext;
22 using namespace OHOS;
23 using namespace OHOS::AAFwk;
24
25 namespace {
26 const std::string STRING_PAGE_ABILITY_BUNDLE_PATH = "/data/test/resource/aa/pageAbilityBundleForDump.hap";
27 const std::string STRING_PAGE_ABILITY_BUNDLE_NAME = "com.ohos.tools.pageAbilityBundleForDump";
28
29 const std::string STRING_DATA_ABILITY_BUNDLE_PATH = "/data/test/resource/aa/dataAbilityBundleForDump.hap";
30 const std::string STRING_DATA_ABILITY_BUNDLE_NAME = "com.ohos.tools.dataAbilityBundleForDump";
31
32 const std::string STRING_SERVICE_ABILITY_BUNDLE_PATH = "/data/test/resource/aa/serviceAbilityBundleForStart.hap";
33 const std::string STRING_SERVICE_ABILITY_BUNDLE_NAME = "com.ohos.tools.serviceAbilityBundleForStart";
34 } // namespace
35
36 class AaCommandDumpSystemTest : public ::testing::Test {
37 public:
38 static void SetUpTestCase();
39 static void TearDownTestCase();
40 void SetUp() override;
41 void TearDown() override;
42 };
43
SetUpTestCase()44 void AaCommandDumpSystemTest::SetUpTestCase()
45 {}
46
TearDownTestCase()47 void AaCommandDumpSystemTest::TearDownTestCase()
48 {}
49
SetUp()50 void AaCommandDumpSystemTest::SetUp()
51 {
52 // reset optind to 0
53 optind = 0;
54 }
55
TearDown()56 void AaCommandDumpSystemTest::TearDown()
57 {}
58
59 /**
60 * @tc.number: Aa_Command_Dump_SystemTest_0100
61 * @tc.name: ExecCommand
62 * @tc.desc: Verify the "aa dump -a" command.
63 */
64 HWTEST_F(AaCommandDumpSystemTest, Aa_Command_Dump_SystemTest_0100, Function | MediumTest | Level1)
65 {
66 // uninstall the bundle
67 ToolSystemTest::UninstallBundle(STRING_PAGE_ABILITY_BUNDLE_NAME);
68
69 // install the bundle
70 ToolSystemTest::InstallBundle(STRING_PAGE_ABILITY_BUNDLE_PATH, false);
71
72 // dump the abilities
73 std::string command = "aa dump -a";
74 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
75
76 EXPECT_NE(commandResult, "");
77
78 // uninstall the bundle
79 ToolSystemTest::UninstallBundle(STRING_PAGE_ABILITY_BUNDLE_NAME);
80 }
81
82 /**
83 * @tc.number: Aa_Command_Dump_SystemTest_0200
84 * @tc.name: ExecCommand
85 * @tc.desc: Verify the "aa dump -d" command.
86 */
87 HWTEST_F(AaCommandDumpSystemTest, Aa_Command_Dump_SystemTest_0200, Function | MediumTest | Level1)
88 {
89 // uninstall the bundle
90 ToolSystemTest::UninstallBundle(STRING_DATA_ABILITY_BUNDLE_NAME);
91
92 // install the bundle
93 ToolSystemTest::InstallBundle(STRING_DATA_ABILITY_BUNDLE_PATH, false);
94
95 // dump the abilities
96 std::string command = "aa dump -d";
97 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
98
99 EXPECT_NE(commandResult, "");
100
101 // uninstall the bundle
102 ToolSystemTest::UninstallBundle(STRING_DATA_ABILITY_BUNDLE_NAME);
103 }
104
105 /**
106 * @tc.number: Aa_Command_Dump_SystemTest_0300
107 * @tc.name: ExecCommand
108 * @tc.desc: Verify the "aa dump -e" command.
109 */
110 HWTEST_F(AaCommandDumpSystemTest, Aa_Command_Dump_SystemTest_0300, Function | MediumTest | Level1)
111 {
112 // uninstall the bundle
113 ToolSystemTest::UninstallBundle(STRING_SERVICE_ABILITY_BUNDLE_NAME);
114
115 // install the bundle
116 ToolSystemTest::InstallBundle(STRING_SERVICE_ABILITY_BUNDLE_PATH, false);
117
118 // dump the abilities
119 std::string command = "aa dump -d";
120 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
121
122 EXPECT_NE(commandResult, "");
123
124 // uninstall the bundle
125 ToolSystemTest::UninstallBundle(STRING_SERVICE_ABILITY_BUNDLE_NAME);
126 }
127