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 <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::AAFwk;
25 using namespace OHOS::AppExecFwk;
26
27 namespace {
28 const std::string STRING_BUNDLE_PATH = "/data/test/resource/bm/pageAbilityBundleForInstall.hap";
29 const std::string STRING_BUNDLE_PATH_INVALID = STRING_BUNDLE_PATH + ".invalid";
30 const std::string STRING_BUNDLE_NAME = "com.ohos.tools.pageAbilityBundleForInstall";
31
32 const std::string STRING_BUNDLE_PATH_NO_SIGNATURE = "/data/test/resource/bm/pageAbilityBundleForInstallNoSignature.hap";
33 } // namespace
34
35 class BmCommandInstallSystemTest : public ::testing::Test {
36 public:
37 static void SetUpTestCase();
38 static void TearDownTestCase();
39 void SetUp() override;
40 void TearDown() override;
41 };
42
SetUpTestCase()43 void BmCommandInstallSystemTest::SetUpTestCase()
44 {}
45
TearDownTestCase()46 void BmCommandInstallSystemTest::TearDownTestCase()
47 {}
48
SetUp()49 void BmCommandInstallSystemTest::SetUp()
50 {
51 // reset optind to 0
52 optind = 0;
53 }
54
TearDown()55 void BmCommandInstallSystemTest::TearDown()
56 {}
57
58 /**
59 * @tc.number: Bm_Command_Install_SystemTest_0100
60 * @tc.name: ExecCommand
61 * @tc.desc: Verify the "bm install -p <bundle-path>" command.
62 */
63 HWTEST_F(BmCommandInstallSystemTest, Bm_Command_Install_SystemTest_0100, Function | MediumTest | Level1)
64 {
65 // uninstall the bundle
66 ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
67
68 // install a valid bundle
69 ToolSystemTest::InstallBundle(STRING_BUNDLE_PATH, true);
70
71 // uninstall the bundle
72 ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
73 }
74
75 /**
76 * @tc.number: Bm_Command_Install_SystemTest_0200
77 * @tc.name: ExecCommand
78 * @tc.desc: Verify the "bm install -p <bundle-path>" command.
79 */
80 HWTEST_F(BmCommandInstallSystemTest, Bm_Command_Install_SystemTest_0200, Function | MediumTest | Level1)
81 {
82 // install an invalid bundle
83 std::string command = "bm install -p " + STRING_BUNDLE_PATH_INVALID;
84 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
85
86 EXPECT_EQ(commandResult, STRING_INSTALL_BUNDLE_NG + "\n");
87 }
88
89 /**
90 * @tc.number: Bm_Command_Install_SystemTest_0300
91 * @tc.name: ExecCommand
92 * @tc.desc: Verify the "bm install -p <bundle-path> -r" command.
93 */
94 HWTEST_F(BmCommandInstallSystemTest, Bm_Command_Install_SystemTest_0300, Function | MediumTest | Level1)
95 {
96 // uninstall the bundle
97 ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
98
99 // install a valid bundle
100 ToolSystemTest::InstallBundle(STRING_BUNDLE_PATH, true);
101
102 // install the same bundle
103 std::string command = "bm install -p " + STRING_BUNDLE_PATH + " -r";
104 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
105
106 EXPECT_EQ(commandResult, STRING_INSTALL_BUNDLE_OK + "\n");
107
108 // uninstall the bundle
109 ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
110 }
111
112 /**
113 * @tc.number: Bm_Command_Install_SystemTest_0400
114 * @tc.name: ExecCommand
115 * @tc.desc: Verify the "bm install -p <bundle-path>" command.
116 */
117 HWTEST_F(BmCommandInstallSystemTest, Bm_Command_Install_SystemTest_0400, Function | MediumTest | Level1)
118 {
119 // uninstall the bundle
120 ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
121
122 // install a valid bundle with no signature
123 std::string command = "bm install -p " + STRING_BUNDLE_PATH_NO_SIGNATURE;
124 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
125
126 EXPECT_NE(commandResult, STRING_INSTALL_BUNDLE_OK + "\n");
127
128 // uninstall the bundle
129 ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
130 }
131
132 /**
133 * @tc.number: Bm_Command_Install_SystemTest_0500
134 * @tc.name: ExecCommand
135 * @tc.desc: Verify the "bm install -p <bundle-path> -f" command.
136 */
137 HWTEST_F(BmCommandInstallSystemTest, Bm_Command_Install_SystemTest_0500, Function | MediumTest | Level1)
138 {
139 // uninstall the bundle
140 ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
141
142 // install a valid bundle with no signature
143 std::string command = "bm install -p " + STRING_BUNDLE_PATH_NO_SIGNATURE + " -f";
144 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
145
146 EXPECT_EQ(commandResult, STRING_INSTALL_BUNDLE_OK + "\n");
147
148 // uninstall the bundle
149 ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
150 }
151