• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 const std::string INSTALL_FALSE = "error: install file path invalid.";
32 }  // namespace
33 
34 class BmCommandInstallSystemTest : 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 BmCommandInstallSystemTest::SetUpTestCase()
43 {}
44 
TearDownTestCase()45 void BmCommandInstallSystemTest::TearDownTestCase()
46 {}
47 
SetUp()48 void BmCommandInstallSystemTest::SetUp()
49 {
50     // reset optind to 0
51     optind = 0;
52 }
53 
TearDown()54 void BmCommandInstallSystemTest::TearDown()
55 {}
56 
57 /**
58  * @tc.number: Bm_Command_Install_SystemTest_0100
59  * @tc.name: ExecCommand
60  * @tc.desc: Verify the "bm install -p <bundle-path>" command.
61  */
62 HWTEST_F(BmCommandInstallSystemTest, Bm_Command_Install_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     // uninstall the bundle
71     ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
72 }
73 
74 /**
75  * @tc.number: Bm_Command_Install_SystemTest_0200
76  * @tc.name: ExecCommand
77  * @tc.desc: Verify the "bm install -p <bundle-path>" command.
78  */
79 HWTEST_F(BmCommandInstallSystemTest, Bm_Command_Install_SystemTest_0200, Function | MediumTest | Level1)
80 {
81     // install an invalid bundle
82     std::string command = "bm install -p " + STRING_BUNDLE_PATH_INVALID;
83     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
84 
85     EXPECT_EQ(commandResult, STRING_INSTALL_BUNDLE_NG + "\n" + INSTALL_FALSE + "\n");
86 }
87 
88 /**
89  * @tc.number: Bm_Command_Install_SystemTest_0300
90  * @tc.name: ExecCommand
91  * @tc.desc: Verify the "bm install -p <bundle-path> -r" command.
92  */
93 HWTEST_F(BmCommandInstallSystemTest, Bm_Command_Install_SystemTest_0300, Function | MediumTest | Level1)
94 {
95     // uninstall the bundle
96     ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
97 
98     // install a valid bundle
99     ToolSystemTest::InstallBundle(STRING_BUNDLE_PATH, true);
100 
101     // install the same bundle
102     std::string command = "bm install -p " + STRING_BUNDLE_PATH + " -r";
103     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
104 
105     EXPECT_EQ(commandResult, STRING_INSTALL_BUNDLE_OK + "\n");
106 
107     // uninstall the bundle
108     ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
109 }