1 /*
2 * Copyright (c) 2021-2023 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 <thread>
19 #include "bundle_command.h"
20 #include "tool_system_test.h"
21
22 using namespace testing::ext;
23 using namespace OHOS;
24 using namespace OHOS::AppExecFwk;
25
26 namespace OHOS {
27 namespace {
28 const std::string STRING_BUNDLE_PATH = "/data/test/resource/bm/pageAbilityBundleForInstall.hap";
29 const std::string STRING_BUNDLE_NAME = "com.ohos.tools.pageAbilityBundleForInstall";
30 const std::string STRING_BUNDLE_NAME_INVALID = STRING_BUNDLE_NAME + ".invalid";
31 const std::string GET_FALSE = "error: failed to get information and the parameters may be wrong.";
32 } // namespace
33
34 class BmCommandDumpSystemTest : 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 BmCommandDumpSystemTest::SetUpTestCase()
43 {}
44
TearDownTestCase()45 void BmCommandDumpSystemTest::TearDownTestCase()
46 {}
47
SetUp()48 void BmCommandDumpSystemTest::SetUp()
49 {
50 // reset optind to 0
51 optind = 0;
52 }
53
TearDown()54 void BmCommandDumpSystemTest::TearDown()
55 {}
56
57 /**
58 * @tc.number: Bm_Command_Dump_SystemTest_0100
59 * @tc.name: ExecCommand
60 * @tc.desc: Verify the "bm dump -a" command.
61 */
62 HWTEST_F(BmCommandDumpSystemTest, Bm_Command_Dump_SystemTest_0100, Function | MediumTest | Level1)
63 {
64 // uninstall the bundle
65 ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
66
67 // install a valid bundle
68 ToolSystemTest::InstallBundle(STRING_BUNDLE_PATH, true);
69
70 // dump all bundle
71 std::string command = "bm dump -a";
72 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
73
74 EXPECT_NE(commandResult, "");
75
76 // uninstall the bundle
77 ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
78 }
79
80 /**
81 * @tc.number: Bm_Command_Dump_SystemTest_0200
82 * @tc.name: ExecCommand
83 * @tc.desc: Verify the "bm dump -n <bundle-name>" command.
84 */
85 HWTEST_F(BmCommandDumpSystemTest, Bm_Command_Dump_SystemTest_0200, Function | MediumTest | Level1)
86 {
87 // uninstall the bundle
88 ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
89
90 // install a valid bundle
91 ToolSystemTest::InstallBundle(STRING_BUNDLE_PATH, true);
92
93 // dump a valid bundle
94 std::string command = "bm dump -n " + STRING_BUNDLE_NAME;
95 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
96
97 EXPECT_NE(commandResult, "");
98
99 // uninstall the bundle
100 ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
101 }
102
103 /**
104 * @tc.number: Bm_Command_Dump_SystemTest_0300
105 * @tc.name: ExecCommand
106 * @tc.desc: Verify the "bm dump -n <bundle-name>" command.
107 */
108 HWTEST_F(BmCommandDumpSystemTest, Bm_Command_Dump_SystemTest_0300, Function | MediumTest | Level1)
109 {
110 // dump an invalid bundle
111 std::string command = "bm dump -n " + STRING_BUNDLE_NAME_INVALID;
112 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
113
114 EXPECT_EQ(commandResult, GET_FALSE + "\n");
115 }
116 } // OHOS
117