• 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_NAME = "com.ohos.tools.pageAbilityBundleForInstall";
30 const std::string STRING_BUNDLE_NAME_INVALID = STRING_BUNDLE_NAME + ".invalid";
31 }  // namespace
32 
33 class BmCommandDumpSystemTest : public ::testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp() override;
38     void TearDown() override;
39 };
40 
SetUpTestCase()41 void BmCommandDumpSystemTest::SetUpTestCase()
42 {}
43 
TearDownTestCase()44 void BmCommandDumpSystemTest::TearDownTestCase()
45 {}
46 
SetUp()47 void BmCommandDumpSystemTest::SetUp()
48 {
49     // reset optind to 0
50     optind = 0;
51 }
52 
TearDown()53 void BmCommandDumpSystemTest::TearDown()
54 {}
55 
56 /**
57  * @tc.number: Bm_Command_Dump_SystemTest_0100
58  * @tc.name: ExecCommand
59  * @tc.desc: Verify the "bm dump -a" command.
60  */
61 HWTEST_F(BmCommandDumpSystemTest, Bm_Command_Dump_SystemTest_0100, Function | MediumTest | Level1)
62 {
63     // uninstall the bundle
64     ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
65 
66     // install a valid bundle
67     ToolSystemTest::InstallBundle(STRING_BUNDLE_PATH, true);
68 
69     // dump all bundle
70     std::string command = "bm dump -a";
71     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
72 
73     EXPECT_NE(commandResult, "");
74 
75     // uninstall the bundle
76     ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
77 }
78 
79 /**
80  * @tc.number: Bm_Command_Dump_SystemTest_0200
81  * @tc.name: ExecCommand
82  * @tc.desc: Verify the "bm dump -n <bundle-name>" command.
83  */
84 HWTEST_F(BmCommandDumpSystemTest, Bm_Command_Dump_SystemTest_0200, Function | MediumTest | Level1)
85 {
86     // uninstall the bundle
87     ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
88 
89     // install a valid bundle
90     ToolSystemTest::InstallBundle(STRING_BUNDLE_PATH, true);
91 
92     // dump a valid bundle
93     std::string command = "bm dump -n " + STRING_BUNDLE_NAME;
94     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
95 
96     EXPECT_NE(commandResult, "");
97 
98     // uninstall the bundle
99     ToolSystemTest::UninstallBundle(STRING_BUNDLE_NAME);
100 }
101 
102 /**
103  * @tc.number: Bm_Command_Dump_SystemTest_0300
104  * @tc.name: ExecCommand
105  * @tc.desc: Verify the "bm dump -n <bundle-name>" command.
106  */
107 HWTEST_F(BmCommandDumpSystemTest, Bm_Command_Dump_SystemTest_0300, Function | MediumTest | Level1)
108 {
109     // dump an invalid bundle
110     std::string command = "bm dump -n " + STRING_BUNDLE_NAME_INVALID;
111     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
112 
113     EXPECT_EQ(commandResult, "");
114 }
115